Skip to content
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

8th and final round of migrating integration tests from Python #538

Merged
merged 5 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions nutkit/frontend/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ def process_transaction(self, req, fn, config=None, hooks=None):
"Should be RetryableTry or RetryableDone but was: %s" % res
)

def read_transaction(self, fn, tx_meta=None, hooks=None, **kwargs):
def execute_read(self, fn, tx_meta=None, hooks=None, **kwargs):
# Send request to enter transactional read function
req = protocol.SessionReadTransaction(
self._session.id, txMeta=tx_meta, **kwargs
)
return self.process_transaction(req, fn, hooks=hooks)

def write_transaction(self, fn, tx_meta=None, hooks=None, **kwargs):
def execute_write(self, fn, tx_meta=None, hooks=None, **kwargs):
# Send request to enter transactional read function
req = protocol.SessionWriteTransaction(
self._session.id, txMeta=tx_meta, **kwargs
Expand Down
6 changes: 3 additions & 3 deletions tests/neo4j/datatypes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def work(tx):
assert isinstance(result.next(), types.NullRecord)
return record_

record = self._session.read_transaction(work)
record = self._session.execute_read(work)
self.assertEqual(record, types.Record(values=[val]))

def _read_query_values(self, query, params=None):
Expand All @@ -45,7 +45,7 @@ def work(tx):
assert isinstance(result.next(), types.NullRecord)
return record_.values

return self._session.read_transaction(work)
return self._session.execute_read(work)

def _write_query_values(self, query, params=None):
values = []
Expand All @@ -60,5 +60,5 @@ def work(tx):
raise ApplicationCodeError

with self.assertRaises(types.FrontendError):
self._session.write_transaction(work)
self._session.execute_write(work)
return values
6 changes: 3 additions & 3 deletions tests/neo4j/datatypes/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def work(tx):

self._create_driver_and_session()

record = self._session.write_transaction(work)
record = self._session.execute_write(work)
self.assertIsInstance(record, types.Record)

node = record.values[0]
Expand All @@ -173,7 +173,7 @@ def work(tx):

self._create_driver_and_session()

record = self._session.write_transaction(work)
record = self._session.execute_write(work)
self.assertIsInstance(record, types.Record)
values = record.values
self.assertEqual(len(values), 3)
Expand Down Expand Up @@ -205,7 +205,7 @@ def work(tx):

self._create_driver_and_session()

record = self._session.write_transaction(work)
record = self._session.execute_write(work)
self.assertIsInstance(record, types.Record)
values = record.values
self.assertEqual(len(values), 6)
Expand Down
4 changes: 2 additions & 2 deletions tests/neo4j/datatypes/test_temporal_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def work(tx):

assert self._driver and self._session
try:
echoed_tz_id = self._session.read_transaction(work)
echoed_tz_id = self._session.execute_read(work)
return echoed_tz_id == tz_id
except types.DriverError as e:
assert tz_id in e.msg
Expand Down Expand Up @@ -208,7 +208,7 @@ def work(tx):
continue
with self.subTest(tz_id=tz_id):
dt, y, mo, d, h, m, s, ns, offset, tz = \
self._session.read_transaction(work)
self._session.execute_read(work)
cypher_dt = types.CypherDateTime(
y, mo, d, h, m, s, ns, offset, tz_id
)
Expand Down
2 changes: 1 addition & 1 deletion tests/neo4j/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def dummy_query(tx_or_session):

self.create_driver_and_session(auth_token)
if use_tx:
result = self._session.read_transaction(dummy_query)
result = self._session.execute_read(dummy_query)
else:
result = self._session.run("RETURN 2 as Number")
self.assertEqual(
Expand Down
6 changes: 3 additions & 3 deletions tests/neo4j/test_bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def work(tx):
result.next()

with self.assertRaises(types.DriverError) as exc:
self._session.read_transaction(work)
self._session.execute_read(work)
if get_driver_name() in ["java"]:
self.assertEqual(
"org.neo4j.driver.exceptions.ClientException",
Expand Down Expand Up @@ -151,7 +151,7 @@ def create_node(tx):

for _ in range(expected_node_count):
self._session = self._driver.session("w")
self._session.write_transaction(create_node)
self._session.execute_write(create_node)
bookmarks.append(self._session.last_bookmarks())
self._session.close()

Expand All @@ -167,7 +167,7 @@ def get_node_count(tx):
record = result.next()
return record.values[0]

count = self._session.read_transaction(get_node_count)
count = self._session.execute_read(get_node_count)
self.assertEqual(types.CypherInt(expected_node_count), count)

@cluster_unsafe_test
Expand Down
2 changes: 1 addition & 1 deletion tests/neo4j/test_direct_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def work(tx):

self._driver = get_driver(self._backend)
self._session = self._driver.session("w")
summary = self._session.read_transaction(work)
summary = self._session.execute_read(work)
result = self._driver.supports_multi_db()

self.assertTrue(result)
Expand Down
2 changes: 1 addition & 1 deletion tests/neo4j/test_session_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_autocommit_transactions_should_support_metadata(self):
self._session1 = self._driver.session("r")
result = self._session1.run(
"CALL tx.getMetaData",
tx_meta={k: v.value for k, v in metadata.items()}
tx_meta=metadata
)
record = result.next()
self.assertIsInstance(record, types.Record)
Expand Down
2 changes: 1 addition & 1 deletion tests/neo4j/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def work(tx):
return summary
params = {} if params is None else params
self._session = self._driver.session("w")
return self._session.write_transaction(work)
return self._session.execute_write(work)

def test_can_obtain_summary_after_consuming_result(self):
summary = self.get_summary("CREATE (n) RETURN n")
Expand Down
50 changes: 35 additions & 15 deletions tests/neo4j/test_tx_func_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,38 @@ def _test():
self._driver.close()
self._driver = get_driver(self._backend, user_agent="test")
self._session1 = self._driver.session("r", fetch_size=2)
self._session1.read_transaction(work)
self._session1.execute_read(work)
self._session1.close()
self._session1 = None

for consume in (True, False):
with self.subTest(consume=consume):
_test()

def test_parameter(self):
def work(tx):
result = tx.run("RETURN $x", {"x": types.CypherInt(1)})
self.assertEqual(list(result),
[types.Record([types.CypherInt(1)])])

self._session1 = self._driver.session("r")
self._session1.execute_read(work)

def test_meta_data(self):
metadata = {"foo": types.CypherFloat(1.5),
"bar": types.CypherString("baz")}

def work(tx):
result = tx.run("CALL tx.getMetaData")
record = result.next()
self.assertIsInstance(record, types.Record)
self.assertEqual(record.values, [types.CypherMap(metadata)])

self._session1 = self._driver.session("r")
self._session1.execute_read(
work, tx_meta=metadata,
)

def test_iteration_nested(self):
# Verifies that it is possible to nest results with small fetch sizes
# within a transaction function.
Expand Down Expand Up @@ -100,7 +124,7 @@ def nested(tx):
self.assertEqual(res0.next(), types.NullRecord())
return "done"

x = self._session1.read_transaction(nested)
x = self._session1.execute_read(nested)
self.assertEqual(lasts, {0: 6, 1: 11, 2: 1001})
self.assertEqual(x, "done")

Expand All @@ -112,7 +136,7 @@ def run(tx):
tx.run("CREATE (n:SessionNode) RETURN n")

self._session1 = self._driver.session("w")
self._session1.write_transaction(run)
self._session1.execute_write(run)
bookmarks = self._session1.last_bookmarks()
self.assertEqual(len(bookmarks), 1)
self.assertGreater(len(bookmarks[0]), 3)
Expand All @@ -126,7 +150,7 @@ def run(tx):

self._session1 = self._driver.session("w")
with self.assertRaises(types.FrontendError):
self._session1.write_transaction(run)
self._session1.execute_write(run)
bookmarks = self._session1.last_bookmarks()
self.assertEqual(len(bookmarks), 0)

Expand All @@ -151,15 +175,11 @@ def assertion_query(tx):
self._session1 = self._driver.session("w")
expected_exc = types.FrontendError
with self.assertRaises(expected_exc):
self._session1.write_transaction(run)
self._session1.execute_write(run)

self._session1.read_transaction(assertion_query)
self._session1.execute_read(assertion_query)

def test_tx_func_configuration(self):
# TODO: remove this block once all languages work
if get_driver_name() in ["java"]:
self.skipTest("Does not send metadata")

def run(tx):
values = []
result = tx.run("UNWIND [1,2,3,4] AS x RETURN x")
Expand All @@ -177,9 +197,9 @@ def run(tx):
metadata = {"foo": types.CypherFloat(1.5),
"bar": types.CypherString("baz")}
self._session1 = self._driver.session("w")
res = self._session1.read_transaction(
res = self._session1.execute_read(
run, timeout=3000,
tx_meta={k: v.value for k, v in metadata.items()}
tx_meta=metadata
)
self.assertEqual(res, list(map(types.CypherInt, range(1, 5))))

Expand All @@ -198,7 +218,7 @@ def update1(tx):
tx.run("MATCH (a:Node) SET a.property = 1").consume()

with self.assertRaises(types.FrontendError):
self._session2.write_transaction(update2, timeout=250)
self._session2.execute_write(update2, timeout=250)

def update2(tx):
nonlocal exc
Expand All @@ -215,11 +235,11 @@ def update2(tx):
exc = None

self._session1 = self._driver.session("w")
db = self._session1.write_transaction(create)
db = self._session1.execute_write(create)
self._session2 = self._driver.session(
"w", bookmarks=self._session1.last_bookmarks(), database=db
)
self._session1.write_transaction(update1)
self._session1.execute_write(update1)
self.assertIsInstance(exc, types.DriverError)

self.assertEqual(exc.code,
Expand Down
2 changes: 1 addition & 1 deletion tests/neo4j/test_tx_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_tx_configuration(self):
"bar": types.CypherString("baz")}
self._session1 = self._driver.session("r")
tx = self._session1.begin_transaction(
tx_meta={k: v.value for k, v in metadata.items()}, timeout=3000
tx_meta=metadata, timeout=3000
)
result = tx.run("UNWIND [1,2,3,4] AS x RETURN x")
values = []
Expand Down
16 changes: 8 additions & 8 deletions tests/stub/authorization/test_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def work(tx):
result = tx.run("RETURN 1 as n")
sequences.append(list(result))

session.read_transaction(work)
session.execute_read(work)
session.close()
driver.close()

Expand Down Expand Up @@ -442,7 +442,7 @@ def work(tx):
sequences.append(list(result))

with self.assertRaises(types.DriverError) as exc:
session.read_transaction(work)
session.execute_read(work)
self.assert_is_token_error(exc.exception)
session.close()
driver.close()
Expand Down Expand Up @@ -482,7 +482,7 @@ def work(tx):
result = tx.run("RETURN 1 as n")
sequences.append(list(result))

session.read_transaction(work, hooks={
session.execute_read(work, hooks={
"on_send_RetryableNegative": lambda _: self.switch_unused_servers(
(self._read_server1, self._read_server2), "reader_tx.script"
)
Expand Down Expand Up @@ -523,7 +523,7 @@ def work(tx):
sequences.append(list(result))

with self.assertRaises(types.DriverError) as exc:
session.read_transaction(work, hooks={
session.execute_read(work, hooks={
"on_send_RetryableNegative": lambda _:
self.switch_unused_servers(
(self._read_server1, self._read_server2),
Expand Down Expand Up @@ -573,7 +573,7 @@ def work(tx):
result = tx.run("RETURN 1 as n")
sequences.append(list(result))

session.read_transaction(work, hooks={
session.execute_read(work, hooks={
"on_send_RetryableNegative": lambda _: self.switch_unused_servers(
(self._read_server1, self._read_server2), "reader_tx.script"
)
Expand Down Expand Up @@ -612,7 +612,7 @@ def work(tx):
sequences.append(list(result))

with self.assertRaises(types.DriverError) as exc:
session.read_transaction(work, hooks={
session.execute_read(work, hooks={
"on_send_RetryableNegative": lambda _:
self.switch_unused_servers(
(self._read_server1, self._read_server2),
Expand Down Expand Up @@ -662,7 +662,7 @@ def work(tx):
result = tx.run("RETURN 1 as n")
sequences.append(list(result))

session.read_transaction(work, hooks={
session.execute_read(work, hooks={
"on_send_RetryablePositive": lambda _: self.switch_unused_servers(
(self._read_server1, self._read_server2), "reader_tx.script"
)
Expand Down Expand Up @@ -702,7 +702,7 @@ def work(tx):
sequences.append(list(result))

with self.assertRaises(types.DriverError) as exc:
session.read_transaction(work, hooks={
session.execute_read(work, hooks={
"on_send_RetryableNegative": lambda _:
self.switch_unused_servers(
(self._read_server1, self._read_server2),
Expand Down
4 changes: 2 additions & 2 deletions tests/stub/bookmarks/test_bookmarks_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ def test(mode_, bm_count_, check_bms_pre_query_, consume_):
sorted(bookmarks))
work = work_consume if consume_ else work_no_consume
if mode == "write":
session.write_transaction(work)
session.execute_write(work)
else:
session.read_transaction(work)
session.execute_read(work)
self.assertEqual(session.last_bookmarks(), ["bm:re"])
session.close()
server.done()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def work(tx):
self.assertIsInstance(result.next(), types.NullRecord)

self._start_server("1_second_exceeds_tx_retry.script")
self._session.write_transaction(work)
self._session.execute_write(work)
self._server.done()
self.assertEqual(retries, 2)
self.assertIsInstance(record, types.Record)
Expand Down Expand Up @@ -230,7 +230,7 @@ def work(tx):
self.assertIsInstance(result.next(), types.NullRecord)

self._start_server("2_seconds_in_time_tx_retry.script")
self._session.write_transaction(work)
self._session.execute_write(work)
self._server.done()
self.assertEqual(retries, 1)
self.assertIsInstance(record, types.Record)
Expand Down
Loading