diff options
Diffstat (limited to 'src/server-tests/test_db_controller.py')
| -rw-r--r-- | src/server-tests/test_db_controller.py | 102 |
1 files changed, 59 insertions, 43 deletions
diff --git a/src/server-tests/test_db_controller.py b/src/server-tests/test_db_controller.py index b2b5689e..5aaa6d57 100644 --- a/src/server-tests/test_db_controller.py +++ b/src/server-tests/test_db_controller.py @@ -1,16 +1,31 @@ -import unittest import logging -import db_controller as dbc +import unittest -from rz_server import Config -from neo4j_test_util import rand_id +import test_util +import db_controller as dbc +from db_op import DBO_add_link_set +from db_op import DBO_rz_clone +from db_op import DBO_block_chain__commit +from db_op import DBO_block_chain__list +from db_op import DBO_match_node_set_by_id_attribute +from db_op import DBO_match_link_id_set +from db_op import DBO_add_node_set +from db_op import DBO_attr_diff_commit +from db_op import DBO_load_link_set +from db_op import DBO_load_node_set_by_DB_id +from db_op import DBO_match_node_id_set +from db_op import DBO_rm_node_set +from db_op import DBO_rz_clone +from db_op import DBO_topo_diff_commit +from model.graph import Attr_Diff +from model.graph import Topo_Diff +from model.model import Link from neo4j_test_util import flush_db from neo4j_test_util import gen_rand_data +from neo4j_test_util import rand_id from neo4j_util import Neo4JException +from rz_server import Config -from model.graph import Attr_Diff -from model.graph import Topo_Diff -from model.model import Link class TestDBController(unittest.TestCase): @@ -37,9 +52,10 @@ class TestDBController(unittest.TestCase): self.log.addHandler(logging.StreamHandler()) def setUp(self): - flush_db(self.db_ctl) # remove once embedded DB test mode is supported - self.db_ctl.exec_op(dbc.DBO_add_node_set(self.n_map)) - self.db_ctl.exec_op(dbc.DBO_add_link_set(self.l_map)) + # flush_db(self.db_ctl) # remove once embedded DB test mode is supported + # self.db_ctl.exec_op(DBO_add_node_set(self.n_map)) + # self.db_ctl.exec_op(DBO_add_link_set(self.l_map)) + pass def test_db_op_statement_iteration(self): s_arr = ['create (b:Book {title: \'foo\'}) return b', @@ -68,7 +84,7 @@ class TestDBController(unittest.TestCase): def test_add_node_set(self): n_map = { 'T_test_add_node_set': [{'id': rand_id()}, {'id': rand_id()}] } - op = dbc.DBO_add_node_set(n_map) + op = DBO_add_node_set(n_map) self.assertEqual(len(op.statement_set), 1) # assert a single statement is issued @@ -82,48 +98,48 @@ class TestDBController(unittest.TestCase): n_map = { 'T_test_add_node_set': [{'id': src_id }, {'id': dst_id_0 }, {'id': dst_id_1 }] } - self.db_ctl.exec_op(dbc.DBO_add_node_set(n_map)) + self.db_ctl.exec_op(DBO_add_node_set(n_map)) l_map = { 'T_test_add_link_set' : [{'__src': src_id, '__dst': dst_id_0}, {'__src': src_id, '__dst': dst_id_1}] } - op = dbc.DBO_add_link_set(l_map) + op = DBO_add_link_set(l_map) self.assertEqual(len(op.statement_set), 2) # no support yet for parameterized statements for link creation l_set = self.db_ctl.exec_op(op) self.assertEqual(len(l_set), 2) def test_match_node_set_by_type(self): - op = dbc.DBO_match_node_id_set(filter_label='Person') + op = DBO_match_node_id_set(filter_label='Person') id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 2) - op = dbc.DBO_match_node_id_set(filter_label='Nan_Type') + op = DBO_match_node_id_set(filter_label='Nan_Type') id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0) def test_match_node_set_by_attribute(self): fam = { 'name': ['Bob', u'Judo'], 'age': [128] } - n_set = self.db_ctl.exec_op(dbc.DBO_match_node_id_set(filter_attr_map=fam)) + n_set = self.db_ctl.exec_op(DBO_match_node_id_set(filter_attr_map=fam)) self.assertEqual(len(n_set), 1) fam = { 'age': [128, 256, 404] } - n_set = self.db_ctl.exec_op(dbc.DBO_match_node_id_set(filter_attr_map=fam)) + n_set = self.db_ctl.exec_op(DBO_match_node_id_set(filter_attr_map=fam)) self.assertEqual(len(n_set), 2) def test_match_node_set_by_DB_id(self): pass # TODO def test_match_node_set_by_id_attribute(self): - n_set = self.db_ctl.exec_op(dbc.DBO_match_node_set_by_id_attribute(['skill_00', 'person_01'])) + n_set = self.db_ctl.exec_op(DBO_match_node_set_by_id_attribute(['skill_00', 'person_01'])) self.assertEqual(len(n_set), 2) def test_match_link_set_by_type(self): - op = dbc.DBO_match_link_id_set(filter_label='Knows') + op = DBO_match_link_id_set(filter_label='Knows') id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 2) - op = dbc.DBO_match_link_id_set(filter_label='Nan_Type') + op = DBO_match_link_id_set(filter_label='Nan_Type') id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0) @@ -131,30 +147,30 @@ class TestDBController(unittest.TestCase): # load by l_ptr l_ptr = Link.link_ptr(src_id='person_00', dst_id='skill_00') - op = dbc.DBO_load_link_set.init_from_link_ptr(l_ptr) + op = DBO_load_link_set.init_from_link_ptr(l_ptr) l_set = self.db_ctl.exec_op(op) self.assertEqual(len(l_set), 1) l_ptr = Link.link_ptr(src_id='person_00') - op = dbc.DBO_load_link_set.init_from_link_ptr(l_ptr) + op = DBO_load_link_set.init_from_link_ptr(l_ptr) l_set = self.db_ctl.exec_op(op) self.assertEqual(len(l_set), 2) l_ptr = Link.link_ptr(dst_id='skill_00') - op = dbc.DBO_load_link_set.init_from_link_ptr(l_ptr) + op = DBO_load_link_set.init_from_link_ptr(l_ptr) l_set = self.db_ctl.exec_op(op) self.assertEqual(len(l_set), 1) # load by l_ptr sets l_ptr_set = [Link.link_ptr(s, d) for (s, d) in [('person_00', 'skill_00'), ('person_00', 'skill_01')]] - op = dbc.DBO_load_link_set.init_from_link_ptr_set(l_ptr_set) + op = DBO_load_link_set.init_from_link_ptr_set(l_ptr_set) l_set = self.db_ctl.exec_op(op) self.assertEqual(len(l_set), 2) # this should return the same link twice l_ptr_set = [Link.link_ptr(s, d) for (s, d) in [('person_00', 'skill_00'), ('person_00', 'skill_01')]] l_ptr_set.append(Link.link_ptr(dst_id='skill_00')) - op = dbc.DBO_load_link_set.init_from_link_ptr_set(l_ptr_set) + op = DBO_load_link_set.init_from_link_ptr_set(l_ptr_set) l_set = self.db_ctl.exec_op(op) self.assertEqual(len(l_set), 3) @@ -164,12 +180,12 @@ class TestDBController(unittest.TestCase): """ # create nodes, get DB ids - op = dbc.DBO_add_node_set({'T_test_load_node_set_by_DB_id': [{'name': 'John Doe'}, + op = DBO_add_node_set({'T_test_load_node_set_by_DB_id': [{'name': 'John Doe'}, {'name': 'John Doe'}]}) id_set = self.db_ctl.exec_op(op) # match against DB ids - op = dbc.DBO_load_node_set_by_DB_id(id_set) + op = DBO_load_node_set_by_DB_id(id_set) n_set = self.db_ctl.exec_op(op) self.assertEqual(len(n_set), len(id_set), 'incorrect result size') @@ -196,7 +212,7 @@ class TestDBController(unittest.TestCase): self.assertEqual(len(op.error_set), 1) # assert node creation did not persist - n_set = self.db_ctl.exec_op(dbc.DBO_match_node_set_by_id_attribute([n_id])) + n_set = self.db_ctl.exec_op(DBO_match_node_set_by_id_attribute([n_id])) self.assertEqual(len(n_set), 0) def test_topo_diff_commit(self): @@ -214,28 +230,28 @@ class TestDBController(unittest.TestCase): topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set) - op = dbc.DBO_topo_diff_commit(topo_diff) + op = DBO_topo_diff_commit(topo_diff) op_ret = self.db_ctl.exec_op(op) self.assertEqual(len(op_ret), 2) # to id-sets, nodes & links self.assertEqual(len(op_ret[0]), 3) # expect id-set of length 3 self.assertEqual(len(op_ret[1]), 2) # expect id-set of length 2 - id_set = self.db_ctl.exec_op(dbc.DBO_match_node_set_by_id_attribute([n_0_id, n_1_id])) + id_set = self.db_ctl.exec_op(DBO_match_node_set_by_id_attribute([n_0_id, n_1_id])) self.assertEqual(len(id_set), 2) l_ptr = Link.link_ptr(src_id=n_0_id, dst_id=n_1_id) - id_set = self.db_ctl.exec_op(dbc.DBO_load_link_set.init_from_link_ptr(l_ptr)) + id_set = self.db_ctl.exec_op(DBO_load_link_set.init_from_link_ptr(l_ptr)) self.assertEqual(len(id_set), 1) l_ptr = Link.link_ptr(src_id=n_1_id, dst_id=n_0_id) - id_set = self.db_ctl.exec_op(dbc.DBO_load_link_set.init_from_link_ptr(l_ptr)) + id_set = self.db_ctl.exec_op(DBO_load_link_set.init_from_link_ptr(l_ptr)) self.assertEqual(len(id_set), 1) id_set_rm = [n_2_id] topo_diff = Topo_Diff(node_set_rm=id_set_rm) - op = dbc.DBO_topo_diff_commit(topo_diff) + op = DBO_topo_diff_commit(topo_diff) self.db_ctl.exec_op(op) - op = dbc.DBO_match_node_set_by_id_attribute(id_set_rm) + op = DBO_match_node_set_by_id_attribute(id_set_rm) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0) @@ -244,7 +260,7 @@ class TestDBController(unittest.TestCase): n_id = rand_id() topo_diff = Topo_Diff(node_set_add=[{'__label_set': ['T_test_attr_diff_commit'], 'id': n_id, 'attr_0': 0}]) - op = dbc.DBO_topo_diff_commit(topo_diff) + op = DBO_topo_diff_commit(topo_diff) self.db_ctl.exec_op(op) # apply attr_diff @@ -253,7 +269,7 @@ class TestDBController(unittest.TestCase): attr_diff.add_node_attr_write(n_id, 'attr_1', 'a') attr_diff.add_node_attr_rm(n_id, 'attr_2') - op = dbc.DBO_attr_diff_commit(attr_diff) + op = DBO_attr_diff_commit(attr_diff) ret_diff = self.db_ctl.exec_op(op) self.assertEqual(len(ret_diff.type__node), 1) @@ -263,7 +279,7 @@ class TestDBController(unittest.TestCase): attr_diff = Attr_Diff() attr_diff.add_node_attr_write(n_id, 'attr_2', 0) - op = dbc.DBO_attr_diff_commit(attr_diff) + op = DBO_attr_diff_commit(attr_diff) ret_diff = self.db_ctl.exec_op(op) self.assertTrue(None != ret_diff.type__node[n_id]['__attr_write'].get('attr_2')) @@ -271,7 +287,7 @@ class TestDBController(unittest.TestCase): attr_diff = Attr_Diff() attr_diff.add_node_attr_rm(n_id, 'attr_2') - op = dbc.DBO_attr_diff_commit(attr_diff) + op = DBO_attr_diff_commit(attr_diff) ret_diff = self.db_ctl.exec_op(op) self.assertTrue('attr_2' in ret_diff.type__node[n_id]['__attr_remove']) @@ -292,23 +308,23 @@ class TestDBController(unittest.TestCase): topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set) - op = dbc.DBO_topo_diff_commit(topo_diff) + op = DBO_topo_diff_commit(topo_diff) self.db_ctl.exec_op(op) - op = dbc.DBO_rm_node_set([n_0_id, n_1_id]) + op = DBO_rm_node_set([n_0_id, n_1_id]) self.db_ctl.exec_op(op) - op = dbc.DBO_rm_node_set([n_2_id, n_3_id], rm_links=True) + op = DBO_rm_node_set([n_2_id, n_3_id], rm_links=True) self.db_ctl.exec_op(op) # assert all deleted - op = dbc.DBO_match_node_id_set(filter_label=n_T) + op = DBO_match_node_id_set(filter_label=n_T) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0) def test_rz_clone(self): l_n, l_r = gen_rand_data(self.db_ctl, lim_n=8, lim_r=16, prob_link_create=0.7) - op = dbc.DBO_rz_clone(filter_label=l_n, limit=32) + op = DBO_rz_clone(filter_label=l_n, limit=32) ret = self.db_ctl.exec_op(op) n_set = ret['node_set'] l_set = ret['link_set'] |
