Ejemplo n.º 1
0
    def test_get_certificate(self, cfngin_context, patch_time):
        """Test get_certificate."""
        # setup context
        cfngin_context.add_stubber('acm', 'us-east-1')
        cfngin_context.add_stubber('route53', 'us-east-1')
        cfngin_context.config.namespace = 'test'

        provider = MagicMock(cloudformation=boto3.client('cloudformation'))
        cfn_stubber = Stubber(provider.cloudformation)

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

        expected_request = {
            'StackName': 'test-example-com',
            'LogicalResourceId': 'Certificate'
        }

        cfn_stubber.add_response('describe_stack_resources',
                                 {'StackResources': []}, expected_request)
        cfn_stubber.add_response('describe_stack_resources',
                                 {'StackResources': [gen_stack_resource()]},
                                 expected_request)
        cfn_stubber.add_response('describe_stack_resources', {
            'StackResources':
            [gen_stack_resource(PhysicalResourceId='success')]
        }, expected_request)

        with cfn_stubber:
            assert cert.get_certificate() == 'success'

        cfn_stubber.assert_no_pending_responses()
Ejemplo n.º 2
0
    def test_get_certificate(self, cfngin_context: MockCFNginContext,
                             patch_time: None) -> None:
        """Test get_certificate."""
        # setup context
        cfngin_context.add_stubber("acm", "us-east-1")
        cfngin_context.add_stubber("route53", "us-east-1")
        cfngin_context.config.namespace = "test"

        provider = MagicMock(cloudformation=boto3.client("cloudformation"))
        cfn_stubber = Stubber(provider.cloudformation)

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

        expected_request = {
            "StackName": "test-example-com",
            "LogicalResourceId": "Certificate",
        }

        cfn_stubber.add_response("describe_stack_resources",
                                 {"StackResources": []}, expected_request)
        cfn_stubber.add_response(
            "describe_stack_resources",
            {"StackResources": [gen_stack_resource()]},
            expected_request,
        )
        cfn_stubber.add_response(
            "describe_stack_resources",
            {
                "StackResources":
                [gen_stack_resource(PhysicalResourceId="success")]
            },
            expected_request,
        )

        with cfn_stubber:
            assert cert.get_certificate() == "success"

        cfn_stubber.assert_no_pending_responses()