@@ -501,3 +501,67 @@ def test_can_rollback_transaction_using_with_block(self):
501501 result = session .run ("MATCH (a) WHERE id(a) = {n} "
502502 "RETURN a.foo" , {"n" : node_id })
503503 assert len (list (result )) == 0
504+
505+
506+ class ResultConsumptionTestCase (ServerTestCase ):
507+
508+ def setUp (self ):
509+ self .driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
510+
511+ def test_can_consume_result_immediately (self ):
512+ session = self .driver .session ()
513+ tx = session .begin_transaction ()
514+ result = tx .run ("UNWIND range(1, 3) AS n RETURN n" )
515+ assert [record [0 ] for record in result ] == [1 , 2 , 3 ]
516+ tx .commit ()
517+ session .close ()
518+
519+ def test_can_consume_result_after_commit (self ):
520+ session = self .driver .session ()
521+ tx = session .begin_transaction ()
522+ result = tx .run ("UNWIND range(1, 3) AS n RETURN n" )
523+ tx .commit ()
524+ assert [record [0 ] for record in result ] == [1 , 2 , 3 ]
525+ session .close ()
526+
527+ def test_can_consume_result_after_rollback (self ):
528+ session = self .driver .session ()
529+ tx = session .begin_transaction ()
530+ result = tx .run ("UNWIND range(1, 3) AS n RETURN n" )
531+ tx .rollback ()
532+ assert [record [0 ] for record in result ] == [1 , 2 , 3 ]
533+ session .close ()
534+
535+ def test_can_consume_result_after_session_close (self ):
536+ session = self .driver .session ()
537+ tx = session .begin_transaction ()
538+ result = tx .run ("UNWIND range(1, 3) AS n RETURN n" )
539+ tx .commit ()
540+ session .close ()
541+ assert [record [0 ] for record in result ] == [1 , 2 , 3 ]
542+
543+ def test_can_consume_result_after_session_reuse (self ):
544+ session = self .driver .session ()
545+ tx = session .begin_transaction ()
546+ result_a = tx .run ("UNWIND range(1, 3) AS n RETURN n" )
547+ tx .commit ()
548+ session .close ()
549+ session = self .driver .session ()
550+ tx = session .begin_transaction ()
551+ result_b = tx .run ("UNWIND range(4, 6) AS n RETURN n" )
552+ tx .commit ()
553+ session .close ()
554+ assert [record [0 ] for record in result_a ] == [1 , 2 , 3 ]
555+ assert [record [0 ] for record in result_b ] == [4 , 5 , 6 ]
556+
557+ def test_can_consume_result_after_session_with_error (self ):
558+ session = self .driver .session ()
559+ with self .assertRaises (CypherError ):
560+ session .run ("X" ).consume ()
561+ session .close ()
562+ session = self .driver .session ()
563+ tx = session .begin_transaction ()
564+ result = tx .run ("UNWIND range(1, 3) AS n RETURN n" )
565+ tx .commit ()
566+ session .close ()
567+ assert [record [0 ] for record in result ] == [1 , 2 , 3 ]
0 commit comments