def test_nonexistent_keyspace_create_disabled(self): self.config['create_keyspace'] = False self.session.set_keyspace.side_effect = cassandra.InvalidRequest with self.assertRaises(cassandra.InvalidRequest): migrator.get_session(self.config) ((args,), _) = self.session.set_keyspace.call_args self.assertEqual(self.config["keyspace"], args)
def test_nonexistent_keyspace_create_disabled(self): self.config['create_keyspace'] = False self.session.set_keyspace.side_effect = cassandra.InvalidRequest with self.assertRaises(cassandra.InvalidRequest): migrator.get_session(self.config) ((args, ), _) = self.session.set_keyspace.call_args self.assertEqual(self.config["keyspace"], args)
def test_ssl_enabled(self): self.config["ssl_enabled"] = True self.config["ssl_ca_certs"] = "/path/to/ca/certs" migrator.get_session(self.config) args, kwargs = self.mock_cluster.call_args self.assertEqual( {"ca_certs": self.config["ssl_ca_certs"], "ssl_version": ssl.PROTOCOL_TLSv1}, # pylint: disable=E1101 kwargs["ssl_options"], )
def test_ssl_enabled(self): self.config['ssl_enabled'] = True self.config['ssl_ca_certs'] = '/path/to/ca/certs' migrator.get_session(self.config) args, kwargs = self.mock_cluster.call_args self.assertEqual( { 'ca_certs': self.config['ssl_ca_certs'], 'ssl_version': ssl.PROTOCOL_TLSv1, # pylint: disable=E1101 }, kwargs['ssl_options'], )
def test_nonexistent_keyspace_create_enabled(self): self.config['create_keyspace'] = True self.config['replication_strategy'] = 'test' self.session.set_keyspace.side_effect = [ cassandra.InvalidRequest, None ] migrator.get_session(self.config) ((args, ), _) = self.session.set_keyspace.call_args self.assertEqual(self.config["keyspace"], args) ((args, ), _) = self.session.execute.call_args self.assertEqual( "CREATE KEYSPACE {0} WITH REPLICATION = {1};".format( self.config["keyspace"], self.config["replication_strategy"]), args)
def test_nonexistent_keyspace_create_enabled(self): self.config["create_keyspace"] = True self.config["replication_strategy"] = "test" self.session.set_keyspace.side_effect = [cassandra.InvalidRequest, None] migrator.get_session(self.config) ((args,), _) = self.session.set_keyspace.call_args self.assertEqual(self.config["keyspace"], args) ((args,), _) = self.session.execute.call_args self.assertEqual( "CREATE KEYSPACE {0} WITH REPLICATION = {1};".format( self.config["keyspace"], self.config["replication_strategy"] ), args, )
def test_consistency_level_EACH_QUORUM(self): self.config['consistency_level'] = 'EACH_QUORUM' session = migrator.get_session(self.config) self.assertEqual( cassandra.ConsistencyLevel.EACH_QUORUM, session.default_consistency_level, )
def test_consistency_level_ALL(self): self.config['consistency_level'] = 'ALL' session = migrator.get_session(self.config) self.assertEqual( cassandra.ConsistencyLevel.ALL, session.default_consistency_level, )
def test_auth_enabled(self): self.config['auth_enabled'] = True self.config['auth_username'] = '******' self.config['auth_password'] = '******' patch_path = 'cdeploy.migrator.auth.PlainTextAuthProvider' with mock.patch(patch_path) as mock_provider: provider = mock.Mock() mock_provider.return_value = provider migrator.get_session(self.config) args, kwargs = mock_provider.call_args self.assertEqual(self.config['auth_username'], kwargs['username']) self.assertEqual(self.config['auth_password'], kwargs['password']) args, kwargs = self.mock_cluster.call_args self.assertEqual(provider, kwargs['auth_provider'])
def test_auth_enabled(self): self.config["auth_enabled"] = True self.config["auth_username"] = "******" self.config["auth_password"] = "******" patch_path = "cdeploy.migrator.auth.PlainTextAuthProvider" with mock.patch(patch_path) as mock_provider: provider = mock.Mock() mock_provider.return_value = provider migrator.get_session(self.config) args, kwargs = mock_provider.call_args self.assertEqual(self.config["auth_username"], kwargs["username"]) self.assertEqual(self.config["auth_password"], kwargs["password"]) args, kwargs = self.mock_cluster.call_args self.assertEqual(provider, kwargs["auth_provider"])
def test_consistency_level_default(self): level = mock.Mock() mock_session = mock.Mock(default_consistency_level=level) mock_cluster = mock.Mock() mock_cluster.connect.return_value = mock_session self.mock_cluster.return_value = mock_cluster session = migrator.get_session(self.config) self.assertEqual(level, session.default_consistency_level)
def test_auth_disabled(self): migrator.get_session(self.config) args, kwargs = self.mock_cluster.call_args self.assertEqual(None, kwargs['auth_provider'])
def test_ssl_disabled(self): migrator.get_session(self.config) args, kwargs = self.mock_cluster.call_args self.assertEqual(None, kwargs['ssl_options'])