summaryrefslogtreecommitdiff
path: root/src-py
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2014-10-15 18:38:53 +0200
committerLV-426 <lv-426@taproot.org.il>2014-10-15 18:38:53 +0200
commitcd4c8fc54cdd6d24ef6385a89afdec1c9d65e9cb (patch)
treee84c16d4e3c88ae2185c72df9c74041a54f740fb /src-py
parent93873bd93ccc8463eaa3931e1efe7d30d1007e0b (diff)
DBO_topo_diff_commit & test
Diffstat (limited to 'src-py')
-rw-r--r--src-py/db_controller.py22
-rw-r--r--src-py/test_db_controller.py22
2 files changed, 44 insertions, 0 deletions
diff --git a/src-py/db_controller.py b/src-py/db_controller.py
index 9a6151ec..dcb70c10 100644
--- a/src-py/db_controller.py
+++ b/src-py/db_controller.py
@@ -101,6 +101,28 @@ class DB_composed_op(DB_op):
return object.__getattribute__(self, attr)
+class DBO_topo_diff_commit(DB_composed_op):
+ """
+ commit a
+ """
+ def __init__(self, topo_diff):
+ super(DBO_topo_diff_commit, self).__init__()
+
+ # TODO rm link set
+ # TODO rm node set
+ assert not topo_diff.node_set_rm, 'unsupported'
+ assert not topo_diff.link_set_rm, 'unsupported'
+
+ n_add_map = db_util.meta_attr_list_to_meta_attr_map(topo_diff.node_set_add)
+ l_add_map = db_util.meta_attr_list_to_meta_attr_map(topo_diff.link_set_add)
+
+ op_n_add = DBO_add_node_set(n_add_map)
+ op_l_add = DBO_add_link_set(l_add_map)
+
+ # [!] order critical
+ self.add_sub_op(op_n_add)
+ self.add_sub_op(op_l_add)
+
pass
class DBO_add_node_set(DB_op):
diff --git a/src-py/test_db_controller.py b/src-py/test_db_controller.py
index b768898d..2820068e 100644
--- a/src-py/test_db_controller.py
+++ b/src-py/test_db_controller.py
@@ -160,6 +160,28 @@ class TestDBController(unittest.TestCase):
n_set = self.db_ctl.exec_op(dbc.DBO_load_node_set_by_id_attribute([n_id]))
self.assertEqual(len(n_set), 0)
+ def test_topo_diff_commit(self):
+ n_0_id = rand_id()
+ n_1_id = rand_id()
+
+ n_set = [{'__type': 'T_test_topo_diff_commit', 'id': n_0_id },
+ {'__type': 'T_test_topo_diff_commit', 'id': n_1_id }]
+ l_set = [{'__type': 'T_test_topo_diff_commit', '__src': n_0_id, '__dst': n_1_id},
+ {'__type': 'T_test_topo_diff_commit', '__src': n_1_id, '__dst': n_0_id}]
+
+ topo_diff = Topo_Diff(node_set_add=n_set,
+ link_set_add=l_set)
+
+ op = dbc.DBO_topo_diff_commit(topo_diff)
+ self.assertEqual(len(op.statement_set), 3) # one parameterized node create. 2 link create
+ self.db_ctl.exec_op(op)
+
+ id_set = self.db_ctl.exec_op(dbc.DBO_match_node_set_by_id_attribute([n_0_id, n_1_id]))
+ self.assertEqual(len(id_set), 2)
+ id_set = self.db_ctl.exec_op(dbc.DBO_match_link_set_by_src_or_dst_id_attributes(src_id=n_0_id, dst_id=n_1_id))
+ self.assertEqual(len(id_set), 1)
+ id_set = self.db_ctl.exec_op(dbc.DBO_match_link_set_by_src_or_dst_id_attributes(src_id=n_1_id, dst_id=n_0_id))
+ self.assertEqual(len(id_set), 1)
def tearDown(self): pass
if __name__ == "__main__":