コード例 #1
0
 def test_can_hydrate_path(self):
     from neo4j.types.graph import hydrate_path, _put_unbound_relationship
     g = Graph()
     alice = g.put_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = g.put_node(2, {"Person"}, {"name": "Bob", "age": 44})
     carol = g.put_node(3, {"Person"}, {"name": "Carol", "age": 55})
     r = [
         _put_unbound_relationship(g, 1, "KNOWS", {"since": 1999}),
         _put_unbound_relationship(g, 2, "DISLIKES")
     ]
     path = hydrate_path([alice, bob, carol], r, [1, 1, -2, 2])
     self.assertEqual(path.start_node, alice)
     self.assertEqual(path.end_node, carol)
     self.assertEqual(path.nodes, (alice, bob, carol))
     expected_alice_knows_bob = g.put_relationship(1, alice, bob, "KNOWS",
                                                   {"since": 1999})
     expected_carol_dislikes_bob = g.put_relationship(
         2, carol, bob, "DISLIKES")
     self.assertEqual(
         path.relationships,
         (expected_alice_knows_bob, expected_carol_dislikes_bob))
     self.assertEqual(
         list(path),
         [expected_alice_knows_bob, expected_carol_dislikes_bob])
     self.assertTrue(repr(path))
コード例 #2
0
 def test_path_hashing(self):
     g = Graph()
     alice = g.put_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = g.put_node(2, {"Person"}, {"name": "Bob", "age": 44})
     carol = g.put_node(3, {"Person"}, {"name": "Carol", "age": 55})
     alice_knows_bob = g.put_relationship(1, alice, bob, "KNOWS", {"since": 1999})
     carol_dislikes_bob = g.put_relationship(2, carol, bob, "DISLIKES")
     path_1 = Path(alice, alice_knows_bob, carol_dislikes_bob)
     path_2 = Path(alice, alice_knows_bob, carol_dislikes_bob)
     self.assertEqual(hash(path_1), hash(path_2))
コード例 #3
0
 def test_can_create_path(self):
     g = Graph()
     alice = g.put_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = g.put_node(2, {"Person"}, {"name": "Bob", "age": 44})
     carol = g.put_node(3, {"Person"}, {"name": "Carol", "age": 55})
     alice_knows_bob = g.put_relationship(1, alice, bob, "KNOWS", {"since": 1999})
     carol_dislikes_bob = g.put_relationship(2, carol, bob, "DISLIKES")
     path = Path(alice, alice_knows_bob, carol_dislikes_bob)
     self.assertEqual(path.start_node, alice)
     self.assertEqual(path.end_node, carol)
     self.assertEqual(path.nodes, (alice, bob, carol))
     self.assertEqual(path.relationships, (alice_knows_bob, carol_dislikes_bob))
     self.assertEqual(list(path), [alice_knows_bob, carol_dislikes_bob])
     self.assertTrue(repr(path))
コード例 #4
0
 def test_can_create_relationship(self):
     g = Graph()
     alice = g.put_node(1, {"Person"}, name="Alice", age=33)
     bob = g.put_node(2, {"Person"}, name="Bob", age=44)
     alice_knows_bob = g.put_relationship(1, alice, bob, "KNOWS", since=1999)
     self.assertEqual(alice_knows_bob.start_node, alice)
     self.assertEqual(alice_knows_bob.type, "KNOWS")
     self.assertEqual(alice_knows_bob.end_node, bob)
     self.assertEqual(set(alice_knows_bob.keys()), {"since"})
     self.assertEqual(set(alice_knows_bob.values()), {1999})
     self.assertEqual(set(alice_knows_bob.items()), {("since", 1999)})
     self.assertEqual(alice_knows_bob.get("since"), 1999)
     self.assertTrue(repr(alice_knows_bob))