Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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"],
        )
Example #4
0
    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'],
        )
Example #5
0
    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'],
        )
Example #6
0
    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)
Example #7
0
    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,
        )
Example #8
0
    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,
        )
Example #9
0
    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,
        )
Example #10
0
    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'])
Example #11
0
    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"])
Example #12
0
    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,
        )
Example #13
0
    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,
        )
Example #14
0
    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'])
Example #15
0
    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)
Example #16
0
    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)
Example #17
0
    def test_auth_disabled(self):
        migrator.get_session(self.config)

        args, kwargs = self.mock_cluster.call_args
        self.assertEqual(None, kwargs['auth_provider'])
Example #18
0
    def test_ssl_disabled(self):
        migrator.get_session(self.config)

        args, kwargs = self.mock_cluster.call_args
        self.assertEqual(None, kwargs['ssl_options'])
Example #19
0
    def test_ssl_disabled(self):
        migrator.get_session(self.config)

        args, kwargs = self.mock_cluster.call_args
        self.assertEqual(None, kwargs['ssl_options'])
Example #20
0
    def test_auth_disabled(self):
        migrator.get_session(self.config)

        args, kwargs = self.mock_cluster.call_args
        self.assertEqual(None, kwargs['auth_provider'])