Example #1
0
    def test_destory_aws_errors(self, cfngin_context: MockCFNginContext,
                                monkeypatch: MonkeyPatch) -> None:
        """Test destory with errors from AWS."""
        # setup context
        cfngin_context.add_stubber("acm", "us-east-1")
        cfngin_context.add_stubber("route53", "us-east-1")
        cfngin_context.config.namespace = "test"

        cert = Certificate(
            context=cfngin_context,
            provider=MagicMock(),
            domain="example.com",
            hosted_zone_id="test",
        )

        monkeypatch.setattr(
            cert,
            "remove_validation_records",
            MagicMock(side_effect=[
                cert.r53_client.exceptions.InvalidChangeBatch({}, ""),
                cert.r53_client.exceptions.NoSuchHostedZone({}, ""),
                cert.acm_client.exceptions.ResourceNotFoundException({}, ""),
            ]),
        )
        monkeypatch.setattr(cert, "destroy_stack", lambda wait: None)

        assert cert.destroy()
        assert cert.destroy()
        assert cert.destroy()
Example #2
0
    def test_destroy_raise_client_error(self, cfngin_context, monkeypatch):
        """Test destory with ClientError raised."""
        # setup context
        cfngin_context.add_stubber('acm', 'us-east-1')
        cfngin_context.add_stubber('route53', 'us-east-1')
        cfngin_context.config.namespace = 'test'

        def build_client_error(msg):
            """Raise a ClientError."""
            return ClientError({'Error': {'Message': msg}}, 'test')

        cert = Certificate(context=cfngin_context,
                           provider=MagicMock(),
                           domain='example.com',
                           hosted_zone_id='test')
        monkeypatch.setattr(cert, 'destroy_stack', lambda wait: None)

        def raise_stack_not_exist(_records):
            """Raise ClientError mimicing stack not existing."""
            raise build_client_error('Stack with id {} does not exist'.format(
                cert.stack.fqn))

        def raise_other(_records):
            """Raise other ClientError."""
            raise build_client_error('something')

        monkeypatch.setattr(cert, 'remove_validation_records',
                            raise_stack_not_exist)
        assert cert.destroy()

        monkeypatch.setattr(cert, 'remove_validation_records', raise_other)
        with pytest.raises(ClientError) as excinfo:
            cert.destroy()
        assert 'something' in str(excinfo.value)
Example #3
0
    def test_destory(self, cfngin_context, monkeypatch):
        """Test destory."""
        # setup context
        cfngin_context.add_stubber('acm', 'us-east-1')
        cfngin_context.add_stubber('route53', 'us-east-1')
        cfngin_context.config.namespace = 'test'

        cert = Certificate(context=cfngin_context,
                           provider=MagicMock(),
                           domain='example.com',
                           hosted_zone_id='test')
        # should only be called once
        monkeypatch.setattr(cert, 'remove_validation_records',
                            MagicMock(return_value=None))
        monkeypatch.setattr(cert, 'destroy_stack', lambda wait: None)

        assert cert.destroy()
        assert cert.destroy(skip_r53=True)
        assert cert.remove_validation_records.call_count == 1  # pylint: disable=no-member
Example #4
0
    def test_destroy_raise_client_error(self,
                                        cfngin_context: MockCFNginContext,
                                        monkeypatch: MonkeyPatch) -> None:
        """Test destory with ClientError raised."""
        # setup context
        cfngin_context.add_stubber("acm", "us-east-1")
        cfngin_context.add_stubber("route53", "us-east-1")
        cfngin_context.config.namespace = "test"

        def build_client_error(msg: str) -> ClientError:
            """Raise a ClientError."""
            return ClientError({"Error": {"Code": "", "Message": msg}}, "test")

        cert = Certificate(
            context=cfngin_context,
            provider=MagicMock(),
            domain="example.com",
            hosted_zone_id="test",
        )
        monkeypatch.setattr(cert, "destroy_stack", lambda wait: None)

        def raise_stack_not_exist(_records: Any) -> NoReturn:
            """Raise ClientError mimicing stack not existing."""
            raise build_client_error("Stack with id {} does not exist".format(
                cert.stack.fqn))

        def raise_other(_records: Any) -> NoReturn:
            """Raise other ClientError."""
            raise build_client_error("something")

        monkeypatch.setattr(cert, "remove_validation_records",
                            raise_stack_not_exist)
        assert cert.destroy()

        monkeypatch.setattr(cert, "remove_validation_records", raise_other)
        with pytest.raises(ClientError) as excinfo:
            cert.destroy()
        assert "something" in str(excinfo.value)
Example #5
0
    def test_destory(self, cfngin_context: MockCFNginContext,
                     monkeypatch: MonkeyPatch) -> None:
        """Test destory."""
        # setup context
        cfngin_context.add_stubber("acm", "us-east-1")
        cfngin_context.add_stubber("route53", "us-east-1")
        cfngin_context.config.namespace = "test"

        cert = Certificate(
            context=cfngin_context,
            provider=MagicMock(),
            domain="example.com",
            hosted_zone_id="test",
        )
        # should only be called once
        monkeypatch.setattr(cert, "remove_validation_records",
                            MagicMock(return_value=None))
        monkeypatch.setattr(cert, "destroy_stack", lambda wait: None)

        assert cert.destroy()
        assert cert.destroy(skip_r53=True)
        assert (  # pylint: disable=no-member
            cert.remove_validation_records.call_count == 1  # type: ignore
        )
Example #6
0
    def test_destory_aws_errors(self, cfngin_context, monkeypatch):
        """Test destory with errors from AWS."""
        # setup context
        cfngin_context.add_stubber('acm', 'us-east-1')
        cfngin_context.add_stubber('route53', 'us-east-1')
        cfngin_context.config.namespace = 'test'

        cert = Certificate(context=cfngin_context,
                           provider=MagicMock(),
                           domain='example.com',
                           hosted_zone_id='test')

        monkeypatch.setattr(
            cert, 'remove_validation_records',
            MagicMock(side_effect=[
                cert.r53_client.exceptions.InvalidChangeBatch({}, ''),
                cert.r53_client.exceptions.NoSuchHostedZone({}, ''),
                cert.acm_client.exceptions.ResourceNotFoundException({}, '')
            ]))
        monkeypatch.setattr(cert, 'destroy_stack', lambda wait: None)

        assert cert.destroy()
        assert cert.destroy()
        assert cert.destroy()