|
26 | 26 | from mock import patch |
27 | 27 |
|
28 | 28 | from neo4j.v1.constants import TRUST_ON_FIRST_USE |
29 | | -from neo4j.v1.exceptions import CypherError |
| 29 | +from neo4j.v1.exceptions import CypherError, ResultError |
30 | 30 | from neo4j.v1.session import GraphDatabase, basic_auth, Record, SSL_AVAILABLE |
31 | 31 | from neo4j.v1.types import Node, Relationship, Path |
32 | 32 |
|
@@ -575,3 +575,27 @@ def test_can_consume_result_after_session_with_error(self): |
575 | 575 | tx.commit() |
576 | 576 | session.close() |
577 | 577 | assert [record[0] for record in result] == [1, 2, 3] |
| 578 | + |
| 579 | + def test_single_with_exactly_one_record(self): |
| 580 | + session = self.driver.session() |
| 581 | + result = session.run("UNWIND range(1, 1) AS n RETURN n") |
| 582 | + record = result.single() |
| 583 | + assert list(record.values()) == [1] |
| 584 | + |
| 585 | + def test_single_with_no_records(self): |
| 586 | + session = self.driver.session() |
| 587 | + result = session.run("CREATE ()") |
| 588 | + with self.assertRaises(ResultError): |
| 589 | + _ = result.single() |
| 590 | + |
| 591 | + def test_single_with_multiple_records(self): |
| 592 | + session = self.driver.session() |
| 593 | + result = session.run("UNWIND range(1, 3) AS n RETURN n") |
| 594 | + with self.assertRaises(ResultError): |
| 595 | + _ = result.single() |
| 596 | + |
| 597 | + def test_single_consumes_entire_result(self): |
| 598 | + session = self.driver.session() |
| 599 | + result = session.run("UNWIND range(1, 1) AS n RETURN n") |
| 600 | + _ = result.single() |
| 601 | + assert result._consumed |
0 commit comments