Пример #1
0
    def test_artifact_different_from_required_option(self, template_artifacts_mock):
        template_artifacts_mock.return_value = [IMAGE, ZIP]
        mock_params = MagicMock()
        mock_params.get = MagicMock(
            side_effect=[
                MagicMock(),  # mock_params.get("t")
                False,  # mock_params.get("resolve_s3")
            ]
        )
        mock_default_map = MagicMock()
        mock_default_map.get = MagicMock(return_value=False)
        param = MagicMock()
        param.name = "s3_bucket"
        param.opts.__getitem__.return_value = ["--s3-bucket"]
        image_repository = None

        with self.assertRaises(click.BadOptionUsage) as ex:
            artifact_callback(
                ctx=MockContext(info_name="test", parent=None, params=mock_params, default_map=mock_default_map),
                param=param,
                provided_value=image_repository,
                artifact=ZIP,
            )
        self.assertEqual(ex.exception.option_name, "s3_bucket")
        self.assertEqual(ex.exception.message, "Missing option '['--s3-bucket']'")
Пример #2
0
    def test_image_based_artifact_image_repo_not_given_error(
            self, template_artifacts_mock):
        template_artifacts_mock.return_value = [IMAGE]
        mock_params = MagicMock()
        mock_params.get = MagicMock()
        image_repository = None

        with self.assertRaises(click.BadOptionUsage):
            artifact_callback(
                ctx=MockContext(info_name="test",
                                parent=None,
                                params=mock_params),
                param=MagicMock(),
                provided_value=image_repository,
                artifact=IMAGE,
            )
Пример #3
0
 def test_zip_based_artifact_s3_bucket_not_given_error(
         self, template_artifacts_mock):
     # implicitly artifacts are zips
     template_artifacts_mock.return_value = [ZIP]
     mock_params = MagicMock()
     mock_params.get = MagicMock()
     s3_bucket = None
     with self.assertRaises(click.BadOptionUsage):
         artifact_callback(
             ctx=MockContext(info_name="test",
                             parent=None,
                             params=mock_params),
             param=MagicMock(),
             provided_value=s3_bucket,
             artifact=ZIP,
         )
Пример #4
0
 def test_zip_based_artifact_s3_bucket_not_given_error(self, template_artifacts_mock):
     # implicitly artifacts are zips
     template_artifacts_mock.return_value = [ZIP]
     mock_params = MagicMock()
     mock_params.get.side_effect = [
         MagicMock(),
         False,
     ]
     mock_default_map = MagicMock()
     mock_default_map.get.side_effect = [False]
     mock_param = MagicMock(name="s3_bucket")
     mock_param.name = "s3_bucket"
     s3_bucket = None
     with self.assertRaises(click.BadOptionUsage):
         artifact_callback(
             ctx=MockContext(info_name="test", parent=None, params=mock_params, default_map=mock_default_map),
             param=mock_param,
             provided_value=s3_bucket,
             artifact=ZIP,
         )
Пример #5
0
    def test_image_based_artifact_image_repo(self, template_artifacts_mock):
        template_artifacts_mock.return_value = [IMAGE]
        mock_params = MagicMock()
        mock_params.get = MagicMock()
        image_repository = "123456789.dkr.ecr.us-east-1.amazonaws.com/sam-cli"

        result = artifact_callback(
            ctx=MockContext(info_name="test", parent=None, params=mock_params),
            param=MagicMock(),
            provided_value=image_repository,
            artifact=IMAGE,
        )
        self.assertEqual(result, image_repository)
Пример #6
0
 def test_zip_based_artifact_s3_required(self, template_artifacts_mock):
     # implicitly artifacts are zips
     template_artifacts_mock.return_value = [ZIP]
     mock_params = MagicMock()
     mock_params.get = MagicMock()
     s3_bucket = "mock-bucket"
     result = artifact_callback(
         ctx=MockContext(info_name="test", parent=None, params=mock_params),
         param=MagicMock(),
         provided_value=s3_bucket,
         artifact=ZIP,
     )
     self.assertEqual(result, s3_bucket)
Пример #7
0
 def test_zip_based_artifact_s3_not_required_resolve_s3_option_present(
         self, template_artifacts_mock):
     # implicitly artifacts are zips
     template_artifacts_mock.return_value = [ZIP]
     mock_params = MagicMock()
     mock_params.get = MagicMock(side_effect=[
         MagicMock(),  # mock_params.get("t")
         MagicMock(),  # mock_params.get("template-file")
         MagicMock(),  # mock_params.get("template")
         True,  # mock_params.get("resolve_s3")
     ])
     s3_bucket = "mock-bucket"
     result = artifact_callback(
         ctx=MockContext(info_name="test", parent=None, params=mock_params),
         param=MagicMock(name="s3_bucket"),
         provided_value=s3_bucket,
         artifact=ZIP,
     )
     # No Exceptions thrown since resolve_s3 is True
     self.assertEqual(result, s3_bucket)