22
22
from unittest import skip , skipUnless
23
23
24
24
from neo4j .v1 import TRUST_ON_FIRST_USE , TRUST_SIGNED_CERTIFICATES , SSL_AVAILABLE
25
+ from neo4j .v1 .exceptions import CypherError
25
26
from test .util import ServerTestCase
26
27
27
28
# Do not change the contents of this tagged section without good reason*
@@ -50,7 +51,7 @@ def test_minimal_working_example(self):
50
51
driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ("neo4j" , "password" ))
51
52
session = driver .session ()
52
53
53
- session .run ("CREATE (a:Person {name:'Arthur', title:'King'})" , )
54
+ session .run ("CREATE (a:Person {name:'Arthur', title:'King'})" )
54
55
55
56
result = session .run ("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" )
56
57
for record in result :
@@ -70,7 +71,7 @@ def test_construct_driver(self):
70
71
71
72
def test_configuration (self ):
72
73
# tag::configuration[]
73
- driver = GraphDatabase .driver ("bolt://localhost" , max_pool_size = 10 )
74
+ driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ), max_pool_size = 10 )
74
75
# end::configuration[]
75
76
return driver
76
77
@@ -94,6 +95,13 @@ def test_tls_signed(self):
94
95
# end::tls-signed[]
95
96
assert driver
96
97
98
+ @skipUnless (SSL_AVAILABLE , "Bolt over TLS is not supported by this version of Python" )
99
+ def test_connect_with_auth_disabled (self ):
100
+ # tag::connect-with-auth-disabled[]
101
+ driver = GraphDatabase .driver ("bolt://localhost" , encrypted = True )
102
+ # end::connect-with-auth-disabled[]
103
+ assert driver
104
+
97
105
def test_statement (self ):
98
106
driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
99
107
session = driver .session ()
@@ -116,7 +124,7 @@ def test_result_traversal(self):
116
124
driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
117
125
session = driver .session ()
118
126
# tag::result-traversal[]
119
- search_term = "sword "
127
+ search_term = "Sword "
120
128
result = session .run ("MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} "
121
129
"RETURN weapon.name" , {"term" : search_term })
122
130
print ("List of weapons called %r:" % search_term )
@@ -125,6 +133,19 @@ def test_result_traversal(self):
125
133
# end::result-traversal[]
126
134
session .close ()
127
135
136
+ def test_access_record (self ):
137
+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
138
+ session = driver .session ()
139
+ # tag::access-record[]
140
+ search_term = "Arthur"
141
+ result = session .run ("MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} "
142
+ "RETURN weapon.name, weapon.material, weapon.size" , {"term" : search_term })
143
+ print ("List of weapons owned by %r:" % search_term )
144
+ for record in result :
145
+ print (", " .join ("%s: %s" % (key , record [key ]) for key in record .keys ()))
146
+ # end::access-record[]
147
+ session .close ()
148
+
128
149
def test_result_retention (self ):
129
150
driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
130
151
# tag::retain-result[]
@@ -199,3 +220,16 @@ def test_result_summary_notifications(self):
199
220
print (notification )
200
221
# end::result-summary-notifications[]
201
222
session .close ()
223
+
224
+ def test_handle_cypher_error (self ):
225
+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
226
+ session = driver .session ()
227
+ with self .assertRaises (RuntimeError ):
228
+ # tag::handle-cypher-error
229
+ try :
230
+ session .run ("This will cause a syntax error" ).consume ()
231
+ except CypherError :
232
+ raise RuntimeError ("Something really bad has happened!" )
233
+ finally :
234
+ session .close ()
235
+ # end::handle-cypher-error
0 commit comments