Skip to content

Commit 710b6f7

Browse files
committed
Added tests for PYTHON-966
1 parent 3b88b63 commit 710b6f7

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

tests/integration/cqlengine/query/test_queryset.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from packaging.version import Version
2424
import uuid
2525

26-
from cassandra.cluster import Session
26+
from cassandra.cluster import Cluster, Session
2727
from cassandra import InvalidRequest
2828
from tests.integration.cqlengine.base import BaseCassEngTestCase
2929
from cassandra.cqlengine.connection import NOT_SET
@@ -43,7 +43,7 @@
4343
from cassandra.cqlengine.connection import get_session
4444
from tests.integration import PROTOCOL_VERSION, CASSANDRA_VERSION, greaterthancass20, greaterthancass21, \
4545
greaterthanorequalcass30
46-
from tests.integration.cqlengine import execute_count
46+
from tests.integration.cqlengine import execute_count, DEFAULT_KEYSPACE
4747

4848

4949
class TzOffset(tzinfo):
@@ -86,6 +86,7 @@ class CustomIndexedTestModel(Model):
8686

8787
test_id = columns.Integer(primary_key=True)
8888
description = columns.Text(custom_index=True)
89+
indexed = columns.Text(index=True)
8990
data = columns.Text()
9091

9192

@@ -754,15 +755,33 @@ def test_custom_indexed_field_can_be_queried(self):
754755
with self.assertRaises(query.QueryException):
755756
list(CustomIndexedTestModel.objects.filter(data='test')) # not custom indexed
756757

758+
# It should return InvalidRequest if target an indexed columns
759+
with self.assertRaises(InvalidRequest):
760+
list(CustomIndexedTestModel.objects.filter(indexed='test', data='test'))
761+
762+
# It should return InvalidRequest if target an indexed columns
763+
with self.assertRaises(InvalidRequest):
764+
list(CustomIndexedTestModel.objects.filter(description='test', data='test'))
765+
757766
# equals operator, server error since there is no real index, but it passes
758767
with self.assertRaises(InvalidRequest):
759768
list(CustomIndexedTestModel.objects.filter(description='test'))
760769

770+
with self.assertRaises(InvalidRequest):
771+
list(CustomIndexedTestModel.objects.filter(test_id=1, description='test'))
772+
761773
# gte operator, server error since there is no real index, but it passes
762774
# this can't work with a secondary index
763775
with self.assertRaises(InvalidRequest):
764776
list(CustomIndexedTestModel.objects.filter(description__gte='test'))
765777

778+
with Cluster().connect() as session:
779+
session.execute("CREATE INDEX custom_index_cqlengine ON {}.{} (description)".
780+
format(DEFAULT_KEYSPACE, CustomIndexedTestModel._table_name))
781+
782+
list(CustomIndexedTestModel.objects.filter(description='test'))
783+
list(CustomIndexedTestModel.objects.filter(test_id=1, description='test'))
784+
766785

767786
class TestQuerySetDelete(BaseQuerySetUsage):
768787

0 commit comments

Comments
 (0)