def test_path_hashing(self): alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33}) bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44}) carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55}) alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999}) carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES") path_1 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol) path_2 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol) assert hash(path_1) == hash(path_2)
def test_can_create_path(self): alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33}) bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44}) carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55}) alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999}) carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES") path = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol) assert path.start == alice assert path.end == carol assert path.nodes == (alice, bob, carol) assert path.relationships == (alice_knows_bob, carol_dislikes_bob) assert list(path) == [alice_knows_bob, carol_dislikes_bob] assert repr(path)
def test_can_hydrate_path(self): alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33}) bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44}) carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55}) alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999}) carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES") rels = [Relationship(None, None, alice_knows_bob.type, alice_knows_bob.properties), Relationship(None, None, carol_dislikes_bob.type, carol_dislikes_bob.properties)] rels[0].id = alice_knows_bob.id rels[1].id = carol_dislikes_bob.id path = Path.hydrate([alice, bob, carol], rels, [1, 1, -2, 2]) assert path.start == alice assert path.end == carol assert path.nodes == (alice, bob, carol) assert path.relationships == (alice_knows_bob, carol_dislikes_bob) assert list(path) == [alice_knows_bob, carol_dislikes_bob] assert repr(path)