more formatting
This commit is contained in:
@@ -483,7 +483,6 @@ class BaseCQLStatement(object):
|
|||||||
|
|
||||||
return long(((tmp - datetime.fromtimestamp(0)).total_seconds()) * 1000000)
|
return long(((tmp - datetime.fromtimestamp(0)).total_seconds()) * 1000000)
|
||||||
|
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class TzOffset(tzinfo):
|
|||||||
"""Minimal implementation of a timezone offset to help testing with timezone
|
"""Minimal implementation of a timezone offset to help testing with timezone
|
||||||
aware datetimes.
|
aware datetimes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, offset):
|
def __init__(self, offset):
|
||||||
self._offset = timedelta(hours=offset)
|
self._offset = timedelta(hours=offset)
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ class TzOffset(tzinfo):
|
|||||||
def dst(self, dt):
|
def dst(self, dt):
|
||||||
return timedelta(0)
|
return timedelta(0)
|
||||||
|
|
||||||
|
|
||||||
class TestModel(Model):
|
class TestModel(Model):
|
||||||
test_id = columns.Integer(primary_key=True)
|
test_id = columns.Integer(primary_key=True)
|
||||||
attempt_id = columns.Integer(primary_key=True)
|
attempt_id = columns.Integer(primary_key=True)
|
||||||
@@ -41,6 +43,7 @@ class TestModel(Model):
|
|||||||
expected_result = columns.Integer()
|
expected_result = columns.Integer()
|
||||||
test_result = columns.Integer()
|
test_result = columns.Integer()
|
||||||
|
|
||||||
|
|
||||||
class IndexedTestModel(Model):
|
class IndexedTestModel(Model):
|
||||||
test_id = columns.Integer(primary_key=True)
|
test_id = columns.Integer(primary_key=True)
|
||||||
attempt_id = columns.Integer(index=True)
|
attempt_id = columns.Integer(index=True)
|
||||||
@@ -48,6 +51,7 @@ class IndexedTestModel(Model):
|
|||||||
expected_result = columns.Integer()
|
expected_result = columns.Integer()
|
||||||
test_result = columns.Integer(index=True)
|
test_result = columns.Integer(index=True)
|
||||||
|
|
||||||
|
|
||||||
class TestMultiClusteringModel(Model):
|
class TestMultiClusteringModel(Model):
|
||||||
one = columns.Integer(primary_key=True)
|
one = columns.Integer(primary_key=True)
|
||||||
two = columns.Integer(primary_key=True)
|
two = columns.Integer(primary_key=True)
|
||||||
@@ -55,7 +59,6 @@ class TestMultiClusteringModel(Model):
|
|||||||
|
|
||||||
|
|
||||||
class TestQuerySetOperation(BaseCassEngTestCase):
|
class TestQuerySetOperation(BaseCassEngTestCase):
|
||||||
|
|
||||||
def test_query_filter_parsing(self):
|
def test_query_filter_parsing(self):
|
||||||
"""
|
"""
|
||||||
Tests the queryset filter method parses it's kwargs properly
|
Tests the queryset filter method parses it's kwargs properly
|
||||||
@@ -164,8 +167,8 @@ class TestQuerySetOperation(BaseCassEngTestCase):
|
|||||||
Tests that setting only or defer fields that don't exist raises an exception
|
Tests that setting only or defer fields that don't exist raises an exception
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class BaseQuerySetUsage(BaseCassEngTestCase):
|
|
||||||
|
|
||||||
|
class BaseQuerySetUsage(BaseCassEngTestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(BaseQuerySetUsage, cls).setUpClass()
|
super(BaseQuerySetUsage, cls).setUpClass()
|
||||||
@@ -201,9 +204,12 @@ class BaseQuerySetUsage(BaseCassEngTestCase):
|
|||||||
IndexedTestModel.objects.create(test_id=7, attempt_id=3, description='try8', expected_result=20, test_result=20)
|
IndexedTestModel.objects.create(test_id=7, attempt_id=3, description='try8', expected_result=20, test_result=20)
|
||||||
|
|
||||||
IndexedTestModel.objects.create(test_id=8, attempt_id=0, description='try9', expected_result=50, test_result=40)
|
IndexedTestModel.objects.create(test_id=8, attempt_id=0, description='try9', expected_result=50, test_result=40)
|
||||||
IndexedTestModel.objects.create(test_id=9, attempt_id=1, description='try10', expected_result=60, test_result=40)
|
IndexedTestModel.objects.create(test_id=9, attempt_id=1, description='try10', expected_result=60,
|
||||||
IndexedTestModel.objects.create(test_id=10, attempt_id=2, description='try11', expected_result=70, test_result=45)
|
test_result=40)
|
||||||
IndexedTestModel.objects.create(test_id=11, attempt_id=3, description='try12', expected_result=75, test_result=45)
|
IndexedTestModel.objects.create(test_id=10, attempt_id=2, description='try11', expected_result=70,
|
||||||
|
test_result=45)
|
||||||
|
IndexedTestModel.objects.create(test_id=11, attempt_id=3, description='try12', expected_result=75,
|
||||||
|
test_result=45)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
@@ -212,8 +218,8 @@ class BaseQuerySetUsage(BaseCassEngTestCase):
|
|||||||
drop_table(IndexedTestModel)
|
drop_table(IndexedTestModel)
|
||||||
drop_table(TestMultiClusteringModel)
|
drop_table(TestMultiClusteringModel)
|
||||||
|
|
||||||
class TestQuerySetCountSelectionAndIteration(BaseQuerySetUsage):
|
|
||||||
|
|
||||||
|
class TestQuerySetCountSelectionAndIteration(BaseQuerySetUsage):
|
||||||
def test_count(self):
|
def test_count(self):
|
||||||
""" Tests that adding filtering statements affects the count query as expected """
|
""" Tests that adding filtering statements affects the count query as expected """
|
||||||
assert TestModel.objects.count() == 12
|
assert TestModel.objects.count() == 12
|
||||||
@@ -354,10 +360,10 @@ class TestQuerySetCountSelectionAndIteration(BaseQuerySetUsage):
|
|||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TestQuerySetOrdering(BaseQuerySetUsage):
|
class TestQuerySetOrdering(BaseQuerySetUsage):
|
||||||
|
|
||||||
def test_order_by_success_case(self):
|
def test_order_by_success_case(self):
|
||||||
|
|
||||||
q = TestModel.objects(test_id=0).order_by('attempt_id')
|
q = TestModel.objects(test_id=0).order_by('attempt_id')
|
||||||
expected_order = [0, 1, 2, 3]
|
expected_order = [0, 1, 2, 3]
|
||||||
for model, expect in zip(q, expected_order):
|
for model, expect in zip(q, expected_order):
|
||||||
@@ -403,7 +409,6 @@ class TestQuerySetOrdering(BaseQuerySetUsage):
|
|||||||
|
|
||||||
|
|
||||||
class TestQuerySetSlicing(BaseQuerySetUsage):
|
class TestQuerySetSlicing(BaseQuerySetUsage):
|
||||||
|
|
||||||
def test_out_of_range_index_raises_error(self):
|
def test_out_of_range_index_raises_error(self):
|
||||||
q = TestModel.objects(test_id=0).order_by('attempt_id')
|
q = TestModel.objects(test_id=0).order_by('attempt_id')
|
||||||
with self.assertRaises(IndexError):
|
with self.assertRaises(IndexError):
|
||||||
@@ -435,8 +440,8 @@ class TestQuerySetSlicing(BaseQuerySetUsage):
|
|||||||
for model, expect in zip(q[:-1], expected_order[:-1]):
|
for model, expect in zip(q[:-1], expected_order[:-1]):
|
||||||
assert model.attempt_id == expect
|
assert model.attempt_id == expect
|
||||||
|
|
||||||
class TestQuerySetValidation(BaseQuerySetUsage):
|
|
||||||
|
|
||||||
|
class TestQuerySetValidation(BaseQuerySetUsage):
|
||||||
def test_primary_key_or_index_must_be_specified(self):
|
def test_primary_key_or_index_must_be_specified(self):
|
||||||
"""
|
"""
|
||||||
Tests that queries that don't have an equals relation to a primary key or indexed field fail
|
Tests that queries that don't have an equals relation to a primary key or indexed field fail
|
||||||
@@ -453,7 +458,6 @@ class TestQuerySetValidation(BaseQuerySetUsage):
|
|||||||
q = TestModel.objects(test_id__gt=0)
|
q = TestModel.objects(test_id__gt=0)
|
||||||
list([i for i in q])
|
list([i for i in q])
|
||||||
|
|
||||||
|
|
||||||
def test_indexed_field_can_be_queried(self):
|
def test_indexed_field_can_be_queried(self):
|
||||||
"""
|
"""
|
||||||
Tests that queries on an indexed field will work without any primary key relations specified
|
Tests that queries on an indexed field will work without any primary key relations specified
|
||||||
@@ -461,8 +465,8 @@ class TestQuerySetValidation(BaseQuerySetUsage):
|
|||||||
q = IndexedTestModel.objects(test_result=25)
|
q = IndexedTestModel.objects(test_result=25)
|
||||||
assert q.count() == 4
|
assert q.count() == 4
|
||||||
|
|
||||||
class TestQuerySetDelete(BaseQuerySetUsage):
|
|
||||||
|
|
||||||
|
class TestQuerySetDelete(BaseQuerySetUsage):
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
TestModel.objects.create(test_id=3, attempt_id=0, description='try9', expected_result=50, test_result=40)
|
TestModel.objects.create(test_id=3, attempt_id=0, description='try9', expected_result=50, test_result=40)
|
||||||
TestModel.objects.create(test_id=3, attempt_id=1, description='try10', expected_result=60, test_result=40)
|
TestModel.objects.create(test_id=3, attempt_id=1, description='try10', expected_result=60, test_result=40)
|
||||||
@@ -487,8 +491,8 @@ class TestQuerySetDelete(BaseQuerySetUsage):
|
|||||||
with self.assertRaises(query.QueryException):
|
with self.assertRaises(query.QueryException):
|
||||||
TestModel.objects(attempt_id=0).delete()
|
TestModel.objects(attempt_id=0).delete()
|
||||||
|
|
||||||
class TestQuerySetConnectionHandling(BaseQuerySetUsage):
|
|
||||||
|
|
||||||
|
class TestQuerySetConnectionHandling(BaseQuerySetUsage):
|
||||||
def test_conn_is_returned_after_filling_cache(self):
|
def test_conn_is_returned_after_filling_cache(self):
|
||||||
"""
|
"""
|
||||||
Tests that the queryset returns it's connection after it's fetched all of it's results
|
Tests that the queryset returns it's connection after it's fetched all of it's results
|
||||||
@@ -512,7 +516,6 @@ class TimeUUIDQueryModel(Model):
|
|||||||
|
|
||||||
|
|
||||||
class TestMinMaxTimeUUIDFunctions(BaseCassEngTestCase):
|
class TestMinMaxTimeUUIDFunctions(BaseCassEngTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TestMinMaxTimeUUIDFunctions, cls).setUpClass()
|
super(TestMinMaxTimeUUIDFunctions, cls).setUpClass()
|
||||||
@@ -616,7 +619,6 @@ class TestMinMaxTimeUUIDFunctions(BaseCassEngTestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestInOperator(BaseQuerySetUsage):
|
class TestInOperator(BaseQuerySetUsage):
|
||||||
|
|
||||||
def test_kwarg_success_case(self):
|
def test_kwarg_success_case(self):
|
||||||
""" Tests the in operator works with the kwarg query method """
|
""" Tests the in operator works with the kwarg query method """
|
||||||
q = TestModel.filter(test_id__in=[0, 1])
|
q = TestModel.filter(test_id__in=[0, 1])
|
||||||
@@ -637,8 +639,8 @@ class TestValuesList(BaseQuerySetUsage):
|
|||||||
item = q.values_list('expected_result', flat=True).first()
|
item = q.values_list('expected_result', flat=True).first()
|
||||||
assert item == 10
|
assert item == 10
|
||||||
|
|
||||||
class TestObjectsProperty(BaseQuerySetUsage):
|
|
||||||
|
|
||||||
|
class TestObjectsProperty(BaseQuerySetUsage):
|
||||||
def test_objects_property_returns_fresh_queryset(self):
|
def test_objects_property_returns_fresh_queryset(self):
|
||||||
assert TestModel.objects._result_cache is None
|
assert TestModel.objects._result_cache is None
|
||||||
len(TestModel.objects) # evaluate queryset
|
len(TestModel.objects) # evaluate queryset
|
||||||
|
|||||||
Reference in New Issue
Block a user