def test_load_link_set(self): # load by l_ptr l_ptr = Link.link_ptr(src_id='person_00', dst_id='skill_00') 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 = 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 = 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 = 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 = 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)
def test_load_link_set(self): # load by l_ptr l_ptr = Link.link_ptr(src_id='person_00', dst_id='skill_00') 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 = 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 = 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 = 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 = 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)
def load_link_set_by_link_ptr_set(): def deserialize_param_set(param_json): l_ptr_set_raw = param_json['link_ptr_set'] __sanitize_input(l_ptr_set_raw) l_ptr_set = [] for lptr_dict in l_ptr_set_raw: src_id = lptr_dict.get('__src_id') dst_id = lptr_dict.get('__dst_id') l_ptr_set += [Link.Link_Ptr(src_id=src_id, dst_id=dst_id)] return l_ptr_set l_ptr_set = deserialize_param_set(request.get_json()) op = DBO_load_link_set.init_from_link_ptr_set(l_ptr_set) assert False
def load_link_set_by_link_ptr_set(): def deserialize_param_set(param_json): l_ptr_set_raw = param_json['link_ptr_set'] __sanitize_input(l_ptr_set_raw) l_ptr_set = [] for lptr_dict in l_ptr_set_raw: src_id = lptr_dict.get('__src_id') dst_id = lptr_dict.get('__dst_id') l_ptr_set += [Link.Link_Ptr(src_id=src_id, dst_id=dst_id) ] return l_ptr_set l_ptr_set = deserialize_param_set(request.get_json()) op = DBO_load_link_set.init_from_link_ptr_set(l_ptr_set) assert False
def test_diff_commit__topo(self): test_label = neo4j_test_util.rand_label() n_0, n_0_id = generate_random_node_dict(test_label) n_1, n_1_id = generate_random_node_dict(test_label) n_2, n_2_id = generate_random_node_dict(test_label) l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id) l_1, l_1_id = generate_random_link_dict(test_label, n_0_id, n_2_id) n_set = [n_0, n_1, n_2] l_set = [l_0, l_1] topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set) # commit diff op = DBO_diff_commit__topo(topo_diff) ret_topo_diff = self.db_ctl.exec_op(op) # test return type self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_add')) self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_add')) self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_rm')) self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_rm')) # test return set lengths self.assertEqual(len(ret_topo_diff.node_id_set_add), len(n_set)) self.assertEqual(len(ret_topo_diff.link_id_set_add), len(l_set)) self.assertEqual(len(ret_topo_diff.node_id_set_rm), 0) self.assertEqual(len(ret_topo_diff.link_id_set_rm), 0) # assert nodes persisted 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) # assert links persisted l_ptr_0 = Link.link_ptr(src_id=n_0_id, dst_id=n_1_id) l_ptr_1 = Link.link_ptr(src_id=n_0_id, dst_id=n_2_id) op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1]) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 2) # remova links topo_diff = Topo_Diff(link_id_set_rm=[l_0_id, l_1_id]) op = DBO_diff_commit__topo(topo_diff) ret_topo_diff = self.db_ctl.exec_op(op) self.assertEqual(len(ret_topo_diff.link_id_set_rm), 2) # assert links removed op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1]) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0) # removal nodes topo_diff = Topo_Diff(node_id_set_rm=[n_2_id]) op = DBO_diff_commit__topo(topo_diff) ret_topo_diff = self.db_ctl.exec_op(op) self.assertEqual(len(ret_topo_diff.node_id_set_rm), 1) # assert nodes removed op = DBO_match_node_set_by_id_attribute([n_2_id]) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0)
def test_diff_commit__topo(self): test_label = neo4j_test_util.rand_label() n_0, n_0_id = generate_random_node_dict(test_label) n_1, n_1_id = generate_random_node_dict(test_label) n_2, n_2_id = generate_random_node_dict(test_label) l_0, l_0_id = generate_random_link_dict(test_label, n_0_id, n_1_id) l_1, l_1_id = generate_random_link_dict(test_label, n_0_id, n_2_id) n_set = [n_0, n_1, n_2] l_set = [l_0, l_1] topo_diff = Topo_Diff(node_set_add=n_set, link_set_add=l_set) # commit diff op = DBO_diff_commit__topo(topo_diff) ret_topo_diff = self.db_ctl.exec_op(op) # test return type self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_add')) self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_add')) self.assertTrue(hasattr(ret_topo_diff, 'node_id_set_rm')) self.assertTrue(hasattr(ret_topo_diff, 'link_id_set_rm')) # test return set lengths self.assertEqual(len(ret_topo_diff.node_id_set_add), len(n_set)) self.assertEqual(len(ret_topo_diff.link_id_set_add), len(l_set)) self.assertEqual(len(ret_topo_diff.node_id_set_rm), 0) self.assertEqual(len(ret_topo_diff.link_id_set_rm), 0) # assert nodes persisted 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) # assert links persisted l_ptr_0 = Link.link_ptr(src_id=n_0_id, dst_id=n_1_id) l_ptr_1 = Link.link_ptr(src_id=n_0_id, dst_id=n_2_id) op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1]) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 2) # remova links topo_diff = Topo_Diff(link_id_set_rm=[l_0_id, l_1_id]) op = DBO_diff_commit__topo(topo_diff) ret_topo_diff = self.db_ctl.exec_op(op) self.assertEqual(len(ret_topo_diff.link_id_set_rm), 2) # assert links removed op = DBO_load_link_set.init_from_link_ptr_set([l_ptr_0, l_ptr_1]) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0) # removal nodes topo_diff = Topo_Diff(node_id_set_rm=[n_2_id]) op = DBO_diff_commit__topo(topo_diff) ret_topo_diff = self.db_ctl.exec_op(op) self.assertEqual(len(ret_topo_diff.node_id_set_rm), 1) # assert nodes removed op = DBO_match_node_set_by_id_attribute([n_2_id]) id_set = self.db_ctl.exec_op(op) self.assertEqual(len(id_set), 0)