19
19
class TestSessionTransaction :
20
20
21
21
def test_simple_unmanaged_session (self , wrappedClient : ImmuTestClient ):
22
- if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
22
+ if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
23
23
pytest .skip ("Version too low" )
24
- txInterface = wrappedClient .client .openSession ("immudb" , "immudb" , b"defaultdb" )
24
+ txInterface = wrappedClient .client .openSession (
25
+ "immudb" , "immudb" , b"defaultdb" )
25
26
try :
26
27
newTx = txInterface .newTx ()
27
28
table = wrappedClient ._generateTableName ()
28
- newTx .sqlExec (f"CREATE TABLE { table } (id INTEGER AUTO_INCREMENT, tester VARCHAR[10], PRIMARY KEY id)" )
29
+ newTx .sqlExec (
30
+ f"CREATE TABLE { table } (id INTEGER AUTO_INCREMENT, tester VARCHAR[10], PRIMARY KEY id)" )
29
31
commit = newTx .commit ()
30
32
assert commit .header .id != None
31
33
32
34
newTx = txInterface .newTx ()
33
- newTx .sqlExec (f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "123" })
34
- what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
35
- if wrappedClient .serverVersionEqual ("1.9DOM.0" ) and what == []:
35
+ newTx .sqlExec (
36
+ f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "123" })
37
+ what = newTx .sqlQuery (
38
+ f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
39
+ if wrappedClient .serverVersionEqual ("1.9DOM.0" ) and what == []:
36
40
pytest .xfail ("Known bug #1854" )
37
41
assert what == [{"id" : 1 , "tester" : '123' }]
38
42
commit = newTx .commit ()
39
43
assert commit .header .id != None
40
44
41
45
newTx = txInterface .newTx ()
42
- newTx .sqlExec (f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "321" })
43
- what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
44
- assert what == [{"id" : 1 , "tester" : '123' }, {"id" : 2 , "tester" : '321' }]
46
+ newTx .sqlExec (
47
+ f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "321" })
48
+ what = newTx .sqlQuery (
49
+ f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
50
+ assert what == [{"id" : 1 , "tester" : '123' },
51
+ {"id" : 2 , "tester" : '321' }]
45
52
commit = newTx .rollback ()
46
53
47
54
newTx = txInterface .newTx ()
48
- what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
55
+ what = newTx .sqlQuery (
56
+ f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
49
57
assert what == [{"id" : 1 , "tester" : '123' }]
50
58
commit = newTx .commit ()
51
59
wrappedClient .closeSession ()
@@ -56,40 +64,48 @@ def test_simple_unmanaged_session(self, wrappedClient: ImmuTestClient):
56
64
pass
57
65
58
66
def test_simple_managed_session (self , wrappedClient : ImmuTestClient ):
59
- if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
67
+ if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
60
68
pytest .skip ("Version too low" )
61
69
with wrappedClient .client .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
62
70
newTx = session .newTx ()
63
71
table = wrappedClient ._generateTableName ()
64
- newTx .sqlExec (f"CREATE TABLE { table } (id INTEGER AUTO_INCREMENT, tester VARCHAR[10], PRIMARY KEY id)" )
72
+ newTx .sqlExec (
73
+ f"CREATE TABLE { table } (id INTEGER AUTO_INCREMENT, tester VARCHAR[10], PRIMARY KEY id)" )
65
74
commit = newTx .commit ()
66
75
assert commit .header .id != None
67
76
68
77
newTx = session .newTx ()
69
- newTx .sqlExec (f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "123" })
70
- what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
71
- if wrappedClient .serverVersionEqual ("1.9DOM.0" ) and what == []:
78
+ newTx .sqlExec (
79
+ f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "123" })
80
+ what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (
81
+ ), columnNameMode = constants .COLUMN_NAME_MODE_FIELD , acceptStream = True )
82
+ if wrappedClient .serverVersionEqual ("1.9DOM.0" ) and what == []:
72
83
pytest .xfail ("Known bug #1854" )
73
- assert what == [{"id" : 1 , "tester" : '123' }]
84
+ assert list ( what ) == [{"id" : 1 , "tester" : '123' }]
74
85
commit = newTx .commit ()
75
86
assert commit .header .id != None
76
87
77
88
with wrappedClient .client .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
78
89
newTx = session .newTx ()
79
- newTx .sqlExec (f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "321" })
80
- what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
81
- assert what == [{"id" : 1 , "tester" : '123' }, {"id" : 2 , "tester" : '321' }]
90
+ newTx .sqlExec (
91
+ f"INSERT INTO { table } (tester) VALUES(@testParam)" , params = {"testParam" : "321" })
92
+ what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (
93
+ ), columnNameMode = constants .COLUMN_NAME_MODE_FIELD , acceptStream = True )
94
+ assert list (what ) == [{"id" : 1 , "tester" : '123' },
95
+ {"id" : 2 , "tester" : '321' }]
82
96
commit = newTx .rollback ()
83
97
84
98
newTx = session .newTx ()
85
- what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (), columnNameMode = constants .COLUMN_NAME_MODE_FIELD )
86
- assert what == [{"id" : 1 , "tester" : '123' }]
99
+ what = newTx .sqlQuery (f"SELECT * FROM { table } " , dict (
100
+ ), columnNameMode = constants .COLUMN_NAME_MODE_FIELD , acceptStream = True )
101
+ assert list (what ) == [{"id" : 1 , "tester" : '123' }]
87
102
commit = newTx .commit ()
88
103
89
104
def test_unmanaged_session (self , wrappedClient : ImmuTestClient ):
90
- if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
105
+ if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
91
106
pytest .skip ("Version too low" )
92
- currentTxInterface = wrappedClient .openSession ("immudb" , "immudb" , b"defaultdb" )
107
+ currentTxInterface = wrappedClient .openSession (
108
+ "immudb" , "immudb" , b"defaultdb" )
93
109
try :
94
110
wrappedClient .currentTx = currentTxInterface
95
111
key = wrappedClient .generateKeyName ().encode ("utf-8" )
@@ -101,13 +117,18 @@ def test_unmanaged_session(self, wrappedClient: ImmuTestClient):
101
117
a = wrappedClient .get (key )
102
118
assert a .value == b'1'
103
119
interface = wrappedClient .newTx ()
104
- table = wrappedClient .createTestTable ("id INTEGER AUTO_INCREMENT" , "tester VARCHAR[10]" , "PRIMARY KEY id" )
105
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "3" })
106
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "4" })
107
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "5" })
120
+ table = wrappedClient .createTestTable (
121
+ "id INTEGER AUTO_INCREMENT" , "tester VARCHAR[10]" , "PRIMARY KEY id" )
122
+ wrappedClient .insertToTable (
123
+ table , ["tester" ], ["@blabla" ], {"blabla" : "3" })
124
+ wrappedClient .insertToTable (
125
+ table , ["tester" ], ["@blabla" ], {"blabla" : "4" })
126
+ wrappedClient .insertToTable (
127
+ table , ["tester" ], ["@blabla" ], {"blabla" : "5" })
108
128
interface .commit ()
109
129
wrappedClient .closeSession ()
110
- currentTxInterface = wrappedClient .openSession ("immudb" , "immudb" , b"defaultdb" )
130
+ currentTxInterface = wrappedClient .openSession (
131
+ "immudb" , "immudb" , b"defaultdb" )
111
132
wrappedClient .currentTx = currentTxInterface
112
133
interface = wrappedClient .newTx ()
113
134
@@ -117,16 +138,20 @@ def test_unmanaged_session(self, wrappedClient: ImmuTestClient):
117
138
118
139
interface .commit ()
119
140
interface = wrappedClient .newTx ()
120
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
121
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
122
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
141
+ wrappedClient .insertToTable (
142
+ table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
143
+ wrappedClient .insertToTable (
144
+ table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
145
+ wrappedClient .insertToTable (
146
+ table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
123
147
interface .rollback ()
124
148
finally :
125
149
try :
126
150
wrappedClient .closeSession ()
127
151
except :
128
152
pass
129
- wrappedClient .currentTx = wrappedClient .openSession ("immudb" , "immudb" , b"defaultdb" )
153
+ wrappedClient .currentTx = wrappedClient .openSession (
154
+ "immudb" , "immudb" , b"defaultdb" )
130
155
interface = wrappedClient .newTx ()
131
156
what = wrappedClient .simpleSelect (table , ["tester" ], dict ())
132
157
concatenated = [item [0 ] for item in what ]
@@ -141,7 +166,7 @@ def test_unmanaged_session(self, wrappedClient: ImmuTestClient):
141
166
assert a .value == b'1'
142
167
143
168
def test_managed_session (self , wrappedClient : ImmuTestClient ):
144
- if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
169
+ if (not wrappedClient .serverHigherOrEqualsToVersion ("1.2.0" )):
145
170
pytest .skip ("Version too low" )
146
171
147
172
with wrappedClient .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
@@ -156,10 +181,14 @@ def test_managed_session(self, wrappedClient: ImmuTestClient):
156
181
with wrappedClient .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
157
182
wrappedClient .currentTx = session
158
183
interface = wrappedClient .newTx ()
159
- table = wrappedClient .createTestTable ("id INTEGER AUTO_INCREMENT" , "tester VARCHAR[10]" , "PRIMARY KEY id" )
160
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "3" })
161
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "4" })
162
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "5" })
184
+ table = wrappedClient .createTestTable (
185
+ "id INTEGER AUTO_INCREMENT" , "tester VARCHAR[10]" , "PRIMARY KEY id" )
186
+ wrappedClient .insertToTable (
187
+ table , ["tester" ], ["@blabla" ], {"blabla" : "3" })
188
+ wrappedClient .insertToTable (
189
+ table , ["tester" ], ["@blabla" ], {"blabla" : "4" })
190
+ wrappedClient .insertToTable (
191
+ table , ["tester" ], ["@blabla" ], {"blabla" : "5" })
163
192
interface .commit ()
164
193
165
194
with wrappedClient .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
@@ -172,9 +201,12 @@ def test_managed_session(self, wrappedClient: ImmuTestClient):
172
201
with wrappedClient .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
173
202
wrappedClient .currentTx = session
174
203
interface = wrappedClient .newTx ()
175
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
176
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
177
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
204
+ wrappedClient .insertToTable (
205
+ table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
206
+ wrappedClient .insertToTable (
207
+ table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
208
+ wrappedClient .insertToTable (
209
+ table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
178
210
interface .rollback ()
179
211
180
212
with wrappedClient .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
@@ -187,14 +219,20 @@ def test_managed_session(self, wrappedClient: ImmuTestClient):
187
219
with wrappedClient .openManagedSession ("immudb" , "immudb" , b"defaultdb" ) as session :
188
220
wrappedClient .currentTx = session
189
221
interface = wrappedClient .newTx ()
190
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
191
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
192
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
222
+ wrappedClient .insertToTable (
223
+ table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
224
+ wrappedClient .insertToTable (
225
+ table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
226
+ wrappedClient .insertToTable (
227
+ table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
193
228
rollbackAs = interface .rollback ()
194
229
interface = wrappedClient .newTx ()
195
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
196
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
197
- wrappedClient .insertToTable (table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
230
+ wrappedClient .insertToTable (
231
+ table , ["tester" ], ["@blabla" ], {"blabla" : "6" })
232
+ wrappedClient .insertToTable (
233
+ table , ["tester" ], ["@blabla" ], {"blabla" : "7" })
234
+ wrappedClient .insertToTable (
235
+ table , ["tester" ], ["@blabla" ], {"blabla" : "8" })
198
236
commitAs = interface .commit ()
199
237
assert commitAs .header .id != None
200
238
interface = wrappedClient .newTx ()
@@ -206,5 +244,3 @@ def test_managed_session(self, wrappedClient: ImmuTestClient):
206
244
concatenated = [item [0 ] for item in what ]
207
245
assert concatenated == ["3" , "4" , "5" , "6" , "7" , "8" ]
208
246
what = wrappedClient .commit ()
209
-
210
-
0 commit comments