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.identity, bob.identity, "KNOWS", {"since": 1999}) carol_dislikes_bob = Relationship(carol.identity, bob.identity, "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_path_equality(self): alice = Node({"Person"}, {"name": "Alice", "age": 33}) bob = Node({"Person"}, {"name": "Bob", "age": 44}) carol = Node({"Person"}, {"name": "Carol", "age": 55}) alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999}) carol_dislikes_bob = Relationship(carol, bob, "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 path_1 == path_2 assert path_1 != "this is not a path"
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.identity, bob.identity, "KNOWS", {"since": 1999}) carol_dislikes_bob = Relationship(carol.identity, bob.identity, "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({"Person"}, {"name": "Alice", "age": 33}) bob = Node({"Person"}, {"name": "Bob", "age": 44}) carol = Node({"Person"}, {"name": "Carol", "age": 55}) alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999}) carol_dislikes_bob = Relationship(carol, bob, "DISLIKES") path = Path.hydrate( [alice, bob, carol], [alice_knows_bob.unbind(), carol_dislikes_bob.unbind()], [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)
def test_can_create_relationship(self): alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33}) bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44}) alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999}) assert alice_knows_bob.start == alice.identity assert alice_knows_bob.type == "KNOWS" assert alice_knows_bob.end == bob.identity assert set(alice_knows_bob.keys()) == {"since"} assert set(alice_knows_bob.values()) == {1999} assert set(alice_knows_bob.items()) == {("since", 1999)} assert alice_knows_bob.get("since") == 1999 assert repr(alice_knows_bob)
def test_can_create_relationship(self): alice = Node({"Person"}, {"name": "Alice", "age": 33}) bob = Node({"Person"}, {"name": "Bob", "age": 44}) alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999}) assert alice_knows_bob.start is alice assert alice_knows_bob.type == "KNOWS" assert alice_knows_bob.end is bob assert set(alice_knows_bob.keys()) == {"since"} assert set(alice_knows_bob.values()) == {1999} assert set(alice_knows_bob.items()) == {("since", 1999)} assert alice_knows_bob.get("since") == 1999 assert repr(alice_knows_bob)