Update imports for moved exceptions, in cqlengine tests
This commit is contained in:
@@ -17,7 +17,7 @@ import json
|
||||
from mock import patch
|
||||
|
||||
from cassandra.cqlengine import columns, SizeTieredCompactionStrategy, LeveledCompactionStrategy
|
||||
from cassandra.cqlengine.exceptions import CQLEngineException
|
||||
from cassandra.cqlengine import CQLEngineException
|
||||
from cassandra.cqlengine.management import get_compaction_options, drop_table, sync_table, get_table_settings
|
||||
from cassandra.cqlengine.models import Model
|
||||
|
||||
@@ -38,8 +38,7 @@ class BaseCompactionTest(BaseCassEngTestCase):
|
||||
|
||||
key = "__compaction_{}__".format(key)
|
||||
|
||||
with patch.object(self.model, key, 10), \
|
||||
self.assertRaises(CQLEngineException):
|
||||
with patch.object(self.model, key, 10), self.assertRaises(CQLEngineException):
|
||||
get_compaction_options(self.model)
|
||||
|
||||
|
||||
@@ -97,7 +96,6 @@ class LeveledcompactionTestTable(Model):
|
||||
user_id = columns.UUID(primary_key=True)
|
||||
name = columns.Text()
|
||||
|
||||
from cassandra.cqlengine.management import schema_columnfamilies
|
||||
|
||||
class AlterTableTest(BaseCassEngTestCase):
|
||||
|
||||
@@ -158,7 +156,6 @@ class AlterTableTest(BaseCassEngTestCase):
|
||||
|
||||
self.assertRegexpMatches(table_settings.options['compaction_strategy_class'], '.*SizeTieredCompactionStrategy$')
|
||||
|
||||
|
||||
def test_alter_options(self):
|
||||
|
||||
class AlterTable(Model):
|
||||
@@ -175,7 +172,6 @@ class AlterTableTest(BaseCassEngTestCase):
|
||||
sync_table(AlterTable)
|
||||
|
||||
|
||||
|
||||
class EmptyCompactionTest(BaseCassEngTestCase):
|
||||
def test_empty_compaction(self):
|
||||
class EmptyCompactionModel(Model):
|
||||
@@ -202,7 +198,6 @@ class CompactionSizeTieredModel(Model):
|
||||
name = columns.Text()
|
||||
|
||||
|
||||
|
||||
class OptionsTest(BaseCassEngTestCase):
|
||||
|
||||
def test_all_size_tiered_options(self):
|
||||
@@ -232,7 +227,6 @@ class OptionsTest(BaseCassEngTestCase):
|
||||
|
||||
self.assertDictEqual(options, expected)
|
||||
|
||||
|
||||
def test_all_leveled_options(self):
|
||||
|
||||
class AllLeveledOptionsModel(Model):
|
||||
@@ -250,4 +244,3 @@ class OptionsTest(BaseCassEngTestCase):
|
||||
|
||||
options = json.loads(settings['compaction_strategy_options'])
|
||||
self.assertDictEqual(options, {u'sstable_size_in_mb': u'64'})
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ import warnings
|
||||
|
||||
from cassandra.cqlengine import CACHING_ALL, CACHING_NONE
|
||||
from cassandra.cqlengine.connection import get_session, get_cluster
|
||||
from cassandra.cqlengine.exceptions import CQLEngineException
|
||||
from cassandra.cqlengine import CQLEngineException
|
||||
from cassandra.cqlengine import management
|
||||
from cassandra.cqlengine.management import get_fields, sync_table, drop_table
|
||||
from cassandra.cqlengine.management import get_fields, sync_table, drop_table
|
||||
from cassandra.cqlengine.models import Model
|
||||
from cassandra.cqlengine import columns, SizeTieredCompactionStrategy, LeveledCompactionStrategy
|
||||
|
||||
@@ -29,6 +29,7 @@ from tests.integration import CASSANDRA_VERSION, PROTOCOL_VERSION
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
from tests.integration.cqlengine.query.test_queryset import TestModel
|
||||
|
||||
|
||||
class KeyspaceManagementTest(BaseCassEngTestCase):
|
||||
def test_create_drop_succeeeds(self):
|
||||
cluster = get_cluster()
|
||||
@@ -71,18 +72,21 @@ class DropTableTest(BaseCassEngTestCase):
|
||||
drop_table(TestModel)
|
||||
drop_table(TestModel)
|
||||
|
||||
|
||||
class LowercaseKeyModel(Model):
|
||||
|
||||
first_key = columns.Integer(primary_key=True)
|
||||
second_key = columns.Integer(primary_key=True)
|
||||
some_data = columns.Text()
|
||||
|
||||
|
||||
class CapitalizedKeyModel(Model):
|
||||
|
||||
firstKey = columns.Integer(primary_key=True)
|
||||
secondKey = columns.Integer(primary_key=True)
|
||||
someData = columns.Text()
|
||||
|
||||
|
||||
class PrimaryKeysOnlyModel(Model):
|
||||
|
||||
__compaction__ = LeveledCompactionStrategy
|
||||
@@ -109,6 +113,7 @@ class FirstModel(Model):
|
||||
second_key = columns.UUID()
|
||||
third_key = columns.Text()
|
||||
|
||||
|
||||
class SecondModel(Model):
|
||||
|
||||
__table_name__ = 'first_model'
|
||||
@@ -117,6 +122,7 @@ class SecondModel(Model):
|
||||
third_key = columns.Text()
|
||||
fourth_key = columns.Text()
|
||||
|
||||
|
||||
class ThirdModel(Model):
|
||||
|
||||
__table_name__ = 'first_model'
|
||||
@@ -126,6 +132,7 @@ class ThirdModel(Model):
|
||||
# removed fourth key, but it should stay in the DB
|
||||
blah = columns.Map(columns.Text, columns.Text)
|
||||
|
||||
|
||||
class FourthModel(Model):
|
||||
|
||||
__table_name__ = 'first_model'
|
||||
@@ -135,6 +142,7 @@ class FourthModel(Model):
|
||||
# removed fourth key, but it should stay in the DB
|
||||
renamed = columns.Map(columns.Text, columns.Text, db_field='blah')
|
||||
|
||||
|
||||
class AddColumnTest(BaseCassEngTestCase):
|
||||
def setUp(self):
|
||||
drop_table(FirstModel)
|
||||
@@ -180,6 +188,7 @@ if CASSANDRA_VERSION >= '2.0.0':
|
||||
ModelWithTableProperties.__index_interval__ = 98706
|
||||
ModelWithTableProperties.__default_time_to_live__ = 4756
|
||||
|
||||
|
||||
class TablePropertiesTests(BaseCassEngTestCase):
|
||||
|
||||
def setUp(self):
|
||||
@@ -233,17 +242,17 @@ class TablePropertiesTests(BaseCassEngTestCase):
|
||||
table_settings = management.get_table_settings(ModelWithTableProperties).options
|
||||
|
||||
expected = {'bloom_filter_fp_chance': 0.66778,
|
||||
'comment': 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy',
|
||||
'gc_grace_seconds': 96362,
|
||||
'read_repair_chance': 0.2989,
|
||||
#'local_read_repair_chance': 0.12732,
|
||||
'comment': 'xirAkRWZVVvsmzRvXamiEcQkshkUIDINVJZgLYSdnGHweiBrAiJdLJkVohdRy',
|
||||
'gc_grace_seconds': 96362,
|
||||
'read_repair_chance': 0.2989,
|
||||
# 'local_read_repair_chance': 0.12732,
|
||||
}
|
||||
if CASSANDRA_VERSION >= '2.0.0':
|
||||
expected['memtable_flush_period_in_ms'] = 60210
|
||||
expected['default_time_to_live'] = 65178
|
||||
expected['memtable_flush_period_in_ms'] = 60210
|
||||
expected['default_time_to_live'] = 65178
|
||||
|
||||
if CASSANDRA_VERSION == '2.0.0':
|
||||
expected['index_interval'] = 94207
|
||||
expected['index_interval'] = 94207
|
||||
|
||||
# these featuers removed in cassandra 2.1
|
||||
if CASSANDRA_VERSION <= '2.0.0':
|
||||
@@ -274,9 +283,7 @@ class SyncTableTests(BaseCassEngTestCase):
|
||||
|
||||
assert LeveledCompactionStrategy in table_settings.options['compaction_strategy_class']
|
||||
|
||||
|
||||
# Now we are "updating" the table:
|
||||
|
||||
# setting up something to change
|
||||
PrimaryKeysOnlyModel.__compaction__ = SizeTieredCompactionStrategy
|
||||
|
||||
@@ -290,6 +297,7 @@ class SyncTableTests(BaseCassEngTestCase):
|
||||
table_settings = management.get_table_settings(PrimaryKeysOnlyModel)
|
||||
assert SizeTieredCompactionStrategy in table_settings.options['compaction_strategy_class']
|
||||
|
||||
|
||||
class NonModelFailureTest(BaseCassEngTestCase):
|
||||
class FakeModel(object):
|
||||
pass
|
||||
@@ -324,9 +332,4 @@ def test_static_columns():
|
||||
sync_table(StaticModel)
|
||||
|
||||
assert len(m2.call_args_list) == 1
|
||||
assert "ALTER" not in m2.call_args[0][0].query_string
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
assert "ALTER" not in m2.call_args[0][0].query_string
|
||||
|
||||
@@ -16,7 +16,7 @@ from uuid import uuid4
|
||||
import random
|
||||
from datetime import date
|
||||
from operator import itemgetter
|
||||
from cassandra.cqlengine.exceptions import CQLEngineException
|
||||
from cassandra.cqlengine import CQLEngineException
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
|
||||
from cassandra.cqlengine.management import sync_table
|
||||
@@ -24,16 +24,10 @@ from cassandra.cqlengine.management import drop_table
|
||||
from cassandra.cqlengine.models import Model
|
||||
from cassandra.cqlengine import columns
|
||||
|
||||
class TestModel(Model):
|
||||
|
||||
id = columns.UUID(primary_key=True, default=lambda:uuid4())
|
||||
count = columns.Integer()
|
||||
text = columns.Text(required=False)
|
||||
a_bool = columns.Boolean(default=False)
|
||||
|
||||
class TestModel(Model):
|
||||
|
||||
id = columns.UUID(primary_key=True, default=lambda:uuid4())
|
||||
id = columns.UUID(primary_key=True, default=lambda: uuid4())
|
||||
count = columns.Integer()
|
||||
text = columns.Text(required=False)
|
||||
a_bool = columns.Boolean(default=False)
|
||||
@@ -153,7 +147,7 @@ class TestDeleting(BaseCassEngTestCase):
|
||||
drop_table(TestMultiKeyModel)
|
||||
|
||||
def test_deleting_only_deletes_one_object(self):
|
||||
partition = random.randint(0,1000)
|
||||
partition = random.randint(0, 1000)
|
||||
for i in range(5):
|
||||
TestMultiKeyModel.create(partition=partition, cluster=i, count=i, text=str(i))
|
||||
|
||||
@@ -262,17 +256,20 @@ class IndexDefinitionModel(Model):
|
||||
key = columns.UUID(primary_key=True)
|
||||
val = columns.Text(index=True)
|
||||
|
||||
|
||||
class TestIndexedColumnDefinition(BaseCassEngTestCase):
|
||||
|
||||
def test_exception_isnt_raised_if_an_index_is_defined_more_than_once(self):
|
||||
sync_table(IndexDefinitionModel)
|
||||
sync_table(IndexDefinitionModel)
|
||||
|
||||
|
||||
class ReservedWordModel(Model):
|
||||
|
||||
token = columns.Text(primary_key=True)
|
||||
insert = columns.Integer(index=True)
|
||||
|
||||
|
||||
class TestQueryQuoting(BaseCassEngTestCase):
|
||||
|
||||
def test_reserved_cql_words_can_be_used_as_column_names(self):
|
||||
@@ -323,6 +320,7 @@ class TestQuerying(BaseCassEngTestCase):
|
||||
assert inst.test_id == uid
|
||||
assert inst.date == day
|
||||
|
||||
|
||||
def test_none_filter_fails():
|
||||
class NoneFilterModel(Model):
|
||||
|
||||
@@ -335,6 +333,3 @@ def test_none_filter_fails():
|
||||
raise Exception("fail")
|
||||
except CQLEngineException as e:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from mock import patch
|
||||
from cassandra.cqlengine.exceptions import ValidationError
|
||||
from cassandra.cqlengine import ValidationError
|
||||
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
from cassandra.cqlengine.models import Model
|
||||
@@ -102,4 +102,3 @@ class ModelUpdateTests(BaseCassEngTestCase):
|
||||
m0 = TestUpdateModel.create(count=5, text='monkey')
|
||||
with self.assertRaises(ValidationError):
|
||||
m0.update(partition=uuid4())
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from uuid import uuid4
|
||||
from cassandra.cqlengine.exceptions import ValidationError
|
||||
from cassandra.cqlengine import ValidationError
|
||||
from cassandra.cqlengine.query import QueryException
|
||||
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
|
||||
Reference in New Issue
Block a user