Skip to content

Commit a50fcb0

Browse files
authored
Merge pull request apache#910 from datastax/python-888-tests
Added tests for PYTHON-888
2 parents b7d2994 + 6bae148 commit a50fcb0

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

tests/integration/cqlengine/query/test_batch_query.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from tests.integration.cqlengine.base import BaseCassEngTestCase
2323
from tests.integration.cqlengine import execute_count
2424
from cassandra.cluster import Session
25+
from cassandra.query import BatchType as cassandra_BatchType
26+
from cassandra.cqlengine.query import BatchType as cqlengine_BatchType
2527

2628

2729
class TestMultiKeyModel(Model):
@@ -37,6 +39,11 @@ class BatchQueryLogModel(Model):
3739
k = columns.Integer(primary_key=True)
3840
v = columns.Integer()
3941

42+
43+
class CounterBatchQueryModel(Model):
44+
k = columns.Integer(primary_key=True)
45+
v = columns.Counter()
46+
4047
class BatchQueryTests(BaseCassEngTestCase):
4148

4249
@classmethod
@@ -209,3 +216,76 @@ def test_batch_execute_no_timeout(self):
209216
with BatchQuery() as b:
210217
BatchQueryLogModel.batch(b).create(k=2, v=2)
211218
self.assertEqual(mock_execute.call_args[-1]['timeout'], NOT_SET)
219+
220+
221+
class BatchTypeQueryTests(BaseCassEngTestCase):
222+
def setUp(self):
223+
sync_table(TestMultiKeyModel)
224+
sync_table(CounterBatchQueryModel)
225+
226+
def tearDown(self):
227+
drop_table(TestMultiKeyModel)
228+
drop_table(CounterBatchQueryModel)
229+
230+
@execute_count(6)
231+
def test_cassandra_batch_type(self):
232+
"""
233+
Tests the different types of `class: cassandra.query.BatchType`
234+
235+
@since 3.13
236+
@jira_ticket PYTHON-88
237+
@expected_result batch query succeeds and the results
238+
are correctly readen
239+
240+
@test_category query
241+
"""
242+
with BatchQuery(batch_type=cassandra_BatchType.UNLOGGED) as b:
243+
TestMultiKeyModel.batch(b).create(partition=1, cluster=1)
244+
TestMultiKeyModel.batch(b).create(partition=1, cluster=2)
245+
246+
obj = TestMultiKeyModel.objects(partition=1)
247+
self.assertEqual(2, len(obj))
248+
249+
with BatchQuery(batch_type=cassandra_BatchType.COUNTER) as b:
250+
CounterBatchQueryModel.batch(b).create(k=1, v=1)
251+
CounterBatchQueryModel.batch(b).create(k=1, v=2)
252+
CounterBatchQueryModel.batch(b).create(k=1, v=10)
253+
254+
obj = CounterBatchQueryModel.objects(k=1)
255+
self.assertEqual(1, len(obj))
256+
self.assertEqual(obj[0].v, 13)
257+
258+
with BatchQuery(batch_type=cassandra_BatchType.LOGGED) as b:
259+
TestMultiKeyModel.batch(b).create(partition=1, cluster=1)
260+
TestMultiKeyModel.batch(b).create(partition=1, cluster=2)
261+
262+
obj = TestMultiKeyModel.objects(partition=1)
263+
self.assertEqual(2, len(obj))
264+
265+
@execute_count(4)
266+
def test_cqlengine_batch_type(self):
267+
"""
268+
Tests the different types of `class: cassandra.cqlengine.query.BatchType`
269+
270+
@since 3.13
271+
@jira_ticket PYTHON-88
272+
@expected_result batch query succeeds and the results
273+
are correctly readen
274+
275+
@test_category query
276+
"""
277+
with BatchQuery(batch_type=cqlengine_BatchType.Unlogged) as b:
278+
TestMultiKeyModel.batch(b).create(partition=1, cluster=1)
279+
TestMultiKeyModel.batch(b).create(partition=1, cluster=2)
280+
281+
obj = TestMultiKeyModel.objects(partition=1)
282+
self.assertEqual(2, len(obj))
283+
284+
with BatchQuery(batch_type=cqlengine_BatchType.Counter) as b:
285+
CounterBatchQueryModel.batch(b).create(k=1, v=1)
286+
CounterBatchQueryModel.batch(b).create(k=1, v=2)
287+
CounterBatchQueryModel.batch(b).create(k=1, v=10)
288+
289+
obj = CounterBatchQueryModel.objects(k=1)
290+
self.assertEqual(1, len(obj))
291+
self.assertEqual(obj[0].v, 13)

0 commit comments

Comments
 (0)