Skip to content

Commit 79996d3

Browse files
committed
Updated to fit with latest feature files. There are no longer tests for sending
path/node/relationship as parameters since this is not supported.
2 parents a255661 + 66ad752 commit 79996d3

File tree

8 files changed

+49
-147
lines changed

8 files changed

+49
-147
lines changed

neo4j/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
# limitations under the License.
2020

2121

22-
from neo4j.meta import version as __version__
22+
from .meta import version as __version__

neo4j/v1/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from socket import create_connection, SHUT_RDWR
3030
from struct import pack as struct_pack, unpack as struct_unpack, unpack_from as struct_unpack_from
3131

32-
from neo4j.meta import version
32+
from ..meta import version
3333
from .compat import hex2, secure_socket
3434
from .exceptions import ProtocolError
3535
from .packstream import Packer, Unpacker
@@ -220,7 +220,7 @@ def __init__(self, sock, **config):
220220
self.responses = deque()
221221

222222
# Determine the user agent and ensure it is a Unicode value
223-
user_agent = config.get("user-agent", DEFAULT_USER_AGENT)
223+
user_agent = config.get("user_agent", DEFAULT_USER_AGENT)
224224
if isinstance(user_agent, bytes):
225225
user_agent = user_agent.decode("UTF-8")
226226

neo4j/v1/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def session(self, **config):
9999
>>> session = driver.session()
100100
101101
"""
102-
return Session(connect(self.host, self.port, **config))
102+
return Session(connect(self.host, self.port, **dict(self.config, **config)))
103103

104104

105105
class Result(list):

neo4j/v1/typesystem.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ def hydrate(cls, identity, start, end, type, properties=None):
119119
return inst
120120

121121
def __init__(self, start, end, type, properties=None, **kwproperties):
122+
assert isinstance(start, int)
123+
assert isinstance(end, int)
122124
super(Relationship, self).__init__(type, properties, **kwproperties)
123125
self.start = start
124126
self.end = end
@@ -172,10 +174,11 @@ def hydrate(cls, nodes, rels, sequence):
172174
assert rel_index != 0
173175
next_node = nodes[sequence[2 * i + 1]]
174176
if rel_index > 0:
175-
entities.append(rels[rel_index - 1].bind(last_node, next_node))
177+
entities.append(rels[rel_index - 1].bind(last_node.identity, next_node.identity))
176178
else:
177-
entities.append(rels[-rel_index - 1].bind(next_node, last_node))
179+
entities.append(rels[-rel_index - 1].bind(next_node.identity, last_node.identity))
178180
entities.append(next_node)
181+
last_node = next_node
179182
return cls(*entities)
180183

181184
def __init__(self, start_node, *rels_and_nodes):

test/tck/configure_feature_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def clean_up():
7-
dir_path = (os.path.dirname(os.path.realpath(__file__)))#'test/tck/'
7+
dir_path = (os.path.dirname(os.path.realpath(__file__)))
88
files = os.listdir(dir_path)
99
for f in files:
1010
if not os.path.isdir(f) and ".feature" in f:

test/tck/steps/bolt_type_steps.py

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ def step_impl(context):
3838
context.M = {}
3939

4040

41-
@given("an empty node N")
42-
def step_impl(context):
43-
context.N = Node()
44-
45-
46-
@given("a node N with properties and labels")
47-
def step_impl(context):
48-
context.N = Node({"Person"}, {"name": "Alice", "age": 33})
49-
50-
5141
@given("a String of size (?P<size>\d+)")
5242
def step_impl(context, size):
5343
context.expected = tck_util.get_random_string(int(size))
@@ -120,13 +110,6 @@ def step_impl(context):
120110
context.results["as_parameters"] = tck_util.send_parameters("RETURN {input}", {'input': context.expected})
121111

122112

123-
@when("the driver asks the server to echo this node back")
124-
def step_impl(context):
125-
context.expected = context.N
126-
context.results = {}
127-
context.results["as_parameters"] = tck_util.send_parameters("RETURN {input}", {'input': context.expected})
128-
129-
130113
@then("the result returned from the server should be a single record with a single value")
131114
def step_impl(context):
132115
assert len(context.results) > 0
@@ -154,88 +137,4 @@ def step_impl(context):
154137
assert result_value.values() == context.expected.values()
155138
assert result_value.items() == context.expected.items()
156139
assert len(result_value) == len(context.expected)
157-
assert iter(result_value) == iter(context.expected)
158-
159-
160-
##CURRENTLY NOT SUPPORTED IN PYTHON DRIVERS
161-
162-
@given("a relationship R")
163-
def step_impl(context):
164-
alice = Node({"Person"}, {"name": "Alice", "age": 33})
165-
bob = Node({"Person"}, {"name": "Bob", "age": 44})
166-
context.R = Relationship(alice, bob, "KNOWS", {"since": 1999})
167-
168-
169-
@when("the driver asks the server to echo this relationship R back")
170-
def step_impl(context):
171-
context.expected = context.R
172-
context.results = {}
173-
context.results["as_parameters"] = tck_util.send_parameters("RETURN {input}", {'input': context.expected})
174-
175-
176-
@step("the relationship value given in the result should be the same as what was sent")
177-
def step_impl(context):
178-
assert len(context.results) > 0
179-
for result in context.results.values():
180-
result_value = result[0].values()[0]
181-
assert result_value == context.expected
182-
assert result_value.start == context.expected.start
183-
assert result_value.type == context.expected.type
184-
assert result_value.end == context.expected.end
185-
assert result_value.items() == context.expected.items()
186-
assert result_value.keys() == context.expected.keys()
187-
assert result_value.values() == context.expected.values()
188-
189-
190-
@given("a zero length path P")
191-
def step_impl(context):
192-
context.P = Path(Node({"Person"}, {"name": "Alice", "age": 33}))
193-
194-
195-
@given("a arbitrary long path P")
196-
def step_impl(context):
197-
alice = Node({"Person"}, {"name": "Alice", "age": 33})
198-
bob = Node({"Person"}, {"name": "Bob", "age": 44})
199-
carol = Node({"Person"}, {"name": "Carol", "age": 55})
200-
alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999})
201-
carol_dislikes_bob = Relationship(carol, bob, "DISLIKES")
202-
context.P = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
203-
204-
205-
@when("the driver asks the server to echo this path back")
206-
def step_impl(context):
207-
context.expected = context.P
208-
context.results = {}
209-
context.results["as_parameters"] = tck_util.send_parameters("RETURN {input}", {'input': context.expected})
210-
211-
212-
@step("the path value given in the result should be the same as what was sent")
213-
def step_impl(context):
214-
assert len(context.results) > 0
215-
for result in context.results.values():
216-
result_value = result[0].values()[0]
217-
assert result_value == context.expected
218-
assert result_value.start == context.expected.start
219-
assert result_value.end == context.expected.end
220-
assert result_value.nodes == context.expected.nodes
221-
assert result_value.relationships == context.expected.relationships
222-
assert list(result_value) == list(context.expected)
223-
224-
225-
@given("a Node with great amount of properties and labels")
226-
def step_impl(context):
227-
context.N = Node(tck_util.get_list_of_random_type(1000, "String"),
228-
tck_util.get_dict_of_random_type(1000, "String"))
229-
230-
231-
@given("a path P of size (?P<size>\d+)")
232-
def step_impl(context, size):
233-
nodes_and_rels = [Node({tck_util.get_random_string(5)}, tck_util.get_dict_of_random_type(3, "String"))]
234-
for i in range(1, int(12)):
235-
n = nodes_and_rels.append(Node({tck_util.get_random_string(5)}, tck_util.get_dict_of_random_type(3, "String")))
236-
r = Relationship(nodes_and_rels[-1], n, tck_util.get_random_string(4),
237-
tck_util.get_dict_of_random_type(3, "String"))
238-
nodes_and_rels.append(r)
239-
nodes_and_rels.append(n)
240-
241-
context.P = Path(nodes_and_rels[0], nodes_and_rels[1:])
140+
assert iter(result_value) == iter(context.expected)

test/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_statement_without_parameters(self):
6060
result = session.run("CREATE (p:Person { name: 'The One' })")
6161
ones_created = result.summary.statistics.nodes_created
6262
print("There were {0} the ones created.".format(ones_created))
63-
#end::statement-without-parameterst[]
63+
#end::statement-without-parameters[]
6464
assert ones_created == 1
6565
session.close()
6666

test/test_typesystem.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,35 @@ def test_null_properties(self):
5757

5858
def test_node_equality(self):
5959
node_1 = Node()
60-
node_1.identity = "node/1234"
60+
node_1.identity = 1234
6161
node_2 = Node()
62-
node_2.identity = "node/1234"
62+
node_2.identity = 1234
6363
node_3 = Node()
64-
node_3.identity = "node/5678"
64+
node_3.identity = 5678
6565
assert node_1 == node_2
6666
assert node_1 != node_3
6767
assert node_1 != "this is not a node"
6868

6969
def test_node_hashing(self):
7070
node_1 = Node()
71-
node_1.identity = "node/1234"
71+
node_1.identity = 1234
7272
node_2 = Node()
73-
node_2.identity = "node/1234"
73+
node_2.identity = 1234
7474
node_3 = Node()
75-
node_3.identity = "node/5678"
75+
node_3.identity = 5678
7676
assert hash(node_1) == hash(node_2)
7777
assert hash(node_1) != hash(node_3)
7878

7979

8080
class RelationshipTestCase(TestCase):
8181

8282
def test_can_create_relationship(self):
83-
alice = Node({"Person"}, {"name": "Alice", "age": 33})
84-
bob = Node({"Person"}, {"name": "Bob", "age": 44})
85-
alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999})
86-
assert alice_knows_bob.start is alice
83+
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
84+
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
85+
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
86+
assert alice_knows_bob.start == alice.identity
8787
assert alice_knows_bob.type == "KNOWS"
88-
assert alice_knows_bob.end is bob
88+
assert alice_knows_bob.end == bob.identity
8989
assert set(alice_knows_bob.keys()) == {"since"}
9090
assert set(alice_knows_bob.values()) == {1999}
9191
assert set(alice_knows_bob.items()) == {("since", 1999)}
@@ -108,11 +108,11 @@ def test_can_create_unbound_relationship(self):
108108
class PathTestCase(TestCase):
109109

110110
def test_can_create_path(self):
111-
alice = Node({"Person"}, {"name": "Alice", "age": 33})
112-
bob = Node({"Person"}, {"name": "Bob", "age": 44})
113-
carol = Node({"Person"}, {"name": "Carol", "age": 55})
114-
alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999})
115-
carol_dislikes_bob = Relationship(carol, bob, "DISLIKES")
111+
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
112+
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
113+
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
114+
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
115+
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
116116
path = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
117117
assert path.start == alice
118118
assert path.end == carol
@@ -122,11 +122,11 @@ def test_can_create_path(self):
122122
assert repr(path)
123123

124124
def test_can_hydrate_path(self):
125-
alice = Node({"Person"}, {"name": "Alice", "age": 33})
126-
bob = Node({"Person"}, {"name": "Bob", "age": 44})
127-
carol = Node({"Person"}, {"name": "Carol", "age": 55})
128-
alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999})
129-
carol_dislikes_bob = Relationship(carol, bob, "DISLIKES")
125+
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
126+
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
127+
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
128+
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
129+
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
130130
path = Path.hydrate([alice, bob, carol],
131131
[alice_knows_bob.unbind(), carol_dislikes_bob.unbind()],
132132
[1, 1, -2, 2])
@@ -138,22 +138,22 @@ def test_can_hydrate_path(self):
138138
assert repr(path)
139139

140140
def test_path_equality(self):
141-
alice = Node({"Person"}, {"name": "Alice", "age": 33})
142-
bob = Node({"Person"}, {"name": "Bob", "age": 44})
143-
carol = Node({"Person"}, {"name": "Carol", "age": 55})
144-
alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999})
145-
carol_dislikes_bob = Relationship(carol, bob, "DISLIKES")
141+
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
142+
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
143+
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
144+
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
145+
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
146146
path_1 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
147147
path_2 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
148148
assert path_1 == path_2
149149
assert path_1 != "this is not a path"
150150

151151
def test_path_hashing(self):
152-
alice = Node({"Person"}, {"name": "Alice", "age": 33})
153-
bob = Node({"Person"}, {"name": "Bob", "age": 44})
154-
carol = Node({"Person"}, {"name": "Carol", "age": 55})
155-
alice_knows_bob = Relationship(alice, bob, "KNOWS", {"since": 1999})
156-
carol_dislikes_bob = Relationship(carol, bob, "DISLIKES")
152+
alice = Node.hydrate(1, {"Person"}, {"name": "Alice", "age": 33})
153+
bob = Node.hydrate(2, {"Person"}, {"name": "Bob", "age": 44})
154+
carol = Node.hydrate(3, {"Person"}, {"name": "Carol", "age": 55})
155+
alice_knows_bob = Relationship(alice.identity, bob.identity, "KNOWS", {"since": 1999})
156+
carol_dislikes_bob = Relationship(carol.identity, bob.identity, "DISLIKES")
157157
path_1 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
158158
path_2 = Path(alice, alice_knows_bob, bob, carol_dislikes_bob, carol)
159159
assert hash(path_1) == hash(path_2)
@@ -163,11 +163,11 @@ class HydrationTestCase(TestCase):
163163

164164
def test_can_hydrate_node_structure(self):
165165
struct = Structure(3, b'N')
166-
struct.append("node/123")
166+
struct.append(123)
167167
struct.append(["Person"])
168168
struct.append({"name": "Alice"})
169169
alice = hydrated(struct)
170-
assert alice.identity == "node/123"
170+
assert alice.identity == 123
171171
assert alice.labels == {"Person"}
172172
assert set(alice.keys()) == {"name"}
173173
assert alice.get("name") == "Alice"
@@ -180,26 +180,26 @@ def test_hydrating_unknown_structure_returns_same(self):
180180

181181
def test_can_hydrate_in_list(self):
182182
struct = Structure(3, b'N')
183-
struct.append("node/123")
183+
struct.append(123)
184184
struct.append(["Person"])
185185
struct.append({"name": "Alice"})
186186
alice_in_list = hydrated([struct])
187187
assert isinstance(alice_in_list, list)
188188
alice, = alice_in_list
189-
assert alice.identity == "node/123"
189+
assert alice.identity == 123
190190
assert alice.labels == {"Person"}
191191
assert set(alice.keys()) == {"name"}
192192
assert alice.get("name") == "Alice"
193193

194194
def test_can_hydrate_in_dict(self):
195195
struct = Structure(3, b'N')
196-
struct.append("node/123")
196+
struct.append(123)
197197
struct.append(["Person"])
198198
struct.append({"name": "Alice"})
199199
alice_in_dict = hydrated({"foo": struct})
200200
assert isinstance(alice_in_dict, dict)
201201
alice = alice_in_dict["foo"]
202-
assert alice.identity == "node/123"
202+
assert alice.identity == 123
203203
assert alice.labels == {"Person"}
204204
assert set(alice.keys()) == {"name"}
205205
assert alice.get("name") == "Alice"

0 commit comments

Comments
 (0)