Skip to content

Commit d1d5ef4

Browse files
committed
Add integration tests
1 parent 9152b4a commit d1d5ef4

5 files changed

Lines changed: 454 additions & 9 deletions

File tree

cassandra/cqlengine/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def unregister_connection(name):
146146
if name not in _connections:
147147
return
148148

149-
if _connections[name] == _connections[DEFAULT_CONNECTION]:
149+
if DEFAULT_CONNECTION in _connections and _connections[name] == _connections[DEFAULT_CONNECTION]:
150150
del _connections[DEFAULT_CONNECTION]
151151
log.warning("Unregistering default connection '{0}'. Use set_default_connection to set a new one.".format(name))
152152

cassandra/cqlengine/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131

3232
def _clone_model_class(model, attrs):
3333
new_type = type(model.__name__, (model,), attrs)
34-
new_type.__abstract__ = model.__abstract__
35-
new_type.__discriminator_value__ = model.__discriminator_value__
36-
new_type.__default_ttl__ = model.__default_ttl__
34+
try:
35+
new_type.__abstract__ = model.__abstract__
36+
new_type.__discriminator_value__ = model.__discriminator_value__
37+
new_type.__default_ttl__ = model.__default_ttl__
38+
except AttributeError:
39+
pass
3740
return new_type
3841

3942

@@ -803,6 +806,8 @@ def _class_batch(cls, batch):
803806

804807
def _inst_batch(self, batch):
805808
assert self._timeout is connection.NOT_SET, 'Setting both timeout and batch is not supported'
809+
if self._connection:
810+
raise CQLEngineException("Cannot specify a connection on model in batch mode.")
806811
self._batch = batch
807812
return self
808813

cassandra/cqlengine/query.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,20 @@ def __init__(self, *args, **kwargs):
302302
self.models = []
303303

304304
if len(args) < 1:
305-
raise CQLEngineException("No model provided.")
305+
raise ValueError("No model provided.")
306306

307307
keyspace = kwargs.pop('keyspace', None)
308308
connection = kwargs.pop('connection', None)
309309

310310
if kwargs:
311-
raise CQLEngineException("Unknown keyword argument(s): {0}".format(
311+
raise ValueError("Unknown keyword argument(s): {0}".format(
312312
','.join(kwargs.keys())))
313313

314314
for model in args:
315-
if not issubclass(model, models.Model):
316-
raise CQLEngineException("Models must be derived from base Model.")
315+
try:
316+
issubclass(model, models.Model)
317+
except TypeError:
318+
raise ValueError("Models must be derived from base Model.")
317319

318320
m = models._clone_model_class(model, {})
319321

@@ -390,7 +392,8 @@ def _execute(self, statement):
390392
if self._batch:
391393
return self._batch.add_query(statement)
392394
else:
393-
result = _execute_statement(self.model, statement, self._consistency, self._timeout, connection=self._connection)
395+
connection = self._connection if self._connection else self.model._get_connection()
396+
result = _execute_statement(self.model, statement, self._consistency, self._timeout, connection=connection)
394397
if self._if_not_exists or self._if_exists or self._conditional:
395398
check_applied(result)
396399
return result

0 commit comments

Comments
 (0)