Example #1
0
    def test_must_override_template_semantic_version(self,
                                                     publish_application_mock,
                                                     get_template_data_mock):
        template_data = {
            METADATA: {
                SERVERLESS_REPO_APPLICATION: {
                    SEMANTIC_VERSION: "0.1"
                }
            }
        }
        get_template_data_mock.return_value = template_data
        publish_application_mock.return_value = {
            "application_id": self.application_id,
            "details": {},
            "actions": {}
        }

        publish_cli(self.ctx_mock, self.template, "0.2")
        expected_template_data = {
            METADATA: {
                SERVERLESS_REPO_APPLICATION: {
                    SEMANTIC_VERSION: "0.2"
                }
            }
        }
        publish_application_mock.assert_called_with(expected_template_data)
Example #2
0
    def test_must_raise_if_serverlessrepo_error(self, click_mock,
                                                publish_application_mock):
        publish_application_mock.side_effect = ServerlessRepoError()
        with self.assertRaises(UserException):
            publish_cli(self.ctx_mock, self.template, None)

        click_mock.secho.assert_called_with("Publish Failed", fg="red")
    def test_must_raise_if_invalid_S3_uri_error(self, click_mock, publish_application_mock):
        publish_application_mock.side_effect = InvalidS3UriError(message="")
        with self.assertRaises(UserException) as context:
            publish_cli(self.ctx_mock, self.template, None)

        message = str(context.exception)
        self.assertTrue("Your SAM template contains invalid S3 URIs" in message)
        click_mock.secho.assert_called_with("Publish Failed", fg="red")
    def test_must_raise_if_value_error(self, click_mock, get_template_data_mock):
        get_template_data_mock.side_effect = ValueError("Template not found")
        with self.assertRaises(UserException) as context:
            publish_cli(self.ctx_mock, self.template, None)

        message = str(context.exception)
        self.assertEqual("Template not found", message)
        click_mock.secho.assert_called_with("Publish Failed", fg="red")
Example #5
0
    def test_must_raise_if_value_error(self, click_mock, get_template_data_mock):
        get_template_data_mock.side_effect = ValueError("Template not found")
        with self.assertRaises(UserException) as context:
            publish_cli(self.ctx_mock, self.template)

        message = str(context.exception)
        self.assertEqual("Template not found", message)
        click_mock.secho.assert_called_with("Publish Failed", fg="red")
Example #6
0
    def test_must_raise_if_not_s3_uri_error(self, click_mock, publish_application_mock):
        publish_application_mock.side_effect = ClientError(
            {'Error': {'Code': 'OtherError', 'Message': 'OtherMessage'}},
            'other_operation'
        )
        with self.assertRaises(ClientError):
            publish_cli(self.ctx_mock, self.template)

        click_mock.secho.assert_called_with("Publish Failed", fg="red")
Example #7
0
    def test_must_raise_if_not_s3_uri_error(self, click_mock,
                                            publish_application_mock):
        publish_application_mock.side_effect = ClientError(
            {'Error': {
                'Code': 'OtherError',
                'Message': 'OtherMessage'
            }}, 'other_operation')
        with self.assertRaises(ClientError):
            publish_cli(self.ctx_mock, self.template)

        click_mock.secho.assert_called_with("Publish Failed", fg="red")
Example #8
0
    def test_must_raise_if_invalid_template(self, exception_to_raise,
                                            click_mock,
                                            get_template_data_mock):
        get_template_data_mock.side_effect = exception_to_raise(
            "Template not found")
        with self.assertRaises(exception_to_raise) as context:
            publish_cli(self.ctx_mock, self.template, None)

        message = str(context.exception)
        self.assertEqual("Template not found", message)
        click_mock.secho.assert_called_with("Publish Failed", fg="red")
    def test_print_console_link_if_context_region_not_set(self, click_mock, boto3_mock, publish_application_mock):
        self.ctx_mock.region = None
        publish_application_mock.return_value = {
            "application_id": self.application_id,
            "details": {"attr1": "value1"},
            "actions": [UPDATE_APPLICATION],
        }

        session_mock = Mock()
        session_mock.region_name = "us-west-1"
        boto3_mock.Session.return_value = session_mock

        publish_cli(self.ctx_mock, self.template, None)
        expected_link = self.console_link.format(session_mock.region_name, self.application_id.replace("/", "~"))
        click_mock.secho.assert_called_with(expected_link, fg="yellow")
Example #10
0
    def test_must_raise_if_s3_uri_error(self, click_mock,
                                        publish_application_mock):
        publish_application_mock.side_effect = ClientError(
            {
                'Error': {
                    'Code': 'BadRequestException',
                    'Message': 'Invalid S3 URI'
                }
            }, 'create_application')
        with self.assertRaises(UserException) as context:
            publish_cli(self.ctx_mock, self.template)

        message = str(context.exception)
        self.assertIn(
            "Please make sure that you have uploaded application artifacts "
            "to S3 by packaging the template", message)
        click_mock.secho.assert_called_with("Publish Failed", fg="red")
Example #11
0
    def test_must_raise_if_s3_uri_error(self, click_mock, publish_application_mock):
        publish_application_mock.side_effect = ClientError(
            {
                'Error': {
                    'Code': 'BadRequestException',
                    'Message': 'Invalid S3 URI'
                }
            },
            'create_application'
        )
        with self.assertRaises(UserException) as context:
            publish_cli(self.ctx_mock, self.template)

        message = str(context.exception)
        self.assertIn("Please make sure that you have uploaded application artifacts "
                      "to S3 by packaging the template", message)
        click_mock.secho.assert_called_with("Publish Failed", fg="red")
Example #12
0
 def test_must_use_template_semantic_version(self, publish_application_mock,
                                             get_template_data_mock):
     template_data = {
         METADATA: {
             SERVERLESS_REPO_APPLICATION: {
                 SEMANTIC_VERSION: '0.1'
             }
         }
     }
     get_template_data_mock.return_value = template_data
     publish_application_mock.return_value = {
         'application_id': self.application_id,
         'details': {},
         'actions': {}
     }
     publish_cli(self.ctx_mock, self.template, None)
     publish_application_mock.assert_called_with(template_data)
    def test_must_succeed_to_update_application(self, click_mock, publish_application_mock):
        publish_application_mock.return_value = {
            "application_id": self.application_id,
            "details": {"attr1": "value1"},
            "actions": [UPDATE_APPLICATION],
        }

        publish_cli(self.ctx_mock, self.template, None)
        details_str = json.dumps({"attr1": "value1"}, indent=2)
        expected_msg = 'The following metadata of application "{}" has been updated:\n{}'
        expected_link = self.console_link.format(self.ctx_mock.region, self.application_id.replace("/", "~"))
        click_mock.secho.assert_has_calls(
            [
                call("Publish Succeeded", fg="green"),
                call(expected_msg.format(self.application_id, details_str)),
                call(expected_link, fg="yellow"),
            ]
        )
Example #14
0
    def test_must_succeed_to_create_application(self, click_mock, publish_application_mock):
        publish_application_mock.return_value = {
            'application_id': self.application_id,
            'details': {'attr1': 'value1'},
            'actions': [CREATE_APPLICATION]
        }

        publish_cli(self.ctx_mock, self.template)
        details_str = json.dumps({'attr1': 'value1'}, indent=2)
        expected_msg = "Created new application with the following metadata:\n{}"
        expected_link = self.console_link.format(
            self.ctx_mock.region,
            self.application_id.replace('/', '~')
        )
        click_mock.secho.assert_has_calls([
            call("Publish Succeeded", fg="green"),
            call(expected_msg.format(details_str), fg="yellow"),
            call(expected_link, fg="yellow")
        ])
Example #15
0
    def test_print_console_link_if_context_region_not_set(
            self, click_mock, boto3_mock, publish_application_mock):
        self.ctx_mock.region = None
        publish_application_mock.return_value = {
            'application_id': self.application_id,
            'details': {
                'attr1': 'value1'
            },
            'actions': [UPDATE_APPLICATION]
        }

        session_mock = Mock()
        session_mock.region_name = "us-west-1"
        boto3_mock.Session.return_value = session_mock

        publish_cli(self.ctx_mock, self.template, None)
        expected_link = self.console_link.format(
            session_mock.region_name, self.application_id.replace('/', '~'))
        click_mock.secho.assert_called_with(expected_link, fg="yellow")
Example #16
0
    def test_print_console_link_if_context_region_not_set(self, click_mock, boto3_mock,
                                                          publish_application_mock):
        self.ctx_mock.region = None
        publish_application_mock.return_value = {
            'application_id': self.application_id,
            'details': {'attr1': 'value1'},
            'actions': [UPDATE_APPLICATION]
        }

        session_mock = Mock()
        session_mock.region_name = "us-west-1"
        boto3_mock.Session.return_value = session_mock

        publish_cli(self.ctx_mock, self.template)
        expected_link = self.console_link.format(
            session_mock.region_name,
            self.application_id.replace('/', '~')
        )
        click_mock.secho.assert_called_with(expected_link, fg="yellow")
Example #17
0
    def test_must_succeed_to_create_application(self, click_mock,
                                                publish_application_mock):
        publish_application_mock.return_value = {
            'application_id': self.application_id,
            'details': {
                'attr1': 'value1'
            },
            'actions': [CREATE_APPLICATION]
        }

        publish_cli(self.ctx_mock, self.template, None)
        details_str = json.dumps({'attr1': 'value1'}, indent=2)
        expected_msg = "Created new application with the following metadata:\n{}"
        expected_link = self.console_link.format(
            self.ctx_mock.region, self.application_id.replace('/', '~'))
        click_mock.secho.assert_has_calls([
            call("Publish Succeeded", fg="green"),
            call(expected_msg.format(details_str)),
            call(expected_link, fg="yellow")
        ])
Example #18
0
    def test_must_raise_if_serverlessrepo_error(self, click_mock, publish_application_mock):
        publish_application_mock.side_effect = ServerlessRepoError()
        with self.assertRaises(UserException):
            publish_cli(self.ctx_mock, self.template)

        click_mock.secho.assert_called_with("Publish Failed", fg="red")