Skip to content

Reworked the docs example code #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Example Usage
.. code:: python

from neo4j.v1 import GraphDatabase, basic_auth
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"))
session = driver.session()
session.run("CREATE (a:Person {name:'Bob'})")
result = session.run("MATCH (a:Person) RETURN a.name AS name")
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Example

from neo4j.v1 import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost")
driver = GraphDatabase.driver("bolt://localhost:7687")
session = driver.session()

session.run("MERGE (a:Person {name:'Alice'})")
Expand Down
27 changes: 15 additions & 12 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@
from neo4j.v1.session import GraphDatabase, basic_auth


driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
session = driver.session()
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"))

session.run("MERGE (a:Person {name:'Alice'})")
with driver.session() as session:

friends = ["Bob", "Carol", "Dave", "Eve", "Frank"]
with session.begin_transaction() as tx:
for friend in friends:
tx.run("MATCH (a:Person {name:'Alice'}) "
"MERGE (a)-[:KNOWS]->(x:Person {name:{n}})", {"n": friend})
tx.success = True
with session.begin_transaction() as transaction:
transaction.run("MERGE (a:Person {name:'Alice'})")
transaction.success = True

for friend, in session.run("MATCH (a:Person {name:'Alice'})-[:KNOWS]->(x) RETURN x"):
print('Alice says, "hello, %s"' % friend["name"])
friends = ["Bob", "Carol", "Dave", "Eve", "Frank"]
with session.begin_transaction() as tx:
for friend in friends:
tx.run("MATCH (a:Person {name:'Alice'}) "
"MERGE (a)-[:KNOWS]->(x:Person {name:{n}})", {"n": friend})
tx.success = True

session.close()
for friend, in session.run("MATCH (a:Person {name:'Alice'})-[:KNOWS]->(x) RETURN x"):
print('Alice says, "hello, %s"' % friend["name"])

# TODO: driver.close()
277 changes: 152 additions & 125 deletions examples/test_examples.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion neo4j/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():
parser.add_argument("-p", "--parameter", action="append", metavar="NAME=VALUE")
parser.add_argument("-q", "--quiet", action="store_true")
parser.add_argument("-U", "--user", default="neo4j")
parser.add_argument("-u", "--url", default="bolt://localhost", metavar="CONNECTION_URL")
parser.add_argument("-u", "--url", default="bolt://localhost:7687", metavar="CONNECTION_URL")
parser.add_argument("-v", "--verbose", action="count")
parser.add_argument("-x", "--times", type=int, default=1)
parser.add_argument("-z", "--summary", action="store_true")
Expand Down
4 changes: 2 additions & 2 deletions neo4j/v1/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def driver(url, **config):
configuration:

>>> from neo4j.v1 import GraphDatabase
>>> driver = GraphDatabase.driver("bolt://localhost")
>>> driver = GraphDatabase.driver("bolt://localhost:7687")

"""
return Driver(url, **config)
Expand Down Expand Up @@ -152,7 +152,7 @@ def session(self):
specified within this driver:

>>> from neo4j.v1 import GraphDatabase
>>> driver = GraphDatabase.driver("bolt://localhost")
>>> driver = GraphDatabase.driver("bolt://localhost:7687")
>>> session = driver.session()
"""
session = None
Expand Down
2 changes: 1 addition & 1 deletion test/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def update_password(user, password, new_password):

token = basic_auth(user, password)
setattr(token, "new-credentials", new_password) # TODO: hopefully switch hyphen to underscore on server
GraphDatabase.driver("bolt://localhost", auth=token).session().close()
GraphDatabase.driver("bolt://localhost:7687", auth=token).session().close()


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions test/tck/steps/driver_auth_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

@given("a driver configured with auth disabled")
def step_impl(context):
context.driver = GraphDatabase.driver("bolt://localhost", encrypted=False)
context.driver = GraphDatabase.driver("bolt://localhost:7687", encrypted=False)


@given("a driver is configured with auth enabled and correct password is provided")
def step_impl(context):
context.driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=False)
context.driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"), encrypted=False)


@given("a driver is configured with auth enabled and the wrong password is provided")
def step_impl(context):
context.driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "wrong"), encrypted=False)
context.driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "wrong"), encrypted=False)


@step("reading and writing to the database should be possible")
Expand Down
2 changes: 1 addition & 1 deletion test/tck/tck_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from test.tck.test_value import TestValue
from test.tck.resultparser import parse_values_to_comparable

driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), encrypted=False)
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"), encrypted=False)
runners = []


Expand Down
Loading