Skip to content

Commit ecc32cc

Browse files
committed
Added tests for PYTHON-890 and PYTHON-877
1 parent 38594b5 commit ecc32cc

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

tests/integration/cqlengine/model/test_model.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,45 @@ def test_comparison(self):
224224
self.assertLessEqual(TestQueryUpdateModel.partition.column, TestQueryUpdateModel.cluster.column)
225225
self.assertGreater(TestQueryUpdateModel.cluster.column, TestQueryUpdateModel.partition.column)
226226
self.assertGreaterEqual(TestQueryUpdateModel.cluster.column, TestQueryUpdateModel.partition.column)
227+
228+
229+
class TestDeprecationWarning(unittest.TestCase):
230+
def test_deprecation_warnings(self):
231+
"""
232+
Test to some deprecation warning have been added. It tests warnings for
233+
negative index, negative index slicing and table sensitive removal
234+
235+
This test should be removed in 4.0, that's why the imports are in
236+
this test, so it's easier to remove
237+
238+
@since 3.13
239+
@jira_ticket PYTHON-877
240+
@expected_result the deprecation warnings are emitted
241+
242+
@test_category logs
243+
"""
244+
import warnings
245+
246+
class SensitiveModel(Model):
247+
__table_name__ = 'SensitiveModel'
248+
__table_name_case_sensitive__ = True
249+
k = columns.Integer(primary_key=True)
250+
251+
with warnings.catch_warnings(record=True) as w:
252+
warnings.simplefilter("always")
253+
sync_table(SensitiveModel)
254+
self.addCleanup(drop_table, SensitiveModel)
255+
256+
SensitiveModel.create(k=0)
257+
258+
rows = SensitiveModel.objects().all().allow_filtering()
259+
rows[-1]
260+
rows[-1:]
261+
262+
self.assertEqual(len(w), 4)
263+
self.assertIn("__table_name_case_sensitive__ will be removed in 4.0.", str(w[0].message))
264+
self.assertIn("__table_name_case_sensitive__ will be removed in 4.0.", str(w[1].message))
265+
self.assertIn("ModelQuerySet indexing with negative indices support will be removed in 4.0.",
266+
str(w[2].message))
267+
self.assertIn("ModelQuerySet slicing with negative indices support will be removed in 4.0.",
268+
str(w[3].message))

tests/integration/standard/test_cluster.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import time
2424
from uuid import uuid4
2525
import logging
26+
import warnings
2627

2728
import cassandra
2829
from cassandra.cluster import Cluster, Session, NoHostAvailable, ExecutionProfile, EXEC_PROFILE_DEFAULT
@@ -45,6 +46,7 @@
4546

4647
def setup_module():
4748
use_singledc()
49+
warnings.simplefilter("always")
4850

4951

5052
class IgnoredHostPolicy(RoundRobinPolicy):
@@ -1428,3 +1430,40 @@ def test_valid_protocol_version_beta_options_connect(self):
14281430
self.assertEqual(cluster.protocol_version, cassandra.ProtocolVersion.MAX_SUPPORTED)
14291431
self.assertTrue(session.execute("select release_version from system.local")[0])
14301432
cluster.shutdown()
1433+
1434+
1435+
class DeprecationWarningTest(unittest.TestCase):
1436+
def test_deprecation_warnings_legacy_parameters(self):
1437+
"""
1438+
Tests the deprecation warning has been added when using
1439+
legacy parameters
1440+
1441+
@since 3.13
1442+
@jira_ticket PYTHON-877
1443+
@expected_result the deprecation warning is emitted
1444+
1445+
@test_category logs
1446+
"""
1447+
with warnings.catch_warnings(record=True) as w:
1448+
Cluster(load_balancing_policy=RoundRobinPolicy())
1449+
self.assertEqual(len(w), 1)
1450+
self.assertIn("Legacy execution parameters will be removed in 4.0. Consider using execution profiles.",
1451+
str(w[0].message))
1452+
1453+
def test_deprecation_warnings_meta_refreshed(self):
1454+
"""
1455+
Tests the deprecation warning has been added when enabling
1456+
metadata refreshment
1457+
1458+
@since 3.13
1459+
@jira_ticket PYTHON-890
1460+
@expected_result the deprecation warning is emitted
1461+
1462+
@test_category logs
1463+
"""
1464+
with warnings.catch_warnings(record=True) as w:
1465+
cluster = Cluster()
1466+
cluster.set_meta_refresh_enabled(True)
1467+
self.assertEqual(len(w), 1)
1468+
self.assertIn("Cluster.set_meta_refresh_enabled is deprecated and will be removed in 4.0.",
1469+
str(w[0].message))

0 commit comments

Comments
 (0)