Skip to content

Commit 808cfa7

Browse files
committed
example updates
1 parent 26bb808 commit 808cfa7

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

examples/test_examples.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
from unittest import skip
2323

24-
from neo4j.v1 import basic_auth, TRUST_ON_FIRST_USE, TRUST_SIGNED_CERTIFICATES
24+
from neo4j.v1 import TRUST_ON_FIRST_USE, TRUST_SIGNED_CERTIFICATES
2525
from test.util import ServerTestCase
2626

2727
# Do not change the contents of this tagged section without good reason*
2828
# tag::minimal-example-import[]
29-
from neo4j.v1 import GraphDatabase
29+
from neo4j.v1 import GraphDatabase, basic_auth
3030
# end::minimal-example-import[]
3131
# (* "good reason" is defined as knowing what you are doing)
3232

@@ -96,15 +96,15 @@ def test_statement(self):
9696
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
9797
session = driver.session()
9898
# tag::statement[]
99-
session.run("CREATE (person:Person {name: {name}})", {"name": "Neo"}).close()
99+
session.run("CREATE (person:Person {name: {name}})", {"name": "Arthur"}).close()
100100
# end::statement[]
101101
session.close()
102102

103103
def test_statement_without_parameters(self):
104104
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
105105
session = driver.session()
106106
# tag::statement-without-parameters[]
107-
session.run("CREATE (person:Person {name: 'Neo'})").close()
107+
session.run("CREATE (person:Person {name: 'Arthur'})").close()
108108
# end::statement-without-parameters[]
109109
session.close()
110110

@@ -125,27 +125,27 @@ def test_cursor_nesting(self):
125125
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
126126
session = driver.session()
127127
# tag::retain-result-query[]
128-
result = session.run("MATCH (person:Person) WHERE person.dept = {dept} "
129-
"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"})
130130
while result.next():
131-
session.run("MATCH (person) WHERE id(person) = {id} "
132-
"MATCH (boss:Person) WHERE boss.name = {boss} "
133-
"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"})
134134
# end::retain-result-query[]
135135
session.close()
136136

137137
def test_result_retention(self):
138138
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
139139
session = driver.session()
140140
# tag::retain-result-process[]
141-
result = session.run("MATCH (person:Person) WHERE person.dept = {dept} "
142-
"RETURN id(person) AS minion", {"dept": "IT"})
143-
minion_records = list(result.stream())
144-
145-
for record in minion_records:
146-
session.run("MATCH (person) WHERE id(person) = {id} "
147-
"MATCH (boss:Person) WHERE boss.name = {boss} "
148-
"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"})
149149
# end::retain-result-process[]
150150
session.close()
151151

@@ -154,10 +154,10 @@ def test_transaction_commit(self):
154154
session = driver.session()
155155
# tag::transaction-commit[]
156156
tx = session.begin_transaction()
157-
tx.run("CREATE (p:Person {name: 'The One'})")
157+
tx.run("CREATE (:Person {name: 'Guinevere'})")
158158
tx.commit()
159159
# end::transaction-commit[]
160-
result = session.run("MATCH (p:Person {name: 'The One'}) RETURN count(p)")
160+
result = session.run("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)")
161161
assert result.next()
162162
assert result["count(p)"] == 1
163163
assert result.at_end
@@ -168,10 +168,10 @@ def test_transaction_rollback(self):
168168
session = driver.session()
169169
# tag::transaction-rollback[]
170170
tx = session.begin_transaction()
171-
tx.run("CREATE (p:Person {name: 'The One'})")
171+
tx.run("CREATE (:Person {name: 'Merlin'})")
172172
tx.rollback()
173173
# end::transaction-rollback[]
174-
result = session.run("MATCH (p:Person {name: 'The One'}) RETURN count(p)")
174+
result = session.run("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)")
175175
assert result.next()
176176
assert result["count(p)"] == 0
177177
assert result.at_end
@@ -182,7 +182,7 @@ def test_result_summary_query_profile(self):
182182
session = driver.session()
183183
# tag::result-summary-query-profile[]
184184
result = session.run("PROFILE MATCH (p:Person {name: {name}}) "
185-
"RETURN id(p)", {"name": "The One"})
185+
"RETURN id(p)", {"name": "Arthur"})
186186
while result.next():
187187
pass # skip the records to get to the summary
188188
print(result.summary.statement_type)
@@ -194,7 +194,7 @@ def test_result_summary_notifications(self):
194194
driver = GraphDatabase.driver("bolt://localhost", auth=auth_token)
195195
session = driver.session()
196196
# tag::result-summary-notifications[]
197-
result = session.run("EXPLAIN MATCH (a), (b) RETURN a,b")
197+
result = session.run("EXPLAIN MATCH (king), (queen) RETURN king, queen")
198198
while result.next():
199199
pass # skip the records to get to the summary
200200
for notification in result.summary.notifications:

0 commit comments

Comments
 (0)