diff --git a/docs/source/index.rst b/docs/source/index.rst index a30b06c37..3fd269d95 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -71,24 +71,25 @@ Example .. code-block:: python - from neo4j.v1 import GraphDatabase + from neo4j.v1 import GraphDatabase, basic_auth - driver = GraphDatabase.driver("bolt://localhost") - session = driver.session() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "password")) - 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 tx: + session.run("MERGE (a:Person {name:'Alice'})") - 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}) - session.close() + for record in session.run("MATCH (a:Person {name:'Alice'})-[:KNOWS]->(friend) RETURN friend"): + print('Alice says, "hello, %s"' % record["friend"]["name"]) + + driver.close() Indices and tables diff --git a/examples/test_examples.py b/examples/test_examples.py index ffbe78598..aab4f1c53 100644 --- a/examples/test_examples.py +++ b/examples/test_examples.py @@ -45,7 +45,7 @@ class FreshDatabaseTestCase(ServerTestCase): def setUp(self): ServerTestCase.setUp(self) - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() + session = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() session.run("MATCH (n) DETACH DELETE n") session.close() @@ -54,7 +54,7 @@ class MinimalWorkingExampleTestCase(FreshDatabaseTestCase): def test_minimal_working_example(self): # tag::minimal-example[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest")) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neotest", "neotest")) session = driver.session() session.run("CREATE (a:Person {name:'Arthur', title:'King'})") @@ -71,45 +71,45 @@ class ExamplesTestCase(FreshDatabaseTestCase): def test_construct_driver(self): # tag::construct-driver[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest")) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neotest", "neotest")) # end::construct-driver[] return driver def test_configuration(self): # tag::configuration[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), max_pool_size=10) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neotest", "neotest"), max_pool_size=10) # end::configuration[] return driver @skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python") def test_tls_require_encryption(self): # tag::tls-require-encryption[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), encrypted=True) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neotest", "neotest"), encrypted=True) # end::tls-require-encryption[] @skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python") def test_tls_trust_on_first_use(self): # tag::tls-trust-on-first-use[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), encrypted=True, trust=TRUST_ON_FIRST_USE) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neotest", "neotest"), encrypted=True, trust=TRUST_ON_FIRST_USE) # end::tls-trust-on-first-use[] assert driver @skip("testing verified certificates not yet supported ") def test_tls_signed(self): # tag::tls-signed[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neotest", "neotest"), encrypted=True, trust=TRUST_SIGNED_CERTIFICATES) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neotest", "neotest"), encrypted=True, trust=TRUST_SIGNED_CERTIFICATES) # end::tls-signed[] assert driver @skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python") def test_connect_with_auth_disabled(self): # tag::connect-with-auth-disabled[] - driver = GraphDatabase.driver("bolt://localhost", encrypted=True) + driver = GraphDatabase.driver("bolt://localhost:7687", encrypted=True) # end::connect-with-auth-disabled[] assert driver def test_statement(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::statement[] result = session.run("CREATE (person:Person {name: {name}})", {"name": "Arthur"}) @@ -118,7 +118,7 @@ def test_statement(self): session.close() def test_statement_without_parameters(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::statement-without-parameters[] result = session.run("CREATE (person:Person {name: 'Arthur'})") @@ -127,7 +127,7 @@ def test_statement_without_parameters(self): session.close() def test_result_traversal(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::result-traversal[] search_term = "Sword" @@ -140,7 +140,7 @@ def test_result_traversal(self): session.close() def test_access_record(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::access-record[] search_term = "Arthur" @@ -153,7 +153,7 @@ def test_access_record(self): session.close() def test_result_retention(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) # tag::retain-result[] session = driver.session() result = session.run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} " @@ -166,7 +166,7 @@ def test_result_retention(self): assert isinstance(retained_result, list) def test_nested_statements(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::nested-statements[] result = session.run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} " @@ -179,7 +179,7 @@ def test_nested_statements(self): session.close() def test_transaction_commit(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::transaction-commit[] with session.begin_transaction() as tx: @@ -192,7 +192,7 @@ def test_transaction_commit(self): session.close() def test_transaction_rollback(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::transaction-rollback[] with session.begin_transaction() as tx: @@ -205,7 +205,7 @@ def test_transaction_rollback(self): session.close() def test_result_summary_query_profile(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::result-summary-query-profile[] result = session.run("PROFILE MATCH (p:Person {name: {name}}) " @@ -217,7 +217,7 @@ def test_result_summary_query_profile(self): session.close() def test_result_summary_notifications(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() # tag::result-summary-notifications[] result = session.run("EXPLAIN MATCH (king), (queen) RETURN king, queen") @@ -228,7 +228,7 @@ def test_result_summary_notifications(self): session.close() def test_handle_cypher_error(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session = driver.session() with self.assertRaises(RuntimeError): # tag::handle-cypher-error[] diff --git a/neo4j/__main__.py b/neo4j/__main__.py index 2d2036587..801e4f9ee 100644 --- a/neo4j/__main__.py +++ b/neo4j/__main__.py @@ -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") diff --git a/neo4j/v1/session.py b/neo4j/v1/session.py index b92fc2dcd..a59323d9f 100644 --- a/neo4j/v1/session.py +++ b/neo4j/v1/session.py @@ -28,7 +28,6 @@ from __future__ import division from collections import deque -import re from warnings import warn from .bolt import connect, Response, RUN, PULL_ALL, ConnectionPool @@ -44,9 +43,6 @@ from .types import hydrated -localhost = re.compile(r"^(localhost|127(\.\d+){3})$", re.IGNORECASE) - - class AuthToken(object): """ Container for auth information """ @@ -76,7 +72,7 @@ def driver(uri, **config): configuration: >>> from neo4j.v1 import GraphDatabase - >>> driver = GraphDatabase.driver("bolt://localhost") + >>> driver = GraphDatabase.driver("bolt://localhost:7687") :param uri: URI for a graph database :param config: configuration and authentication details (valid keys are listed below) diff --git a/test/auth.py b/test/auth.py index a84a31570..6d8308e6c 100644 --- a/test/auth.py +++ b/test/auth.py @@ -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__": diff --git a/test/test_stability.py b/test/test_stability.py index 88f940932..25b530dc3 100644 --- a/test/test_stability.py +++ b/test/test_stability.py @@ -34,7 +34,7 @@ class ServerRestartTestCase(ServerTestCase): # @skipIf(platform.system() == "Windows", "restart testing not supported on Windows") # def test_server_shutdown_detection(self): - # driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + # driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) # session = driver.session() # session.run("RETURN 1").consume() # assert restart_server()