Skip to content

Commit baa9fb3

Browse files
author
Peter Wilhelmsson
committed
testkit: Support for routing stub tests
1 parent 582ed46 commit baa9fb3

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

testkitbackend/backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(self, rd, wr):
2626
self.drivers = {}
2727
self.sessions = {}
2828
self.results = {}
29+
self.transactions = {}
2930
self.key = 0
3031
# Collect all request handlers
3132
self._requestHandlers = dict(

testkitbackend/requests.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def NewSession(backend, data):
6868

6969
def SessionRun(backend, data):
7070
session = backend.sessions[data["sessionId"]].session
71-
print(data)
7271
cypher, params = fromtestkit.toCypherAndParams(data)
7372
# TODO: txMeta, timeout
7473
result = session.run(cypher, parameters=params)
@@ -85,10 +84,47 @@ def SessionClose(backend, data):
8584
backend.send_response("Session", {"id": key})
8685

8786

87+
def SessionBeginTransaction(backend, data):
88+
key = data["sessionId"]
89+
session = backend.sessions[key].session
90+
metadata = data.get('txMeta', None)
91+
timeout = data.get('timeout', None)
92+
if timeout:
93+
timeout = int(timeout)
94+
tx = session.begin_transaction(metadata=metadata, timeout=timeout)
95+
key = backend.next_key()
96+
backend.transactions[key] = tx
97+
backend.send_response("Transaction", {"id": key})
98+
99+
88100
def ResultNext(backend, data):
89101
result = backend.results[data["resultId"]]
90102
try:
91103
record = next(iter(result))
92104
except StopIteration:
93105
backend.send_response("NullRecord", {})
94106
backend.send_response("Record", totestkit.record(record))
107+
108+
109+
def TransactionRun(backend, data):
110+
key = data["txId"]
111+
tx = backend.transactions[key]
112+
cypher, params = fromtestkit.toCypherAndParams(data)
113+
result = tx.run(cypher, parameters=params)
114+
key = backend.next_key()
115+
backend.results[key] = result
116+
backend.send_response("Result", {"id": key})
117+
118+
119+
def TransactionCommit(backend, data):
120+
key = data["txId"]
121+
tx = backend.transactions[key]
122+
tx.commit()
123+
backend.send_response("Transaction", {"id": key})
124+
125+
126+
def TransactionRollback(backend, data):
127+
key = data["txId"]
128+
tx = backend.transactions[key]
129+
tx.rollback()
130+
backend.send_response("Transaction", {"id": key})

0 commit comments

Comments
 (0)