diff --git a/README.rst b/README.rst index cc2f099c8..44f930cd0 100644 --- a/README.rst +++ b/README.rst @@ -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") diff --git a/docs/source/index.rst b/docs/source/index.rst index 03bdd9fe6..70bd7c346 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -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'})") diff --git a/example.py b/example.py index 4d328243a..dc71bdfa5 100644 --- a/example.py +++ b/example.py @@ -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() diff --git a/examples/test_examples.py b/examples/test_examples.py index ba68fac0c..fb59ff0cf 100644 --- a/examples/test_examples.py +++ b/examples/test_examples.py @@ -39,25 +39,33 @@ class FreshDatabaseTestCase(ServerTestCase): def setUp(self): ServerTestCase.setUp(self) - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() - session.run("MATCH (n) DETACH DELETE n") - session.close() + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: + with session.begin_transaction() as tx: + tx.run("MATCH (n) DETACH DELETE n") + tx.success = True class MinimalWorkingExampleTestCase(FreshDatabaseTestCase): def test_minimal_working_example(self): # tag::minimal-example[] - 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("CREATE (a:Person {name:'Arthur', title:'King'})") + with driver.session() as session: - result = session.run("MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title") - for record in result: - print("%s %s" % (record["title"], record["name"])) + with session.begin_transaction() as tx: + tx.run("CREATE (a:Person {name: {name}, title: {title}})", + {"name": "Arthur", "title": "King"}) + tx.success = True - session.close() + with session.begin_transaction() as tx: + result = tx.run("MATCH (a:Person) WHERE a.name = {name} " + "RETURN a.name AS name, a.title AS title", + {"name": "Arthur"}) + for record in result: + print("%s %s" % (record["title"], record["name"])) + + # TODO: driver.close() # end::minimal-example[] @@ -65,171 +73,190 @@ class ExamplesTestCase(FreshDatabaseTestCase): def test_construct_driver(self): # tag::construct-driver[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j")) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j")) # end::construct-driver[] return driver def test_configuration(self): # tag::configuration[] - driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"), max_pool_size=10) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"), 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("neo4j", "neo4j"), encrypted=True) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"), 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("neo4j", "neo4j"), encrypted=True, trust=TRUST_ON_FIRST_USE) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"), 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("neo4j", "neo4j"), encrypted=True, trust=TRUST_SIGNED_CERTIFICATES) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "neo4j"), 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) - session = driver.session() - # tag::statement[] - result = session.run("CREATE (person:Person {name: {name}})", {"name": "Arthur"}) - # end::statement[] - result.consume() - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + with session.begin_transaction() as transaction: + # tag::statement[] + result = transaction.run("CREATE (person:Person {name: {name}})", {"name": "Arthur"}) + transaction.success = True + # end::statement[] + result.consume() + # TODO driver.close() def test_statement_without_parameters(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::statement-without-parameters[] - result = session.run("CREATE (person:Person {name: 'Arthur'})") - # end::statement-without-parameters[] - result.consume() - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + with session.begin_transaction() as transaction: + # tag::statement-without-parameters[] + result = transaction.run("CREATE (person:Person {name: 'Arthur'})") + transaction.success = True + # end::statement-without-parameters[] + result.consume() + # TODO driver.close() def test_result_traversal(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::result-traversal[] - search_term = "Sword" - result = session.run("MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} " - "RETURN weapon.name", {"term": search_term}) - print("List of weapons called %r:" % search_term) - for record in result: - print(record["weapon.name"]) - # end::result-traversal[] - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + with session.begin_transaction() as transaction: + # tag::result-traversal[] + search_term = "Sword" + result = transaction.run("MATCH (weapon:Weapon) WHERE weapon.name CONTAINS {term} " + "RETURN weapon.name", {"term": search_term}) + print("List of weapons called %r:" % search_term) + for record in result: + print(record["weapon.name"]) + # end::result-traversal[] + # TODO driver.close() def test_access_record(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::access-record[] - search_term = "Arthur" - result = session.run("MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} " - "RETURN weapon.name, weapon.material, weapon.size", {"term": search_term}) - print("List of weapons owned by %r:" % search_term) - for record in result: - print(", ".join("%s: %s" % (key, record[key]) for key in record.keys())) - # end::access-record[] - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + with session.begin_transaction() as transaction: + # tag::access-record[] + search_term = "Arthur" + result = transaction.run("MATCH (weapon:Weapon) WHERE weapon.owner CONTAINS {term} " + "RETURN weapon.name, weapon.material, weapon.size", + {"term": search_term}) + print("List of weapons owned by %r:" % search_term) + for record in result: + print(", ".join("%s: %s" % (key, record[key]) for key in record.keys())) + # end::access-record[] + # driver.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} " - "RETURN knight.name AS name", {"castle": "Camelot"}) - retained_result = list(result) - session.close() - for record in retained_result: - print("%s is a knight of Camelot" % record["name"]) - # end::retain-result[] - assert isinstance(retained_result, list) + with driver.session() as session: + + with session.begin_transaction() as tx: + result = tx.run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} " + "RETURN knight.name AS name", {"castle": "Camelot"}) + retained_result = list(result) + + for record in retained_result: + print("%s is a knight of Camelot" % record["name"]) + # end::retain-result[] + assert isinstance(retained_result, list) + # TODO driver.close() def test_nested_statements(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::nested-statements[] - result = session.run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} " - "RETURN id(knight) AS knight_id", {"castle": "Camelot"}) - for record in result: - session.run("MATCH (knight) WHERE id(knight) = {id} " - "MATCH (king:Person) WHERE king.name = {king} " - "CREATE (knight)-[:DEFENDS]->(king)", {"id": record["knight_id"], "king": "Arthur"}) - # end::nested-statements[] - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + # tag::nested-statements[] + with session.begin_transaction() as transaction: + result = transaction.run("MATCH (knight:Person:Knight) WHERE knight.castle = {castle} " + "RETURN id(knight) AS knight_id", {"castle": "Camelot"}) + for record in result: + with session.begin_transaction() as tx: + tx.run("MATCH (knight) WHERE id(knight) = {id} " + "MATCH (king:Person) WHERE king.name = {king} " + "CREATE (knight)-[:DEFENDS]->(king)", + {"id": record["knight_id"], "king": "Arthur"}) + tx.success = True + # end::nested-statements[] + # TODO driver.close() def test_transaction_commit(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::transaction-commit[] - with session.begin_transaction() as tx: - tx.run("CREATE (:Person {name: 'Guinevere'})") - tx.success = True - # end::transaction-commit[] - result = session.run("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)") - record = next(iter(result)) - assert record["count(p)"] == 1 - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + # tag::transaction-commit[] + with session.begin_transaction() as tx: + tx.run("CREATE (:Person {name: 'Guinevere'})") + tx.success = True + # end::transaction-commit[] + with session.begin_transaction() as tx: + result = tx.run("MATCH (p:Person {name: 'Guinevere'}) RETURN count(p)") + record = next(iter(result)) + assert record["count(p)"] == 1 + # TODO driver.close() def test_transaction_rollback(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::transaction-rollback[] - with session.begin_transaction() as tx: - tx.run("CREATE (:Person {name: 'Merlin'})") - tx.success = False - # end::transaction-rollback[] - result = session.run("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)") - record = next(iter(result)) - assert record["count(p)"] == 0 - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + # tag::transaction-rollback[] + with session.begin_transaction() as tx: + tx.run("CREATE (:Person {name: 'Merlin'})") + tx.success = False + # end::transaction-rollback[] + with session.begin_transaction() as tx: + result = tx.run("MATCH (p:Person {name: 'Merlin'}) RETURN count(p)") + record = next(iter(result)) + assert record["count(p)"] == 0 + # TODO driver.close() def test_result_summary_query_profile(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::result-summary-query-profile[] - result = session.run("PROFILE MATCH (p:Person {name: {name}}) " - "RETURN id(p)", {"name": "Arthur"}) - summary = result.consume() - print(summary.statement_type) - print(summary.profile) - # end::result-summary-query-profile[] - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + with session.begin_transaction() as transaction: + # tag::result-summary-query-profile[] + result = transaction.run("PROFILE MATCH (p:Person {name: {name}}) " + "RETURN id(p)", {"name": "Arthur"}) + summary = result.consume() + print(summary.statement_type) + print(summary.profile) + # end::result-summary-query-profile[] + # TODO driver.close() def test_result_summary_notifications(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - # tag::result-summary-notifications[] - result = session.run("EXPLAIN MATCH (king), (queen) RETURN king, queen") - summary = result.consume() - for notification in summary.notifications: - print(notification) - # end::result-summary-notifications[] - session.close() + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + with session.begin_transaction() as transaction: + # tag::result-summary-notifications[] + result = transaction.run("EXPLAIN MATCH (king), (queen) RETURN king, queen") + summary = result.consume() + for notification in summary.notifications: + print(notification) + # end::result-summary-notifications[] + # TODO driver.close() def test_handle_cypher_error(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) - session = driver.session() - with self.assertRaises(RuntimeError): - # tag::handle-cypher-error[] - try: - session.run("This will cause a syntax error").consume() - except CypherError: - raise RuntimeError("Something really bad has happened!") - finally: - session.close() - # end::handle-cypher-error[] + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) + with driver.session() as session: + with session.begin_transaction() as transaction: + with self.assertRaises(RuntimeError): + # tag::handle-cypher-error[] + try: + transaction.run("This will cause a syntax error").consume() + except CypherError: + raise RuntimeError("Something really bad has happened!") + finally: + session.close() + # end::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 8f8891160..4bf2b2518 100644 --- a/neo4j/v1/session.py +++ b/neo4j/v1/session.py @@ -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) @@ -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 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/tck/steps/driver_auth_steps.py b/test/tck/steps/driver_auth_steps.py index edc9d266a..437dc7d4f 100644 --- a/test/tck/steps/driver_auth_steps.py +++ b/test/tck/steps/driver_auth_steps.py @@ -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") diff --git a/test/tck/tck_util.py b/test/tck/tck_util.py index 063e0635f..a4c124b29 100644 --- a/test/tck/tck_util.py +++ b/test/tck/tck_util.py @@ -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 = [] diff --git a/test/test_session.py b/test/test_session.py index 9695f3d5a..c05b323b4 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -39,13 +39,13 @@ class DriverTestCase(ServerTestCase): def test_healthy_session_will_be_returned_to_the_pool_on_close(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) assert len(driver.session_pool) == 0 driver.session().close() assert len(driver.session_pool) == 1 def test_unhealthy_session_will_not_be_returned_to_the_pool_on_close(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) assert len(driver.session_pool) == 0 session = driver.session() session.connection.defunct = True @@ -53,7 +53,7 @@ def test_unhealthy_session_will_not_be_returned_to_the_pool_on_close(self): assert len(driver.session_pool) == 0 def session_pool_cannot_exceed_max_size(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token, max_pool_size=1) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token, max_pool_size=1) assert len(driver.session_pool) == 0 driver.session().close() assert len(driver.session_pool) == 1 @@ -61,7 +61,7 @@ def session_pool_cannot_exceed_max_size(self): assert len(driver.session_pool) == 1 def test_session_that_dies_in_the_pool_will_not_be_given_out(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session_1 = driver.session() session_1.close() assert len(driver.session_pool) == 1 @@ -74,7 +74,7 @@ def test_must_use_valid_url_scheme(self): GraphDatabase.driver("x://xxx", auth=auth_token) def test_sessions_are_reused(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session_1 = driver.session() session_1.close() session_2 = driver.session() @@ -82,7 +82,7 @@ def test_sessions_are_reused(self): assert session_1 is session_2 def test_sessions_are_not_reused_if_still_in_use(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token) session_1 = driver.session() session_2 = driver.session() session_2.close() @@ -102,7 +102,7 @@ def test_fail_nicely_when_connecting_to_http_port(self): class SecurityTestCase(ServerTestCase): def test_insecure_session_uses_normal_socket(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token, encrypted=False) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token, encrypted=False) session = driver.session() connection = session.connection assert isinstance(connection.channel.socket, socket) @@ -111,7 +111,7 @@ def test_insecure_session_uses_normal_socket(self): @skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python") def test_tofu_session_uses_secure_socket(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token, encrypted=True, trust=TRUST_ON_FIRST_USE) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token, encrypted=True, trust=TRUST_ON_FIRST_USE) session = driver.session() connection = session.connection assert isinstance(connection.channel.socket, SSLSocket) @@ -120,7 +120,7 @@ def test_tofu_session_uses_secure_socket(self): @skipUnless(SSL_AVAILABLE, "Bolt over TLS is not supported by this version of Python") def test_tofu_session_trusts_certificate_after_first_use(self): - driver = GraphDatabase.driver("bolt://localhost", auth=auth_token, encrypted=True, trust=TRUST_ON_FIRST_USE) + driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token, encrypted=True, trust=TRUST_ON_FIRST_USE) session = driver.session() connection = session.connection certificate = connection.der_encoded_server_certificate @@ -134,7 +134,7 @@ def test_tofu_session_trusts_certificate_after_first_use(self): class RunTestCase(ServerTestCase): def test_can_run_simple_statement(self): - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() + session = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() result = session.run("RETURN 1 AS n") for record in result: assert record[0] == 1 @@ -151,7 +151,7 @@ def test_can_run_simple_statement(self): session.close() def test_can_run_simple_statement_with_params(self): - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() + session = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() count = 0 for record in session.run("RETURN {x} AS n", {"x": {"abc": ["d", "e", "f"]}}): assert record[0] == {"abc": ["d", "e", "f"]} @@ -163,17 +163,17 @@ def test_can_run_simple_statement_with_params(self): assert count == 1 def test_fails_on_bad_syntax(self): - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() + session = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() with self.assertRaises(CypherError): session.run("X").consume() def test_fails_on_missing_parameter(self): - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() + session = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() with self.assertRaises(CypherError): session.run("RETURN {x}").consume() def test_can_run_simple_statement_from_bytes_string(self): - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() + session = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() count = 0 for record in session.run(b"RETURN 1 AS n"): assert record[0] == 1 @@ -185,7 +185,7 @@ def test_can_run_simple_statement_from_bytes_string(self): assert count == 1 def test_can_run_statement_that_returns_multiple_records(self): - session = GraphDatabase.driver("bolt://localhost", auth=auth_token).session() + session = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() count = 0 for record in session.run("unwind(range(1, 10)) AS z RETURN z"): assert 1 <= record[0] <= 10 @@ -194,14 +194,14 @@ def test_can_run_statement_that_returns_multiple_records(self): assert count == 10 def test_can_use_with_to_auto_close_session(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: record_list = list(session.run("RETURN 1")) assert len(record_list) == 1 for record in record_list: assert record[0] == 1 def test_can_return_node(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: record_list = list(session.run("MERGE (a:Person {name:'Alice'}) RETURN a")) assert len(record_list) == 1 for record in record_list: @@ -211,7 +211,7 @@ def test_can_return_node(self): assert alice.properties == {"name": "Alice"} def test_can_return_relationship(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: reocrd_list = list(session.run("MERGE ()-[r:KNOWS {since:1999}]->() RETURN r")) assert len(reocrd_list) == 1 for record in reocrd_list: @@ -221,7 +221,7 @@ def test_can_return_relationship(self): assert rel.properties == {"since": 1999} def test_can_return_path(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: record_list = list(session.run("MERGE p=({name:'Alice'})-[:KNOWS]->({name:'Bob'}) RETURN p")) assert len(record_list) == 1 for record in record_list: @@ -234,19 +234,19 @@ def test_can_return_path(self): assert len(path.relationships) == 1 def test_can_handle_cypher_error(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: with self.assertRaises(CypherError): session.run("X").consume() def test_keys_are_available_before_and_after_stream(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("UNWIND range(1, 10) AS n RETURN n") assert list(result.keys()) == ["n"] list(result) assert list(result.keys()) == ["n"] def test_keys_with_an_error(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("X") with self.assertRaises(CypherError): list(result.keys()) @@ -255,7 +255,7 @@ def test_keys_with_an_error(self): class SummaryTestCase(ServerTestCase): def test_can_obtain_summary_after_consuming_result(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("CREATE (n) RETURN n") summary = result.consume() assert summary.statement == "CREATE (n) RETURN n" @@ -264,14 +264,14 @@ def test_can_obtain_summary_after_consuming_result(self): assert summary.counters.nodes_created == 1 def test_no_plan_info(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("CREATE (n) RETURN n") summary = result.consume() assert summary.plan is None assert summary.profile is None def test_can_obtain_plan_info(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("EXPLAIN CREATE (n) RETURN n") summary = result.consume() plan = summary.plan @@ -283,7 +283,7 @@ def test_can_obtain_plan_info(self): assert len(plan.children) == 1 def test_can_obtain_profile_info(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("PROFILE CREATE (n) RETURN n") summary = result.consume() profile = summary.profile @@ -297,14 +297,14 @@ def test_can_obtain_profile_info(self): assert len(profile.children) == 1 def test_no_notification_info(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("CREATE (n) RETURN n") summary = result.consume() notifications = summary.notifications assert notifications == [] def test_can_obtain_notification_info(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: result = session.run("EXPLAIN MATCH (n), (m) RETURN n, m") summary = result.consume() notifications = summary.notifications @@ -334,7 +334,7 @@ def test_can_obtain_notification_info(self): class ResetTestCase(ServerTestCase): def test_automatic_reset_after_failure(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: try: session.run("X").consume() except CypherError: @@ -346,7 +346,7 @@ def test_automatic_reset_after_failure(self): def test_defunct(self): from neo4j.v1.bolt import ChunkChannel, ProtocolError - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: assert not session.connection.defunct with patch.object(ChunkChannel, "chunk_reader", side_effect=ProtocolError()): with self.assertRaises(ProtocolError): @@ -428,7 +428,7 @@ def test_record_repr(self): class TransactionTestCase(ServerTestCase): def test_can_commit_transaction(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: tx = session.begin_transaction() # Create a node @@ -451,7 +451,7 @@ def test_can_commit_transaction(self): assert value == "bar" def test_can_rollback_transaction(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: tx = session.begin_transaction() # Create a node @@ -472,7 +472,7 @@ def test_can_rollback_transaction(self): assert len(list(result)) == 0 def test_can_commit_transaction_using_with_block(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: with session.begin_transaction() as tx: # Create a node result = tx.run("CREATE (a) RETURN id(a)") @@ -494,7 +494,7 @@ def test_can_commit_transaction_using_with_block(self): assert value == "bar" def test_can_rollback_transaction_using_with_block(self): - with GraphDatabase.driver("bolt://localhost", auth=auth_token).session() as session: + with GraphDatabase.driver("bolt://localhost:7687", auth=auth_token).session() as session: with session.begin_transaction() as tx: # Create a node result = tx.run("CREATE (a) RETURN id(a)") @@ -515,7 +515,7 @@ def test_can_rollback_transaction_using_with_block(self): class ResultConsumptionTestCase(ServerTestCase): def setUp(self): - self.driver = GraphDatabase.driver("bolt://localhost", auth=auth_token, encrypted=False) + self.driver = GraphDatabase.driver("bolt://localhost:7687", auth=auth_token, encrypted=False) def test_can_consume_result_immediately(self): session = self.driver.session() 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()