22
22
from unittest import TestCase
23
23
24
24
from mock import patch
25
+ from neo4j .v1 .exceptions import DriverError
25
26
from neo4j .v1 .session import GraphDatabase , CypherError , Record , record
26
27
from neo4j .v1 .typesystem import Node , Relationship , Path
27
28
@@ -191,25 +192,59 @@ def test_can_handle_cypher_error(self):
191
192
with self .assertRaises (CypherError ):
192
193
session .run ("X" ).close ()
193
194
194
- def test_can_obtain_summary_info (self ):
195
+ def test_keys_are_available_before_and_after_stream (self ):
196
+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
197
+ cursor = session .run ("UNWIND range(1, 10) AS n RETURN n" )
198
+ assert list (cursor .keys ()) == ["n" ]
199
+ _ = list (cursor .stream ())
200
+ assert list (cursor .keys ()) == ["n" ]
201
+
202
+ def test_keys_with_an_error (self ):
203
+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
204
+ cursor = session .run ("X" )
205
+ with self .assertRaises (CypherError ):
206
+ _ = list (cursor .keys ())
207
+
208
+
209
+ class SummaryTestCase (TestCase ):
210
+
211
+ def test_can_obtain_summary_after_consuming_result (self ):
195
212
with GraphDatabase .driver ("bolt://localhost" ).session () as session :
196
213
cursor = session .run ("CREATE (n) RETURN n" )
197
- summary = cursor .summarize ()
214
+ list (cursor .stream ())
215
+ summary = cursor .summary ()
198
216
assert summary .statement == "CREATE (n) RETURN n"
199
217
assert summary .parameters == {}
200
218
assert summary .statement_type == "rw"
201
219
assert summary .statistics .nodes_created == 1
202
220
221
+ def test_cannot_obtain_summary_without_consuming_result (self ):
222
+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
223
+ cursor = session .run ("CREATE (n) RETURN n" )
224
+ with self .assertRaises (DriverError ):
225
+ _ = cursor .summary ()
226
+
227
+ # def test_can_obtain_summary_immediately_if_empty_result(self):
228
+ # with GraphDatabase.driver("bolt://localhost").session() as session:
229
+ # cursor = session.run("CREATE (n)")
230
+ # summary = cursor.summary()
231
+ # assert summary.statement == "CREATE (n)"
232
+ # assert summary.parameters == {}
233
+ # assert summary.statement_type == "rw"
234
+ # assert summary.statistics.nodes_created == 1
235
+
203
236
def test_no_plan_info (self ):
204
237
with GraphDatabase .driver ("bolt://localhost" ).session () as session :
205
238
cursor = session .run ("CREATE (n) RETURN n" )
206
- assert cursor .summarize ().plan is None
207
- assert cursor .summarize ().profile is None
239
+ list (cursor .stream ())
240
+ assert cursor .summary ().plan is None
241
+ assert cursor .summary ().profile is None
208
242
209
243
def test_can_obtain_plan_info (self ):
210
244
with GraphDatabase .driver ("bolt://localhost" ).session () as session :
211
245
cursor = session .run ("EXPLAIN CREATE (n) RETURN n" )
212
- plan = cursor .summarize ().plan
246
+ list (cursor .stream ())
247
+ plan = cursor .summary ().plan
213
248
assert plan .operator_type == "ProduceResults"
214
249
assert plan .identifiers == ["n" ]
215
250
assert plan .arguments == {"planner" : "COST" , "EstimatedRows" : 1.0 , "version" : "CYPHER 3.0" ,
@@ -220,7 +255,8 @@ def test_can_obtain_plan_info(self):
220
255
def test_can_obtain_profile_info (self ):
221
256
with GraphDatabase .driver ("bolt://localhost" ).session () as session :
222
257
cursor = session .run ("PROFILE CREATE (n) RETURN n" )
223
- profile = cursor .summarize ().profile
258
+ list (cursor .stream ())
259
+ profile = cursor .summary ().profile
224
260
assert profile .db_hits == 0
225
261
assert profile .rows == 1
226
262
assert profile .operator_type == "ProduceResults"
@@ -232,14 +268,16 @@ def test_can_obtain_profile_info(self):
232
268
233
269
def test_no_notification_info (self ):
234
270
with GraphDatabase .driver ("bolt://localhost" ).session () as session :
235
- result = session .run ("CREATE (n) RETURN n" )
236
- notifications = result .summarize ().notifications
271
+ cursor = session .run ("CREATE (n) RETURN n" )
272
+ list (cursor .stream ())
273
+ notifications = cursor .summary ().notifications
237
274
assert notifications == []
238
275
239
276
def test_can_obtain_notification_info (self ):
240
277
with GraphDatabase .driver ("bolt://localhost" ).session () as session :
241
- result = session .run ("EXPLAIN MATCH (n), (m) RETURN n, m" )
242
- notifications = result .summarize ().notifications
278
+ cursor = session .run ("EXPLAIN MATCH (n), (m) RETURN n, m" )
279
+ list (cursor .stream ())
280
+ notifications = cursor .summary ().notifications
243
281
244
282
assert len (notifications ) == 1
245
283
notification = notifications [0 ]
@@ -261,19 +299,6 @@ def test_can_obtain_notification_info(self):
261
299
assert position .line == 1
262
300
assert position .column == 1
263
301
264
- def test_keys_are_available_before_and_after_stream (self ):
265
- with GraphDatabase .driver ("bolt://localhost" ).session () as session :
266
- cursor = session .run ("UNWIND range(1, 10) AS n RETURN n" )
267
- assert list (cursor .keys ()) == ["n" ]
268
- _ = list (cursor .stream ())
269
- assert list (cursor .keys ()) == ["n" ]
270
-
271
- def test_keys_with_an_error (self ):
272
- with GraphDatabase .driver ("bolt://localhost" ).session () as session :
273
- cursor = session .run ("X" )
274
- with self .assertRaises (CypherError ):
275
- _ = list (cursor .keys ())
276
-
277
302
278
303
class ResetTestCase (TestCase ):
279
304
0 commit comments