|
23 | 23 | from packaging.version import Version
|
24 | 24 | import uuid
|
25 | 25 |
|
26 |
| -from cassandra.cluster import Session |
| 26 | +from cassandra.cluster import Cluster, Session |
27 | 27 | from cassandra import InvalidRequest
|
28 | 28 | from tests.integration.cqlengine.base import BaseCassEngTestCase
|
29 | 29 | from cassandra.cqlengine.connection import NOT_SET
|
|
43 | 43 | from cassandra.cqlengine.connection import get_session
|
44 | 44 | from tests.integration import PROTOCOL_VERSION, CASSANDRA_VERSION, greaterthancass20, greaterthancass21, \
|
45 | 45 | greaterthanorequalcass30
|
46 |
| -from tests.integration.cqlengine import execute_count |
| 46 | +from tests.integration.cqlengine import execute_count, DEFAULT_KEYSPACE |
47 | 47 |
|
48 | 48 |
|
49 | 49 | class TzOffset(tzinfo):
|
@@ -86,6 +86,7 @@ class CustomIndexedTestModel(Model):
|
86 | 86 |
|
87 | 87 | test_id = columns.Integer(primary_key=True)
|
88 | 88 | description = columns.Text(custom_index=True)
|
| 89 | + indexed = columns.Text(index=True) |
89 | 90 | data = columns.Text()
|
90 | 91 |
|
91 | 92 |
|
@@ -754,15 +755,33 @@ def test_custom_indexed_field_can_be_queried(self):
|
754 | 755 | with self.assertRaises(query.QueryException):
|
755 | 756 | list(CustomIndexedTestModel.objects.filter(data='test')) # not custom indexed
|
756 | 757 |
|
| 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 | + |
757 | 766 | # equals operator, server error since there is no real index, but it passes
|
758 | 767 | with self.assertRaises(InvalidRequest):
|
759 | 768 | list(CustomIndexedTestModel.objects.filter(description='test'))
|
760 | 769 |
|
| 770 | + with self.assertRaises(InvalidRequest): |
| 771 | + list(CustomIndexedTestModel.objects.filter(test_id=1, description='test')) |
| 772 | + |
761 | 773 | # gte operator, server error since there is no real index, but it passes
|
762 | 774 | # this can't work with a secondary index
|
763 | 775 | with self.assertRaises(InvalidRequest):
|
764 | 776 | list(CustomIndexedTestModel.objects.filter(description__gte='test'))
|
765 | 777 |
|
| 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 | + |
766 | 785 |
|
767 | 786 | class TestQuerySetDelete(BaseQuerySetUsage):
|
768 | 787 |
|
|
0 commit comments