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_null_properties(self): stuff = Node(good=["puppies", "kittens"], bad=None) assert set(stuff.keys()) == {"good"} assert stuff.get("good") == ["puppies", "kittens"] assert stuff.get("bad") is None assert len(stuff) == 1 assert stuff["good"] == ["puppies", "kittens"] assert stuff["bad"] is None assert "good" in stuff assert "bad" not in stuff
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.id, bob.id, "KNOWS", {"since": 1999}) assert alice_knows_bob.start == alice.id assert alice_knows_bob.type == "KNOWS" assert alice_knows_bob.end == bob.id 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_node_hashing(self): node_1 = Node() node_1.id = 1234 node_2 = Node() node_2.id = 1234 node_3 = Node() node_3.id = 5678 assert hash(node_1) == hash(node_2) assert hash(node_1) != hash(node_3)
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_node_equality(self): node_1 = Node() node_1.id = 1234 node_2 = Node() node_2.id = 1234 node_3 = Node() node_3.id = 5678 assert node_1 == node_2 assert node_1 != node_3 assert node_1 != "this is not a node"
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 = [UnboundRelationship(alice_knows_bob.type, alice_knows_bob.properties), UnboundRelationship(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)
def get_node(string_entity): if string_entity[0] != "(": raise ValueError("Excpected node which shuld start with '('. Got: %s" % string_entity[0]) split_at = string_entity.find(')') if split_at == -1: raise ValueError( "Excpected node which shuld end with ')'. Found no such character in: %s" % string_entity) n, string_entity = split_two(string_entity, split_at + 1) n = n[1:-1] labels, properties, n = get_labels_and_properties(n) node = Node(labels=labels, properties=properties) return node, string_entity
def test_can_create_node(self): alice = Node({"Person"}, {"name": "Alice", "age": 33}) assert alice.labels == {"Person"} assert set(alice.keys()) == {"name", "age"} assert set(alice.values()) == {"Alice", 33} assert set(alice.items()) == {("name", "Alice"), ("age", 33)} assert alice.get("name") == "Alice" assert alice.get("age") == 33 assert repr(alice) assert len(alice) == 2 assert alice["name"] == "Alice" assert alice["age"] == 33 assert "name" in alice assert "age" in alice assert set(iter(alice)) == {"name", "age"}