Ejemplo n.º 1
0
 def test_can_hydrate_path(self):
     g = Graph()
     gh = Graph.Hydrator(g)
     alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
     carol = gh.hydrate_node(3, {"Person"}, {"name": "Carol", "age": 55})
     r = [
         gh.hydrate_unbound_relationship(1, "KNOWS", {"since": 1999}),
         gh.hydrate_unbound_relationship(2, "DISLIKES", {})
     ]
     path = gh.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 = gh.hydrate_relationship(
         1, alice.id, bob.id, "KNOWS", {"since": 1999})
     expected_carol_dislikes_bob = gh.hydrate_relationship(
         2, carol.id, bob.id, "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))
Ejemplo n.º 2
0
 def test_path_hashing(self):
     g = Graph()
     gh = Graph.Hydrator(g)
     alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
     carol = gh.hydrate_node(3, {"Person"}, {"name": "Carol", "age": 55})
     alice_knows_bob = gh.hydrate_relationship(1, alice.id, bob.id, "KNOWS",
                                               {"since": 1999})
     carol_dislikes_bob = gh.hydrate_relationship(2, carol.id, bob.id,
                                                  "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))
Ejemplo n.º 3
0
 def test_can_create_relationship(self):
     g = Graph()
     gh = Graph.Hydrator(g)
     alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
     alice_knows_bob = gh.hydrate_relationship(1, alice.id, bob.id, "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))
Ejemplo n.º 4
0
 def test_null_properties(self):
     g = Graph()
     gh = Graph.Hydrator(g)
     stuff = gh.hydrate_node(1, (), {
         "good": ["puppies", "kittens"],
         "bad": None
     })
     self.assertEqual(set(stuff.keys()), {"good"})
     self.assertEqual(stuff.get("good"), ["puppies", "kittens"])
     self.assertIsNone(stuff.get("bad"))
     self.assertEqual(len(stuff), 1)
     self.assertEqual(stuff["good"], ["puppies", "kittens"])
     self.assertIsNone(stuff["bad"])
     self.assertIn("good", stuff)
     self.assertNotIn("bad", stuff)
Ejemplo n.º 5
0
 def test_can_create_node(self):
     g = Graph()
     gh = Graph.Hydrator(g)
     alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
     self.assertEqual(alice.labels, {"Person"})
     self.assertEqual(set(alice.keys()), {"name", "age"})
     self.assertEqual(set(alice.values()), {"Alice", 33})
     self.assertEqual(set(alice.items()), {("name", "Alice"), ("age", 33)})
     self.assertEqual(alice.get("name"), "Alice")
     self.assertEqual(alice.get("age"), 33)
     self.assertTrue(repr(alice))
     self.assertEqual(len(alice), 2)
     self.assertEqual(alice["name"], "Alice")
     self.assertEqual(alice["age"], 33)
     self.assertIn("name", alice)
     self.assertIn("age", alice)
     self.assertEqual(set(iter(alice)), {"name", "age"})
Ejemplo n.º 6
0
 def test_can_create_path(self):
     g = Graph()
     gh = Graph.Hydrator(g)
     alice = gh.hydrate_node(1, {"Person"}, {"name": "Alice", "age": 33})
     bob = gh.hydrate_node(2, {"Person"}, {"name": "Bob", "age": 44})
     carol = gh.hydrate_node(3, {"Person"}, {"name": "Carol", "age": 55})
     alice_knows_bob = gh.hydrate_relationship(1, alice.id, bob.id, "KNOWS",
                                               {"since": 1999})
     carol_dislikes_bob = gh.hydrate_relationship(2, carol.id, bob.id,
                                                  "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))