1919# limitations under the License.
2020
2121
22+ from unittest import skip
23+
24+ from neo4j .v1 import TRUST_ON_FIRST_USE , TRUST_SIGNED_CERTIFICATES
2225from test .util import ServerTestCase
2326
27+ # Do not change the contents of this tagged section without good reason*
2428# tag::minimal-example-import[]
2529from neo4j .v1 import GraphDatabase , basic_auth
2630# end::minimal-example-import[]
31+ # (* "good reason" is defined as knowing what you are doing)
32+
33+
34+ auth_token = basic_auth ("neo4j" , "password" )
2735
2836
2937class FreshDatabaseTestCase (ServerTestCase ):
3038
3139 def setUp (self ):
3240 ServerTestCase .setUp (self )
33- session = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) ).session ()
41+ session = GraphDatabase .driver ("bolt://localhost" , auth = auth_token ).session ()
3442 session .run ("MATCH (n) DETACH DELETE n" )
3543 session .close ()
3644
@@ -42,11 +50,11 @@ def test_minimal_working_example(self):
4250 driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ("neo4j" , "password" ))
4351 session = driver .session ()
4452
45- session .run ("CREATE (neo :Person {name:'Neo ', age:23 })" )
53+ session .run ("CREATE (a :Person {name:'Arthur ', title:'King' })" , )
4654
47- result = session .run ("MATCH (p :Person) WHERE p .name = 'Neo ' RETURN p.age " )
55+ result = session .run ("MATCH (a :Person) WHERE a .name = 'Arthur ' RETURN a.name AS name, a.title AS title " )
4856 while result .next ():
49- print ("Neo is %d years old. " % result ["p.age" ] )
57+ print ("%s %s " % ( result ["title" ], result [ "name" ]) )
5058
5159 session .close ()
5260 # end::minimal-example[]
@@ -68,40 +76,40 @@ def test_configuration(self):
6876
6977 def test_tls_require_encryption (self ):
7078 # tag::tls-require-encryption[]
71- # TODO: Unfortunately, this feature is not yet implemented for Python
72- pass
79+ driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ("neo4j" , "password" ), encrypted = True )
7380 # end::tls-require-encryption[]
7481
7582 def test_tls_trust_on_first_use (self ):
7683 # tag::tls-trust-on-first-use[]
77- # TODO: Unfortunately, this feature is not yet implemented for Python
78- pass
84+ driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ("neo4j" , "password" ), encrypted = True , trust = TRUST_ON_FIRST_USE )
7985 # end::tls-trust-on-first-use[]
86+ assert driver
8087
88+ @skip ("testing verified certificates not yet supported " )
8189 def test_tls_signed (self ):
8290 # tag::tls-signed[]
83- # TODO: Unfortunately, this feature is not yet implemented for Python
84- pass
91+ driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ("neo4j" , "password" ), encrypted = True , trust = TRUST_SIGNED_CERTIFICATES )
8592 # end::tls-signed[]
93+ assert driver
8694
8795 def test_statement (self ):
88- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
96+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
8997 session = driver .session ()
9098 # tag::statement[]
91- session .run ("CREATE (person:Person {name: {name}})" , {"name" : "Neo " }).close ()
99+ session .run ("CREATE (person:Person {name: {name}})" , {"name" : "Arthur " }).close ()
92100 # end::statement[]
93101 session .close ()
94102
95103 def test_statement_without_parameters (self ):
96- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
104+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
97105 session = driver .session ()
98106 # tag::statement-without-parameters[]
99- session .run ("CREATE (person:Person {name: 'Neo '})" ).close ()
107+ session .run ("CREATE (person:Person {name: 'Arthur '})" ).close ()
100108 # end::statement-without-parameters[]
101109 session .close ()
102110
103111 def test_result_cursor (self ):
104- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
112+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
105113 session = driver .session ()
106114 # tag::result-cursor[]
107115 search_term = "hammer"
@@ -114,67 +122,67 @@ def test_result_cursor(self):
114122 session .close ()
115123
116124 def test_cursor_nesting (self ):
117- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
125+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
118126 session = driver .session ()
119127 # tag::retain-result-query[]
120- result = session .run ("MATCH (person :Person) WHERE person.dept = {dept } "
121- "RETURN id(person ) AS minion " , {"dept " : "IT " })
128+ result = session .run ("MATCH (knight :Person:Knight ) WHERE knight.castle = {castle } "
129+ "RETURN id(knight ) AS knight_id " , {"castle " : "Camelot " })
122130 while result .next ():
123- session .run ("MATCH (person ) WHERE id(person ) = {id} "
124- "MATCH (boss :Person) WHERE boss .name = {boss } "
125- "CREATE (person )-[:REPORTS_TO ]->(boss )" , {"id" : result ["minion " ], "boss " : "Bob " })
131+ session .run ("MATCH (knight ) WHERE id(knight ) = {id} "
132+ "MATCH (king :Person) WHERE king .name = {king } "
133+ "CREATE (knight )-[:DEFENDS ]->(king )" , {"id" : result ["knight_id " ], "king " : "Arthur " })
126134 # end::retain-result-query[]
127135 session .close ()
128136
129137 def test_result_retention (self ):
130- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
138+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
131139 session = driver .session ()
132140 # tag::retain-result-process[]
133- result = session .run ("MATCH (person :Person) WHERE person.dept = {dept } "
134- "RETURN id(person ) AS minion " , {"dept " : "IT " })
135- minion_records = list (result .stream ())
136-
137- for record in minion_records :
138- session .run ("MATCH (person ) WHERE id(person ) = {id} "
139- "MATCH (boss :Person) WHERE boss .name = {boss } "
140- "CREATE (person )-[:REPORTS_TO ]->(boss )" , {"id" : record ["minion " ], "boss " : "Bob " })
141+ result = session .run ("MATCH (knight :Person:Knight ) WHERE knight.castle = {castle } "
142+ "RETURN id(knight ) AS knight_id " , {"castle " : "Camelot " })
143+ id_records = list (result .stream ())
144+
145+ for record in id_records :
146+ session .run ("MATCH (knight ) WHERE id(knight ) = {id} "
147+ "MATCH (king :Person) WHERE king .name = {king } "
148+ "CREATE (knight )-[:DEFENDS ]->(king )" , {"id" : record ["knight_id " ], "king " : "Arthur " })
141149 # end::retain-result-process[]
142150 session .close ()
143151
144152 def test_transaction_commit (self ):
145- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
153+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
146154 session = driver .session ()
147155 # tag::transaction-commit[]
148156 tx = session .begin_transaction ()
149- tx .run ("CREATE (p :Person {name: 'The One '})" )
157+ tx .run ("CREATE (:Person {name: 'Guinevere '})" )
150158 tx .commit ()
151159 # end::transaction-commit[]
152- result = session .run ("MATCH (p:Person {name: 'The One '}) RETURN count(p)" )
160+ result = session .run ("MATCH (p:Person {name: 'Guinevere '}) RETURN count(p)" )
153161 assert result .next ()
154162 assert result ["count(p)" ] == 1
155163 assert result .at_end
156164 session .close ()
157165
158166 def test_transaction_rollback (self ):
159- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
167+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
160168 session = driver .session ()
161169 # tag::transaction-rollback[]
162170 tx = session .begin_transaction ()
163- tx .run ("CREATE (p :Person {name: 'The One '})" )
171+ tx .run ("CREATE (:Person {name: 'Merlin '})" )
164172 tx .rollback ()
165173 # end::transaction-rollback[]
166- result = session .run ("MATCH (p:Person {name: 'The One '}) RETURN count(p)" )
174+ result = session .run ("MATCH (p:Person {name: 'Merlin '}) RETURN count(p)" )
167175 assert result .next ()
168176 assert result ["count(p)" ] == 0
169177 assert result .at_end
170178 session .close ()
171179
172180 def test_result_summary_query_profile (self ):
173- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
181+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
174182 session = driver .session ()
175183 # tag::result-summary-query-profile[]
176184 result = session .run ("PROFILE MATCH (p:Person {name: {name}}) "
177- "RETURN id(p)" , {"name" : "The One " })
185+ "RETURN id(p)" , {"name" : "Arthur " })
178186 while result .next ():
179187 pass # skip the records to get to the summary
180188 print (result .summary .statement_type )
@@ -183,10 +191,10 @@ def test_result_summary_query_profile(self):
183191 session .close ()
184192
185193 def test_result_summary_notifications (self ):
186- driver = GraphDatabase .driver ("bolt://localhost" , auth = basic_auth ( "neo4j" , "password" ) )
194+ driver = GraphDatabase .driver ("bolt://localhost" , auth = auth_token )
187195 session = driver .session ()
188196 # tag::result-summary-notifications[]
189- result = session .run ("EXPLAIN MATCH (a ), (b ) RETURN a,b " )
197+ result = session .run ("EXPLAIN MATCH (king ), (queen ) RETURN king, queen " )
190198 while result .next ():
191199 pass # skip the records to get to the summary
192200 for notification in result .summary .notifications :
0 commit comments