1313# limitations under the License.
1414
1515import mock
16+
1617from unittest import skipUnless
18+ import warnings
1719
1820from 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
2022from cassandra .cqlengine .exceptions import CQLEngineException
2123from cassandra .cqlengine import management
2224from cassandra .cqlengine .management import get_fields , sync_table , drop_table
2729from tests .integration .cqlengine .base import BaseCassEngTestCase
2830from 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