adding tests around counter columns
This commit is contained in:
64
cqlengine/tests/columns/test_counter_column.py
Normal file
64
cqlengine/tests/columns/test_counter_column.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from cqlengine import Model, ValidationError
|
||||
from cqlengine import columns
|
||||
from cqlengine.management import create_table, delete_table
|
||||
from cqlengine.tests.base import BaseCassEngTestCase
|
||||
|
||||
|
||||
class TestCounterModel(Model):
|
||||
partition = columns.UUID(primary_key=True, default=uuid4)
|
||||
cluster = columns.UUID(primary_key=True, default=uuid4)
|
||||
counter = columns.Counter()
|
||||
|
||||
|
||||
class TestClassConstruction(BaseCassEngTestCase):
|
||||
|
||||
def test_defining_a_non_counter_column_fails(self):
|
||||
""" Tests that defining a non counter column field fails """
|
||||
|
||||
def test_defining_a_primary_key_counter_column_fails(self):
|
||||
""" Tests that defining primary keys on counter columns fails """
|
||||
|
||||
|
||||
class TestCounterColumn(BaseCassEngTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestCounterColumn, cls).setUpClass()
|
||||
delete_table(TestCounterModel)
|
||||
create_table(TestCounterModel)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(TestCounterColumn, cls).tearDownClass()
|
||||
delete_table(TestCounterModel)
|
||||
|
||||
def test_updates(self):
|
||||
""" Tests that counter updates work as intended """
|
||||
instance = TestCounterModel.create()
|
||||
instance.counter += 5
|
||||
instance.save()
|
||||
|
||||
actual = TestCounterModel.get(partition=instance.partition)
|
||||
assert actual.counter == 5
|
||||
|
||||
def test_concurrent_updates(self):
|
||||
""" Tests updates from multiple queries reaches the correct value """
|
||||
instance = TestCounterModel.create()
|
||||
new1 = TestCounterModel.get(partition=instance.partition)
|
||||
new2 = TestCounterModel.get(partition=instance.partition)
|
||||
|
||||
new1.counter += 5
|
||||
new1.save()
|
||||
new2.counter += 5
|
||||
new2.save()
|
||||
|
||||
actual = TestCounterModel.get(partition=instance.partition)
|
||||
assert actual.counter == 10
|
||||
|
||||
def test_update_from_none(self):
|
||||
""" Tests that updating from None uses a create statement """
|
||||
|
||||
def test_multiple_inserts(self):
|
||||
""" Tests inserting over existing data works as expected """
|
||||
Reference in New Issue
Block a user