def test_node_update_properties_by_id(self, given_id=None, label=None): """Test updating node properties by ID Insert a single node, update it, verify that (1) The first insertion is successful (2) The update is successful (3) The transaction of the update is maintained (4) There is only a single version of the node (5) The voided node is a snapshot of the previous version. """ node_id = str(uuid.uuid4()) if not given_id else given_id if not label: label = 'test' retries = 0 if not given_id else int(1e6) # Add first node propertiesA = { 'key1': None, 'key2': 1, 'key3': timestamp(), 'timestamp': None, 'new_key': None } g.node_merge(node_id=node_id, properties=propertiesA, label=label, max_retries=retries) print '-- commited A' # Add second node propertiesB = {'key1': u'2', 'new_key': u'n', 'timestamp': timestamp()} g.node_merge(node_id=node_id, properties=propertiesB, max_retries=retries) print '-- commited B' # Merge properties merged = deepcopy(propertiesA) merged.update(propertiesB) if not given_id: # Test that there is only 1 non-void node with node_id and property # equality # if this is not part of another test, check the count with g.session_scope(): node = g.node_lookup_one(node_id) self.assertEqual(merged, node.properties) voided_node = g.node_lookup(node_id, voided=True).one() voided_props = sanitize(propertiesA) self.assertEqual(voided_props, voided_node.properties) self.verify_node_count(2, node_id=node_id, voided=True) return merged
def test_repeated_node_update_system_annotations_by_id( self, given_id=None): """Test repeated node updates to system annotations by ID Verify that repeated updates to a single node create the correct number of voided transactions and a single valid node with the correct properties """ REPEAT_COUNT = 20 node_id = str(uuid.uuid4()) if not given_id else given_id for tally in range(REPEAT_COUNT): annotations = self.test_node_update_system_annotations_id(node_id) if not given_id: self.verify_node_count( REPEAT_COUNT*2, node_id=node_id, voided=True) with g.session_scope(): node = g.node_lookup_one(node_id) self.assertEqual( sanitize(annotations), sanitize(node.system_annotations))
def test_node_update_system_annotations_id(self, given_id=None): """Test updating node system annotations ID Insert a single node, update it, verify that (1) The first insertion is successful (2) The update is successful (3) The transaction of the update is maintained (4) There is only a single version of the node """ node_id = str(uuid.uuid4()) if not given_id else given_id # Add first node system_annotationsA = sanitize({ 'key1': None, 'key2': 2, 'key3': timestamp() }) g.node_merge(node_id=node_id, label='test', system_annotations=system_annotationsA) # Add second node system_annotationsB = sanitize({ 'key1': None, 'new_key': 2, 'timestamp': timestamp() }) g.node_merge(node_id=node_id, label='test', system_annotations=system_annotationsB) # Merge system_annotations merged = deepcopy(system_annotationsA) merged.update(system_annotationsB) # if this is not part of another test, check the count if not given_id: with g.session_scope(): node = g.node_lookup_one(node_id) print "merged:", sanitize(merged) print 'node:', sanitize(node.system_annotations) self.assertEqual(sanitize(merged), sanitize(node.system_annotations)) nodes = list( self.verify_node_count(2, node_id=node_id, voided=True)) self.assertEqual(sanitize(system_annotationsA), nodes[1].system_annotations) return merged
def test_node_update_properties_by_id(self, given_id=None, label=None): """Test updating node properties by ID Insert a single node, update it, verify that (1) The first insertion is successful (2) The update is successful (3) The transaction of the update is maintained (4) There is only a single version of the node (5) The voided node is a snapshot of the previous version. """ node_id = str(uuid.uuid4()) if not given_id else given_id if not label: label = 'test' retries = 0 if not given_id else int(1e6) # Add first node propertiesA = {'key1': None, 'key2': 1, 'key3': timestamp(), 'timestamp': None, 'new_key': None} g.node_merge(node_id=node_id, properties=propertiesA, label=label, max_retries=retries) print '-- commited A' # Add second node propertiesB = {'key1': u'2', 'new_key': u'n', 'timestamp': timestamp()} g.node_merge(node_id=node_id, properties=propertiesB, max_retries=retries) print '-- commited B' # Merge properties merged = deepcopy(propertiesA) merged.update(propertiesB) if not given_id: # Test that there is only 1 non-void node with node_id and property # equality # if this is not part of another test, check the count with g.session_scope(): node = g.node_lookup_one(node_id) self.assertEqual(merged, node.properties) voided_node = g.node_lookup(node_id, voided=True).one() voided_props = sanitize(propertiesA) self.assertEqual(voided_props, voided_node.properties) self.verify_node_count(2, node_id=node_id, voided=True) return merged
def test_repeated_node_update_system_annotations_by_id( self, given_id=None): """Test repeated node updates to system annotations by ID Verify that repeated updates to a single node create the correct number of voided transactions and a single valid node with the correct properties """ REPEAT_COUNT = 20 node_id = str(uuid.uuid4()) if not given_id else given_id for tally in range(REPEAT_COUNT): annotations = self.test_node_update_system_annotations_id(node_id) if not given_id: self.verify_node_count(REPEAT_COUNT * 2, node_id=node_id, voided=True) with g.session_scope(): node = g.node_lookup_one(node_id) self.assertEqual(sanitize(annotations), sanitize(node.system_annotations))
def test_node_update_property_items(self): """Test updating node system annotations ID """ node_id = str(uuid.uuid4()) props = sanitize({'key1': None, 'key2': 2}) with g.session_scope() as session: node = PolyNode(node_id, 'test', properties=props) test_string = 'This is a test' node.properties['key1'] = test_string with g.session_scope() as session: session.merge(node) with g.session_scope(): node = g.nodes().ids(node_id).one() self.assertTrue(node.properties['key1'], test_string)
def test_node_update_sysan_items(self): """Test updating node system annotations ID """ node_id = str(uuid.uuid4()) system_annotationsA = sanitize({ 'key1': None, 'key2': 2, 'key3': timestamp() }) node = g.node_merge(node_id=node_id, label='test', system_annotations=system_annotationsA) test_string = 'This is a test' node.system_annotations['key1'] = test_string with g.session_scope() as session: session.merge(node) with g.session_scope(): node = g.nodes().ids(node_id).one() self.assertTrue(node.system_annotations['key1'], test_string)
def test_node_update_system_annotations_id(self, given_id=None): """Test updating node system annotations ID Insert a single node, update it, verify that (1) The first insertion is successful (2) The update is successful (3) The transaction of the update is maintained (4) There is only a single version of the node """ node_id = str(uuid.uuid4()) if not given_id else given_id # Add first node system_annotationsA = sanitize({ 'key1': None, 'key2': 2, 'key3': timestamp() }) g.node_merge(node_id=node_id, label='test', system_annotations=system_annotationsA) # Add second node system_annotationsB = sanitize({ 'key1': None, 'new_key': 2, 'timestamp': timestamp() }) g.node_merge(node_id=node_id, label='test', system_annotations=system_annotationsB) # Merge system_annotations merged = deepcopy(system_annotationsA) merged.update(system_annotationsB) # if this is not part of another test, check the count if not given_id: with g.session_scope(): node = g.node_lookup_one(node_id) print "merged:", sanitize(merged) print 'node:', sanitize(node.system_annotations) self.assertEqual( sanitize(merged), sanitize(node.system_annotations)) nodes = list(self.verify_node_count( 2, node_id=node_id, voided=True)) self.assertEqual(sanitize(system_annotationsA), nodes[1].system_annotations) return merged