fixed pagedresult issue
This commit is contained in:
@@ -14,7 +14,7 @@ except ImportError:
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from cqlengine.exceptions import CQLEngineException
|
from cqlengine.exceptions import CQLEngineException, UndefinedKeyspaceException
|
||||||
from cassandra import ConsistencyLevel
|
from cassandra import ConsistencyLevel
|
||||||
from cqlengine.statements import BaseCQLStatement
|
from cqlengine.statements import BaseCQLStatement
|
||||||
from cassandra.query import dict_factory
|
from cassandra.query import dict_factory
|
||||||
@@ -53,7 +53,9 @@ def setup(
|
|||||||
if 'username' in kwargs or 'password' in kwargs:
|
if 'username' in kwargs or 'password' in kwargs:
|
||||||
raise CQLEngineException("Username & Password are now handled by using the native driver's auth_provider")
|
raise CQLEngineException("Username & Password are now handled by using the native driver's auth_provider")
|
||||||
|
|
||||||
if default_keyspace:
|
if not default_keyspace:
|
||||||
|
raise UndefinedKeyspaceException()
|
||||||
|
|
||||||
from cqlengine import models
|
from cqlengine import models
|
||||||
models.DEFAULT_KEYSPACE = default_keyspace
|
models.DEFAULT_KEYSPACE = default_keyspace
|
||||||
|
|
||||||
|
@@ -3,3 +3,4 @@ class CQLEngineException(Exception): pass
|
|||||||
class ModelException(CQLEngineException): pass
|
class ModelException(CQLEngineException): pass
|
||||||
class ValidationError(CQLEngineException): pass
|
class ValidationError(CQLEngineException): pass
|
||||||
|
|
||||||
|
class UndefinedKeyspaceException(CQLEngineException): pass
|
||||||
|
@@ -762,16 +762,6 @@ class ModelMetaClass(type):
|
|||||||
#create the class and add a QuerySet to it
|
#create the class and add a QuerySet to it
|
||||||
klass = super(ModelMetaClass, cls).__new__(cls, name, bases, attrs)
|
klass = super(ModelMetaClass, cls).__new__(cls, name, bases, attrs)
|
||||||
|
|
||||||
if not klass.__abstract__ and klass.__keyspace__ is None:
|
|
||||||
warnings.warn(
|
|
||||||
"No keyspace defined on {}.{}\n"
|
|
||||||
" The default keyspace 'cqlengine' was removed in 0.16.\n"
|
|
||||||
" Please define a keyspace on the '__keyspace__' model class attribute\n"
|
|
||||||
" or set a default keyspace with management.setup function\n"
|
|
||||||
.format(klass.__module__, klass.__name__),
|
|
||||||
UndefinedKeyspaceWarning
|
|
||||||
)
|
|
||||||
|
|
||||||
return klass
|
return klass
|
||||||
|
|
||||||
|
|
||||||
|
@@ -293,7 +293,7 @@ class AbstractQuerySet(object):
|
|||||||
if self._batch:
|
if self._batch:
|
||||||
raise CQLEngineException("Only inserts, updates, and deletes are available in batch mode")
|
raise CQLEngineException("Only inserts, updates, and deletes are available in batch mode")
|
||||||
if self._result_cache is None:
|
if self._result_cache is None:
|
||||||
self._result_cache = self._execute(self._select_query())
|
self._result_cache = list(self._execute(self._select_query()))
|
||||||
self._construct_result = self._get_result_constructor()
|
self._construct_result = self._get_result_constructor()
|
||||||
|
|
||||||
def _fill_result_cache_to_idx(self, idx):
|
def _fill_result_cache_to_idx(self, idx):
|
||||||
|
@@ -221,15 +221,6 @@ class TestModelClassFunction(BaseCassEngTestCase):
|
|||||||
except Exception:
|
except Exception:
|
||||||
assert False, "Model2 exception should not be caught by Model1"
|
assert False, "Model2 exception should not be caught by Model1"
|
||||||
|
|
||||||
def test_no_keyspace_warning(self):
|
|
||||||
with warnings.catch_warnings(record=True) as warn:
|
|
||||||
class NoKeyspace(Model):
|
|
||||||
key = columns.UUID(primary_key=True)
|
|
||||||
|
|
||||||
self.assertEqual(len(warn), 1)
|
|
||||||
warn_message = warn[0]
|
|
||||||
self.assertEqual(warn_message.category, UndefinedKeyspaceWarning)
|
|
||||||
|
|
||||||
def test_abstract_model_keyspace_warning_is_skipped(self):
|
def test_abstract_model_keyspace_warning_is_skipped(self):
|
||||||
with warnings.catch_warnings(record=True) as warn:
|
with warnings.catch_warnings(record=True) as warn:
|
||||||
class NoKeyspace(Model):
|
class NoKeyspace(Model):
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
import time
|
||||||
from unittest import TestCase
|
from unittest import TestCase, skipUnless
|
||||||
from uuid import uuid1, uuid4
|
from uuid import uuid1, uuid4
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from cqlengine.tests.base import BaseCassEngTestCase
|
from cqlengine.tests.base import BaseCassEngTestCase
|
||||||
|
import mock
|
||||||
from cqlengine.exceptions import ModelException
|
from cqlengine.exceptions import ModelException
|
||||||
from cqlengine import functions
|
from cqlengine import functions
|
||||||
from cqlengine.management import sync_table, drop_table, sync_table
|
from cqlengine.management import sync_table, drop_table, sync_table
|
||||||
@@ -20,6 +20,11 @@ from cqlengine import statements
|
|||||||
from cqlengine import operators
|
from cqlengine import operators
|
||||||
|
|
||||||
|
|
||||||
|
from cqlengine.connection import get_cluster, get_session
|
||||||
|
|
||||||
|
cluster = get_cluster()
|
||||||
|
|
||||||
|
|
||||||
class TzOffset(tzinfo):
|
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.
|
||||||
@@ -684,3 +689,21 @@ class TestObjectsProperty(BaseQuerySetUsage):
|
|||||||
assert TestModel.objects._result_cache is None
|
assert TestModel.objects._result_cache is None
|
||||||
|
|
||||||
|
|
||||||
|
@skipUnless(cluster.protocol_version >= 2, "only runs against the cql3 protocol v2.0")
|
||||||
|
def test_paged_result_handling():
|
||||||
|
# addresses #225
|
||||||
|
class PagingTest(Model):
|
||||||
|
id = columns.Integer(primary_key=True)
|
||||||
|
val = columns.Integer()
|
||||||
|
sync_table(PagingTest)
|
||||||
|
|
||||||
|
PagingTest.create(id=1, val=1)
|
||||||
|
PagingTest.create(id=2, val=2)
|
||||||
|
|
||||||
|
session = get_session()
|
||||||
|
with mock.patch.object(session, 'default_fetch_size', 1):
|
||||||
|
results = PagingTest.objects()[:]
|
||||||
|
|
||||||
|
assert len(results) == 2
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user