def test_download_layer_that_was_template_defined(
        self, codeuri, adjusted_codeuri, create_cache_patch, resolve_code_path_patch
    ):
        """
        when the template is not lcoated in working directory, layer's codeuri needs to be adjusted
        """
        stack_path_mock = Mock()
        stack_template_location = "./some/path/template.yaml"

        download_layers = LayerDownloader(
            "/home", ".", [Mock(stack_path=stack_path_mock, location=stack_template_location)]
        )

        layer_mock = Mock()
        layer_mock.is_template_defined = True
        layer_mock.name = "layer1"
        layer_mock.codeuri = codeuri
        layer_mock.stack_path = stack_path_mock

        resolve_code_path_return_mock = Mock()
        resolve_code_path_patch.return_value = resolve_code_path_return_mock

        actual = download_layers.download(layer_mock)

        self.assertEqual(actual.codeuri, resolve_code_path_return_mock)

        create_cache_patch.assert_not_called()
        resolve_code_path_patch.assert_called_once_with(".", adjusted_codeuri)
    def test_download_layer(
        self, is_layer_cached_patch, create_cache_patch, fetch_layer_uri_patch, unzip_from_uri_patch
    ):
        is_layer_cached_patch.return_value = False

        download_layers = LayerDownloader("/home", ".", Mock())

        layer_mock = Mock()
        layer_mock.is_defined_within_template = False
        layer_mock.name = "layer1"
        layer_mock.arn = "arn:layer:layer1:1"
        layer_mock.layer_arn = "arn:layer:layer1"

        fetch_layer_uri_patch.return_value = "layer/uri"

        actual = download_layers.download(layer_mock)

        self.assertEqual(actual.codeuri, str(Path("/home/layer1").resolve()))

        create_cache_patch.assert_called_once_with("/home")
        fetch_layer_uri_patch.assert_called_once_with(layer_mock)
        unzip_from_uri_patch.assert_called_once_with(
            "layer/uri",
            str(Path("/home/layer1.zip").resolve()),
            unzip_output_dir=str(Path("/home/layer1").resolve()),
            progressbar_label="Downloading arn:layer:layer1",
        )
    def test_download_layer_that_is_cached(self, is_layer_cached_patch, create_cache_patch):
        is_layer_cached_patch.return_value = True

        download_layers = LayerDownloader("/home", ".")

        layer_mock = Mock()
        layer_mock.is_defined_within_template = False
        layer_mock.name = "layer1"

        actual = download_layers.download(layer_mock)

        self.assertEquals(actual.codeuri, '/home/layer1')

        create_cache_patch.assert_called_once_with("/home")
    def test_download_layer_that_is_cached(self, is_layer_cached_patch, create_cache_patch):
        is_layer_cached_patch.return_value = True

        download_layers = LayerDownloader("/home", ".", Mock())

        layer_mock = Mock()
        layer_mock.is_defined_within_template = False
        layer_mock.name = "layer1"

        actual = download_layers.download(layer_mock)

        self.assertEqual(actual.codeuri, str(Path("/home/layer1").resolve()))

        create_cache_patch.assert_called_once_with("/home")
    def test_download_layer_that_was_template_defined(self, create_cache_patch, resolve_code_path_patch):

        download_layers = LayerDownloader("/home", ".")

        layer_mock = Mock()
        layer_mock.is_template_defined = True
        layer_mock.name = "layer1"
        layer_mock.codeuri = "/some/custom/path"

        resolve_code_path_patch.return_value = './some/custom/path'

        actual = download_layers.download(layer_mock)

        self.assertEquals(actual.codeuri, './some/custom/path')

        create_cache_patch.assert_not_called()
        resolve_code_path_patch.assert_called_once_with(".", "/some/custom/path")
Esempio n. 6
0
    def test_download_layer_that_was_template_defined(self, create_cache_patch, resolve_code_path_patch):

        download_layers = LayerDownloader("/home", ".")

        layer_mock = Mock()
        layer_mock.is_template_defined = True
        layer_mock.name = "layer1"
        layer_mock.codeuri = "/some/custom/path"

        resolve_code_path_patch.return_value = './some/custom/path'

        actual = download_layers.download(layer_mock)

        self.assertEquals(actual.codeuri, './some/custom/path')

        create_cache_patch.assert_not_called()
        resolve_code_path_patch.assert_called_once_with(".", "/some/custom/path")
    def test_download_layer(self, is_layer_cached_patch, create_cache_patch,
                            fetch_layer_uri_patch, unzip_from_uri_patch):
        is_layer_cached_patch.return_value = False

        download_layers = LayerDownloader("/home", ".")

        layer_mock = Mock()
        layer_mock.is_defined_within_template = False
        layer_mock.name = "layer1"
        layer_mock.arn = "arn:layer:layer1:1"
        layer_mock.layer_arn = "arn:layer:layer1"

        fetch_layer_uri_patch.return_value = "layer/uri"

        actual = download_layers.download(layer_mock)

        self.assertEquals(actual.codeuri, "/home/layer1")

        create_cache_patch.assert_called_once_with("/home")
        fetch_layer_uri_patch.assert_called_once_with(layer_mock)
        unzip_from_uri_patch.assert_called_once_with("layer/uri",
                                                     '/home/layer1.zip',
                                                     unzip_output_dir='/home/layer1',
                                                     progressbar_label="Downloading arn:layer:layer1")