2424
2525
2626class RunTestCase (TestCase ):
27-
2827 def test_must_use_valid_url_scheme (self ):
2928 try :
3029 GraphDatabase .driver ("x://xxx" )
@@ -168,9 +167,65 @@ def test_can_obtain_summary_info(self):
168167 assert summary .statement_type == "rw"
169168 assert summary .statistics .nodes_created == 1
170169
170+ def test_no_plan_info (self ):
171+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
172+ result = session .run ("CREATE (n) RETURN n" )
173+ assert result .summarize ().plan is None
174+ assert result .summarize ().profile is None
175+
176+ def test_can_obtain_plan_info (self ):
177+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
178+ result = session .run ("EXPLAIN CREATE (n) RETURN n" )
179+ plan = result .summarize ().plan
180+ assert plan .operator_type == "ProduceResults"
181+ assert plan .identifiers == ["n" ]
182+ assert plan .arguments == {"planner" : "COST" , "EstimatedRows" : 1.0 , "version" : "CYPHER 3.0" ,
183+ "KeyNames" : "n" , "runtime-impl" : "INTERPRETED" , "planner-impl" : "IDP" ,
184+ "runtime" : "INTERPRETED" }
185+ assert len (plan .children ) == 1
186+
187+ def test_can_obtain_profile_info (self ):
188+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
189+ result = session .run ("PROFILE CREATE (n) RETURN n" )
190+ profile = result .summarize ().profile
191+ assert profile .db_hits == 0
192+ assert profile .rows == 1
193+ assert profile .operator_type == "ProduceResults"
194+ assert profile .identifiers == ["n" ]
195+ assert profile .arguments == {"planner" : "COST" , "EstimatedRows" : 1.0 , "version" : "CYPHER 3.0" ,
196+ "KeyNames" : "n" , "runtime-impl" : "INTERPRETED" , "planner-impl" : "IDP" ,
197+ "runtime" : "INTERPRETED" , "Rows" : 1 , "DbHits" : 0 }
198+ assert len (profile .children ) == 1
199+
200+ def test_no_notification_info (self ):
201+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
202+ result = session .run ("CREATE (n) RETURN n" )
203+ notifications = result .summarize ().notifications
204+ assert notifications == []
205+
206+ def test_can_obtain_notification_info (self ):
207+ with GraphDatabase .driver ("bolt://localhost" ).session () as session :
208+ result = session .run ("EXPLAIN MATCH (n), (m) RETURN n, m" )
209+ notifications = result .summarize ().notifications
210+
211+ assert len (notifications ) == 1
212+ notification = notifications [0 ]
213+ assert notification .code == "Neo.ClientNotification.Statement.CartesianProduct"
214+ assert notification .title == "This query builds a cartesian product between disconnected patterns."
215+ assert notification .description == \
216+ "If a part of a query contains multiple disconnected patterns, " \
217+ "this will build a cartesian product between all those parts. " \
218+ "This may produce a large amount of data and slow down query processing. " \
219+ "While occasionally intended, it may often be possible to reformulate the query " \
220+ "that avoids the use of this cross product, perhaps by adding a relationship between " \
221+ "the different parts or by using OPTIONAL MATCH (identifier is: (m))"
222+ position = notification .position
223+ assert position .offset == 0
224+ assert position .line == 1
225+ assert position .column == 1
171226
172- class TransactionTestCase (TestCase ):
173227
228+ class TransactionTestCase (TestCase ):
174229 def test_can_commit_transaction (self ):
175230 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
176231 tx = session .new_transaction ()
@@ -188,7 +243,7 @@ def test_can_commit_transaction(self):
188243
189244 # Check the property value
190245 result = session .run ("MATCH (a) WHERE id(a) = {n} "
191- "RETURN a.foo" , {"n" : node_id })
246+ "RETURN a.foo" , {"n" : node_id })
192247 foo = result [0 ][0 ]
193248 assert foo == "bar"
194249
@@ -209,13 +264,12 @@ def test_can_rollback_transaction(self):
209264
210265 # Check the property value
211266 result = session .run ("MATCH (a) WHERE id(a) = {n} "
212- "RETURN a.foo" , {"n" : node_id })
267+ "RETURN a.foo" , {"n" : node_id })
213268 assert len (result ) == 0
214269
215270 def test_can_commit_transaction_using_with_block (self ):
216271 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
217272 with session .new_transaction () as tx :
218-
219273 # Create a node
220274 result = tx .run ("CREATE (a) RETURN id(a)" )
221275 node_id = result [0 ][0 ]
@@ -229,14 +283,13 @@ def test_can_commit_transaction_using_with_block(self):
229283
230284 # Check the property value
231285 result = session .run ("MATCH (a) WHERE id(a) = {n} "
232- "RETURN a.foo" , {"n" : node_id })
286+ "RETURN a.foo" , {"n" : node_id })
233287 foo = result [0 ][0 ]
234288 assert foo == "bar"
235289
236290 def test_can_rollback_transaction_using_with_block (self ):
237291 with GraphDatabase .driver ("bolt://localhost" ).session () as session :
238292 with session .new_transaction () as tx :
239-
240293 # Create a node
241294 result = tx .run ("CREATE (a) RETURN id(a)" )
242295 node_id = result [0 ][0 ]
@@ -248,7 +301,7 @@ def test_can_rollback_transaction_using_with_block(self):
248301
249302 # Check the property value
250303 result = session .run ("MATCH (a) WHERE id(a) = {n} "
251- "RETURN a.foo" , {"n" : node_id })
304+ "RETURN a.foo" , {"n" : node_id })
252305 assert len (result ) == 0
253306
254307
0 commit comments