diff --git a/tests/test_command.py b/tests/test_command.py
index 23006fc..6d828c4 100644
--- a/tests/test_command.py
+++ b/tests/test_command.py
@@ -345,11 +345,10 @@ def test_watch_command_should_call_gateway_with_correct_arguments_belong_to_file
theme_id=1234, template_name='layout/base.html')
self.assertIn(expected_call_deleted, self.mock_gateway.mock_calls)
- @patch("ntk.command.time", autospec=True)
@patch("ntk.command.Command._get_accept_files", autospec=True)
@patch("builtins.open", autospec=True)
def test_watch_command_with_create_image_file_should_call_gateway_with_correct_arguments(
- self, mock_open_file, mock_get_accept_file, mock_time
+ self, mock_open_file, mock_get_accept_file
):
mock_get_accept_file.return_value = [
f'{os.getcwd()}/assets/image.jpg',
@@ -372,8 +371,6 @@ def test_watch_command_with_create_image_file_should_call_gateway_with_correct_a
)
self.assertIn(expected_call_added, self.mock_gateway.mock_calls)
- mock_time.sleep.assert_called_once_with(0.07)
-
@patch("ntk.command.Command._get_accept_files", autospec=True)
@patch("ntk.command.Command._compile_sass", autospec=True)
def test_watch_command_with_sass_directory_should_call_compile_sass(
diff --git a/tests/test_gateway.py b/tests/test_gateway.py
index 6e00fae..bfc04a8 100644
--- a/tests/test_gateway.py
+++ b/tests/test_gateway.py
@@ -27,13 +27,56 @@ def test_request(self, mock_request):
self.gateway._request(request_type, url, apikey=self.apikey, payload=payload, files=files)
- expected_calls = [call(
- 'POST', 'http://simple.com/api/admin/themes/5/templates/',
- headers={'Authorization': 'Bearer apikey'},
- data={'name': 'assets/base.html', 'content': '{% load i18n %}\n\n
My home page
'},
- files=files)
+ expected_calls = [
+ call(
+ 'POST', 'http://simple.com/api/admin/themes/5/templates/',
+ headers={'Authorization': 'Bearer apikey'},
+ data={
+ 'name': 'assets/base.html', 'content': '{% load i18n %}\n\nMy home page
'},
+ files=files),
+ call().status_code.__eq__(429)
]
- self.assertEqual(mock_request.mock_calls, expected_calls)
+ assert mock_request.mock_calls == expected_calls
+
+ @patch('ntk.gateway.requests.request', autospec=True)
+ def test_request_with_rate_limit_should_retry(self, mock_request):
+ mock_response_429 = MagicMock()
+ mock_response_429.status_code = 429
+ mock_response_429.content.decode.return_value = "throttled"
+
+ # Mock the response for the second call with status code 200
+ mock_response_200 = MagicMock()
+ mock_response_200.status_code = 200
+
+ mock_request.side_effect = [mock_response_429, mock_response_200]
+
+ request_type = 'POST'
+ url = 'http://simple.com/api/admin/themes/5/templates/'
+ payload = {
+ 'name': 'assets/base.html',
+ 'content': '{% load i18n %}\n\nMy home page
'
+ }
+ files = {'file': ('assets/image.jpg', self.mock_img_file)}
+
+ self.gateway._request(request_type, url, apikey=self.apikey, payload=payload, files=files)
+
+ assert mock_request.call_count == 2
+
+ expected_calls = [
+ call(
+ 'POST', 'http://simple.com/api/admin/themes/5/templates/',
+ headers={'Authorization': 'Bearer apikey'},
+ data={
+ 'name': 'assets/base.html', 'content': '{% load i18n %}\n\nMy home page
'
+ }, files=files),
+ call(
+ 'POST', 'http://simple.com/api/admin/themes/5/templates/',
+ headers={'Authorization': 'Bearer apikey'},
+ data={
+ 'name': 'assets/base.html', 'content': '{% load i18n %}\n\nMy home page
'
+ }, files=files)
+ ]
+ assert mock_request.mock_calls == expected_calls
#####
# get_themes