|
9 | 9 | from pathlib import Path
|
10 | 10 | from typing import Dict, Any
|
11 | 11 | from unittest import TestCase
|
12 |
| -from unittest.mock import patch, ANY |
| 12 | +from unittest.mock import patch, ANY, Mock |
13 | 13 |
|
14 | 14 | import botocore.exceptions
|
15 | 15 | import click
|
@@ -2204,6 +2204,24 @@ def test_must_return_runtime_from_base_image_name(self):
|
2204 | 2204 | runtime = get_runtime(IMAGE, base_image)
|
2205 | 2205 | self.assertEqual(runtime, expected_runtime[index])
|
2206 | 2206 |
|
| 2207 | + @patch("samcli.commands.init.init_templates.requests") |
| 2208 | + @patch.object(InitTemplates, "__init__", MockInitTemplates.__init__) |
| 2209 | + def test_must_fallback_for_non_ok_http_response(self, requests_mock): |
| 2210 | + requests_mock.get.return_value = Mock(ok=False) |
| 2211 | + requests_mock.Timeout = requests.Timeout |
| 2212 | + requests_mock.ConnectionError = requests.ConnectionError |
| 2213 | + |
| 2214 | + template = InitTemplates() |
| 2215 | + with mock.patch.object( |
| 2216 | + template, "clone_templates_repo", wraps=template.clone_templates_repo |
| 2217 | + ) as mocked_clone_templates_repo: |
| 2218 | + with mock.patch.object( |
| 2219 | + template, "get_manifest_path", wraps=template.get_manifest_path |
| 2220 | + ) as mocked_get_manifest_path: |
| 2221 | + template.get_preprocessed_manifest() |
| 2222 | + mocked_clone_templates_repo.assert_called_once() |
| 2223 | + mocked_get_manifest_path.assert_called_once() |
| 2224 | + |
2207 | 2225 | @patch("samcli.commands.init.init_templates.InitTemplates._get_manifest")
|
2208 | 2226 | @patch.object(InitTemplates, "__init__", MockInitTemplates.__init__)
|
2209 | 2227 | def test_must_process_manifest(self, _get_manifest_mock):
|
|
0 commit comments