示例#1
0
 def test_can_hydrate_path(self):
     from neo4j.v1.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))
 def test_basic_graph(self):
     g = Graph()
     a = g.put_node(1)
     b = g.put_node(2)
     c = g.put_node(3)
     d = g.put_node(4)
     ab = g.put_relationship(7, a, b, "KNOWS")
     cb = g.put_relationship(8, c, b, "KNOWS")
     cd = g.put_relationship(9, c, d, "KNOWS")
     r = cypher_repr(g)
     self.assertEqual(u"<Graph order=4 size=3>", r)
示例#3
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))
 def test_basic_path(self):
     g = Graph()
     a = g.put_node(1)
     b = g.put_node(2)
     c = g.put_node(3)
     d = g.put_node(4)
     ab = g.put_relationship(7, a, b, "KNOWS")
     cb = g.put_relationship(8, c, b, "KNOWS")
     cd = g.put_relationship(9, c, d, "KNOWS")
     p = Path(a, ab, cb, cd)
     r = cypher_repr(p)
     self.assertEqual(
         u"(_1)-[:KNOWS {}]->(_2)<-[:KNOWS {}]-(_3)-[:KNOWS {}]->(_4)", r)
 def test_alternate_related_node_template(self):
     g = Graph()
     a = g.put_node(1, name="Alice")
     b = g.put_node(2, name="Bob")
     ab = g.put_relationship(9, a, b, "KNOWS", since=1999)
     r = cypher_repr(ab, related_node_template="{property.name}")
     self.assertEqual(u'(Alice)-[:KNOWS {since: 1999}]->(Bob)', r)
 def test_basic_relationship(self):
     g = Graph()
     a = g.put_node(1)
     b = g.put_node(2)
     ab = g.put_relationship(9, a, b, "KNOWS", since=1999)
     r = cypher_repr(ab)
     self.assertEqual(u'(_1)-[:KNOWS {since: 1999}]->(_2)', r)
示例#7
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))
示例#8
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))