Skip to content

Commit f753c30

Browse files
committed
Expand cqlengine keyspace management tests to include new functions
1 parent 44c3b2c commit f753c30

2 files changed

Lines changed: 45 additions & 16 deletions

File tree

tests/integration/cqlengine/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import warnings
16+
1517
from cassandra.cqlengine import connection
16-
from cassandra.cqlengine.management import create_keyspace
18+
from cassandra.cqlengine.management import create_keyspace_simple
1719

1820
from tests.integration import use_single_node, PROTOCOL_VERSION
1921

2022

2123
def setup_package():
24+
warnings.simplefilter('always') # for testing warnings, make sure all are let through
25+
2226
use_single_node()
2327

2428
keyspace = 'cqlengine_test'
2529
connection.setup(['localhost'],
2630
protocol_version=PROTOCOL_VERSION,
2731
default_keyspace=keyspace)
2832

29-
create_keyspace(keyspace, replication_factor=1, strategy_class="SimpleStrategy")
33+
create_keyspace_simple(keyspace, 1)

tests/integration/cqlengine/management/test_management.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
# limitations under the License.
1414

1515
import mock
16+
1617
from unittest import skipUnless
18+
import warnings
1719

1820
from cassandra.cqlengine import CACHING_ALL, CACHING_NONE
19-
from cassandra.cqlengine.connection import get_session
21+
from cassandra.cqlengine.connection import get_session, get_cluster
2022
from cassandra.cqlengine.exceptions import CQLEngineException
2123
from cassandra.cqlengine import management
2224
from cassandra.cqlengine.management import get_fields, sync_table, drop_table
@@ -27,17 +29,43 @@
2729
from tests.integration.cqlengine.base import BaseCassEngTestCase
2830
from tests.integration.cqlengine.query.test_queryset import TestModel
2931

30-
class CreateKeyspaceTest(BaseCassEngTestCase):
31-
def test_create_succeeeds(self):
32-
management.create_keyspace('test_keyspace', strategy_class="SimpleStrategy", replication_factor=1)
33-
management.delete_keyspace('test_keyspace')
32+
class KeyspaceManagementTest(BaseCassEngTestCase):
33+
def test_create_drop_succeeeds(self):
34+
cluster = get_cluster()
3435

35-
class DeleteTableTest(BaseCassEngTestCase):
36+
keyspace_ss = 'test_ks_ss'
37+
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
38+
management.create_keyspace_simple(keyspace_ss, 2)
39+
self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)
3640

37-
def test_multiple_deletes_dont_fail(self):
38-
"""
41+
management.drop_keyspace(keyspace_ss)
42+
43+
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
44+
with warnings.catch_warnings(record=True) as w:
45+
management.create_keyspace(keyspace_ss, strategy_class="SimpleStrategy", replication_factor=1)
46+
self.assertEqual(len(w), 1)
47+
self.assertEqual(w[-1].category, DeprecationWarning)
48+
self.assertTrue(keyspace_ss in cluster.metadata.keyspaces)
49+
50+
management.drop_keyspace(keyspace_ss)
51+
self.assertFalse(keyspace_ss in cluster.metadata.keyspaces)
52+
53+
keyspace_nts = 'test_ks_nts'
54+
self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
55+
management.create_keyspace_simple(keyspace_nts, 2)
56+
self.assertTrue(keyspace_nts in cluster.metadata.keyspaces)
57+
58+
with warnings.catch_warnings(record=True) as w:
59+
management.delete_keyspace(keyspace_nts)
60+
self.assertEqual(len(w), 1)
61+
self.assertEqual(w[-1].category, DeprecationWarning)
3962

40-
"""
63+
self.assertFalse(keyspace_nts in cluster.metadata.keyspaces)
64+
65+
66+
class DropTableTest(BaseCassEngTestCase):
67+
68+
def test_multiple_deletes_dont_fail(self):
4169
sync_table(TestModel)
4270

4371
drop_table(TestModel)
@@ -280,12 +308,9 @@ class StaticModel(Model):
280308

281309
drop_table(StaticModel)
282310

283-
from mock import patch
284-
285-
from cassandra.cqlengine.connection import get_session
286311
session = get_session()
287312

288-
with patch.object(session, "execute", wraps=session.execute) as m:
313+
with mock.patch.object(session, "execute", wraps=session.execute) as m:
289314
sync_table(StaticModel)
290315

291316
assert m.call_count > 0
@@ -295,7 +320,7 @@ class StaticModel(Model):
295320
# if we sync again, we should not apply an alter w/ a static
296321
sync_table(StaticModel)
297322

298-
with patch.object(session, "execute", wraps=session.execute) as m2:
323+
with mock.patch.object(session, "execute", wraps=session.execute) as m2:
299324
sync_table(StaticModel)
300325

301326
assert len(m2.call_args_list) == 1

0 commit comments

Comments
 (0)