diff --git a/neo4j/v1/types.py b/neo4j/v1/types.py index 2e652fc2..21d19a03 100644 --- a/neo4j/v1/types.py +++ b/neo4j/v1/types.py @@ -25,14 +25,13 @@ of these classes. """ - from .packstream import Structure class Entity(object): """ Base class for Node and Relationship. """ - identity = None + id = None properties = None def __init__(self, properties=None, **kwproperties): @@ -41,7 +40,7 @@ def __init__(self, properties=None, **kwproperties): def __eq__(self, other): try: - return self.identity == other.identity + return self.id == other.id except AttributeError: return False @@ -49,7 +48,7 @@ def __ne__(self, other): return not self.__eq__(other) def __hash__(self): - return hash(self.identity) + return hash(self.id) def __len__(self): return len(self.properties) @@ -82,9 +81,9 @@ class Node(Entity): labels = None @classmethod - def hydrate(cls, identity, labels, properties=None): + def hydrate(cls, id_, labels, properties=None): inst = cls(labels, properties) - inst.identity = identity + inst.id = id_ return inst def __init__(self, labels=None, properties=None, **kwproperties): @@ -92,8 +91,8 @@ def __init__(self, labels=None, properties=None, **kwproperties): self.labels = set(labels or set()) def __repr__(self): - return "" % \ - (self.identity, self.labels, self.properties) + return "" % \ + (self.id, self.labels, self.properties) class BaseRelationship(Entity): @@ -113,9 +112,9 @@ class Relationship(BaseRelationship): end = None @classmethod - def hydrate(cls, identity, start, end, type, properties=None): + def hydrate(cls, id_, start, end, type, properties=None): inst = cls(start, end, type, properties) - inst.identity = identity + inst.id = id_ return inst def __init__(self, start, end, type, properties=None, **kwproperties): @@ -126,12 +125,12 @@ def __init__(self, start, end, type, properties=None, **kwproperties): self.end = end def __repr__(self): - return "" % \ - (self.identity, self.start, self.end, self.type, self.properties) + return "" % \ + (self.id, self.start, self.end, self.type, self.properties) def unbind(self): inst = UnboundRelationship(self.type, self.properties) - inst.identity = self.identity + inst.id = self.id return inst @@ -140,21 +139,21 @@ class UnboundRelationship(BaseRelationship): """ @classmethod - def hydrate(cls, identity, type, properties=None): + def hydrate(cls, id_, type, properties=None): inst = cls(type, properties) - inst.identity = identity + inst.id = id_ return inst def __init__(self, type, properties=None, **kwproperties): super(UnboundRelationship, self).__init__(type, properties, **kwproperties) def __repr__(self): - return "" % \ - (self.identity, self.type, self.properties) + return "" % \ + (self.id, self.type, self.properties) def bind(self, start, end): inst = Relationship(start, end, self.type, self.properties) - inst.identity = self.identity + inst.id = self.id return inst @@ -174,9 +173,9 @@ def hydrate(cls, nodes, rels, sequence): assert rel_index != 0 next_node = nodes[sequence[2 * i + 1]] if rel_index > 0: - entities.append(rels[rel_index - 1].bind(last_node.identity, next_node.identity)) + entities.append(rels[rel_index - 1].bind(last_node.id, next_node.id)) else: - entities.append(rels[-rel_index - 1].bind(next_node.identity, last_node.identity)) + entities.append(rels[-rel_index - 1].bind(next_node.id, last_node.id)) entities.append(next_node) last_node = next_node return cls(*entities) @@ -187,7 +186,7 @@ def __init__(self, start_node, *rels_and_nodes): def __repr__(self): return "" % \ - (self.start.identity, self.end.identity, len(self)) + (self.start.id, self.end.id, len(self)) def __eq__(self, other): try: diff --git a/test/tck/resultparser.py b/test/tck/resultparser.py index 75bd3789..cb198bc6 100644 --- a/test/tck/resultparser.py +++ b/test/tck/resultparser.py @@ -181,19 +181,19 @@ def get_path(string_path): string_path = string_path[1:-1] n, string_path = get_node(string_path) list_of_nodes_and_rel = [n] - n.identity = ++id + n.id = ++id while string_path != '': r, string_path, point_up = get_relationship(string_path) n, string_path = get_node(string_path) - n.identity = ++id + n.id = ++id if point_up: - r.start = list_of_nodes_and_rel[-1].identity - r.end = n.identity - r.identity = 0 + r.start = list_of_nodes_and_rel[-1].id + r.end = n.id + r.id = 0 else: - r.start = n.identity - r.end = list_of_nodes_and_rel[-1].identity - r.identity = 0 + r.start = n.id + r.end = list_of_nodes_and_rel[-1].id + r.id = 0 list_of_nodes_and_rel.append(r) list_of_nodes_and_rel.append(n) path = Path(list_of_nodes_and_rel[0], *list_of_nodes_and_rel[1:]) diff --git a/test/tck/tck_util.py b/test/tck/tck_util.py index c0a93655..186d6778 100644 --- a/test/tck/tck_util.py +++ b/test/tck/tck_util.py @@ -114,11 +114,11 @@ def create_node(self, entity): def create_path(self, entity): content = {} - prev_id = entity.start.identity + prev_id = entity.start.id p = [] for i, rel in enumerate(list(entity)): n = entity.nodes[i + 1] - current_id = n.identity + current_id = n.id if rel.start == prev_id and rel.end == current_id: rel.start = i rel.end = i + 1 diff --git a/test/test_types.py b/test/test_types.py index 7810ad19..121f79d4 100644 --- a/test/test_types.py +++ b/test/test_types.py @@ -57,22 +57,22 @@ def test_null_properties(self): def test_node_equality(self): node_1 = Node() - node_1.identity = 1234 + node_1.id = 1234 node_2 = Node() - node_2.identity = 1234 + node_2.id = 1234 node_3 = Node() - node_3.identity = 5678 + node_3.id = 5678 assert node_1 == node_2 assert node_1 != node_3 assert node_1 != "this is not a node" def test_node_hashing(self): node_1 = Node() - node_1.identity = 1234 + node_1.id = 1234 node_2 = Node() - node_2.identity = 1234 + node_2.id = 1234 node_3 = Node() - node_3.identity = 5678 + node_3.id = 5678 assert hash(node_1) == hash(node_2) assert hash(node_1) != hash(node_3) @@ -82,10 +82,10 @@ class RelationshipTestCase(TestCase): 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 + 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.identity + 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)} @@ -111,8 +111,8 @@ 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") + 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 @@ -125,8 +125,8 @@ 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.identity, bob.identity, "KNOWS", {"since": 1999}) - carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES") + alice_knows_bob = Relationship(alice.id, bob.id, "KNOWS", {"since": 1999}) + carol_dislikes_bob = Relationship(carol.id, bob.id, "DISLIKES") path = Path.hydrate([alice, bob, carol], [alice_knows_bob.unbind(), carol_dislikes_bob.unbind()], [1, 1, -2, 2]) @@ -141,8 +141,8 @@ def test_path_equality(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") + 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 path_1 == path_2 @@ -152,8 +152,8 @@ 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") + 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) @@ -167,7 +167,7 @@ def test_can_hydrate_node_structure(self): struct.append(["Person"]) struct.append({"name": "Alice"}) alice = hydrated(struct) - assert alice.identity == 123 + assert alice.id == 123 assert alice.labels == {"Person"} assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice" @@ -186,7 +186,7 @@ def test_can_hydrate_in_list(self): alice_in_list = hydrated([struct]) assert isinstance(alice_in_list, list) alice, = alice_in_list - assert alice.identity == 123 + assert alice.id == 123 assert alice.labels == {"Person"} assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice" @@ -199,7 +199,7 @@ def test_can_hydrate_in_dict(self): alice_in_dict = hydrated({"foo": struct}) assert isinstance(alice_in_dict, dict) alice = alice_in_dict["foo"] - assert alice.identity == 123 + assert alice.id == 123 assert alice.labels == {"Person"} assert set(alice.keys()) == {"name"} assert alice.get("name") == "Alice"