Example #1
0
    def test_context_create(self):
        # GIVEN
        context = _set_up_context()

        stack_context = StackContext(context)
        stack_context.initialize(args={})

        # THEN
        self.assertIsNotNone(stack_context)
Example #2
0
    def test_context_get_current_template_with_client_error(self):
        # GIVEN}
        client = _get_cf_stubbed_client_with_error(
            method='get_template', service_error_code='ValidationError')

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        with self.assertRaises(HandledError):
            stack_context.get_current_template(stack_id=TEST_STACK_ID)
Example #3
0
    def test_context_describe_stack_with_validation_error(self):
        # GIVEN
        client = _get_cf_stubbed_client_with_error(
            method='describe_stacks', service_error_code='ValidationError')

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        with self.assertRaises(HandledError):
            stack_context.describe_stack(stack_id=TEST_STACK_ID,
                                         optional=False)
Example #4
0
    def test_context_get_stack_status_client_failure(self):
        # GIVEN
        client = _get_cf_stubbed_client_with_error(
            method='describe_stacks',
            service_error_code="ClientError",
            service_message="Stack with id {TEST_STACK_ID} does not exist")

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        with self.assertRaises(botocore.exceptions.ClientError):
            stack_context.get_stack_status(stack_id=TEST_STACK_ID)
Example #5
0
    def test_context_name_exists_is_false_for_validation_errors(self):
        # GIVEN
        client = _get_cf_stubbed_client_with_error(
            method='describe_stacks',
            service_error_code="ValidationError")

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        exists = stack_context.name_exists(stack_name=TEST_STACK_NAME, region=TEST_REGION)

        # THEN
        self.assertFalse(exists)
Example #6
0
    def test_context_describe_stack_with_optional_and_validation_error(self):
        # GIVEN
        client = _get_cf_stubbed_client_with_error(
            method='describe_stacks', service_error_code='ValidationError')

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        response = stack_context.describe_stack(stack_id=TEST_STACK_ID,
                                                optional=True)

        # THEN
        self.assertIsNone(response)
Example #7
0
    def test_context_get_stack_status_validation_failure(self):
        # GIVEN
        client = _get_cf_stubbed_client_with_error(
            method='describe_stacks',
            service_error_code="ValidationError",
            service_message=f"Stack with id {TEST_STACK_ID} does not exist")

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        status = stack_context.get_stack_status(stack_id=TEST_STACK_ID)

        # THEN
        self.assertIsNone(status)
Example #8
0
    def test_context_describe_stack_with_and_access_denied(self):
        # GIVEN
        client = _get_cf_stubbed_client_with_error(
            method='describe_stacks', service_error_code='AccessDenied')

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        response = stack_context.describe_stack(stack_id=TEST_STACK_ID,
                                                optional=False)

        # THEN
        self.assertEqual(response['StackStatus'], 'UNKNOWN')
        self.assertEqual(response['StackStatusReason'], 'Access denied.')
Example #9
0
    def test_context_get_stack_status(self):
        # GIVEN
        expected_status = 'COMPLETED'
        expected_params = {'StackName': TEST_STACK_ID}
        response = self.__build_simple_describe_stack_response(stack_status=expected_status)

        client = _get_cf_stubbed_client(method='describe_stacks', response=response,
                                        expected_params=expected_params)

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        status = stack_context.get_stack_status(stack_id=TEST_STACK_ID)

        # THEN
        self.assertEqual(status, expected_status)
Example #10
0
    def test_context_name_exists_is_false_for_deleted_stacks(self):
        # GIVEN
        expected_params = {'StackName': TEST_STACK_NAME}
        expected_status = 'DELETE_COMPLETE'
        response = self.__build_simple_describe_stack_response(stack_status=expected_status)

        client = _get_cf_stubbed_client(method='describe_stacks', response=response,
                                        expected_params=expected_params)

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        exists = stack_context.name_exists(stack_name=TEST_STACK_NAME, region=TEST_REGION)

        # THEN
        self.assertFalse(exists)
Example #11
0
    def test_context_get_current_template(self):
        # GIVEN
        expected_params = {'StackName': TEST_STACK_ID}
        expected_body = str({'AWSTemplateFormatVersion': '2010-09-09'})
        response = {"TemplateBody": expected_body}

        client = _get_cf_stubbed_client(method='get_template',
                                        response=response,
                                        expected_params=expected_params)

        context = _set_up_context(mock_client=client)
        stack_context = StackContext(context)

        # WHEN
        response = stack_context.get_current_template(stack_id=TEST_STACK_ID)

        # THEN
        self.assertEqual(response, expected_body)