Skip to content

Commit

Permalink
Merge pull request #21 from 29next/20-improve-rate-limit-hanling
Browse files Browse the repository at this point in the history
20 improve rate limit hanling
  • Loading branch information
reloadsweety authored Mar 22, 2024
2 parents 39529f5 + 326aca3 commit eabc9f8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ntk/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def _push_templates(self, template_names, compile_sass=False):

response = self.gateway.create_or_update_template(
theme_id=self.config.theme_id, template_name=relative_pathfile, content=content, files=files)

time.sleep(0.07)
if not response.ok:
return

Expand All @@ -94,7 +96,7 @@ def _pull_templates(self, template_names):
response = self.gateway.get_templates(theme_id=self.config.theme_id)
templates = response.json()

if type(templates) != list:
if not isinstance(templates, list):
return

template_count = len(templates)
Expand Down
2 changes: 1 addition & 1 deletion ntk/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _wrapper(self, *func_args, **func_kwargs):
result = response.json()
error_msg = " -> "
for key, value in result.items():
if type(value) == list:
if isinstance(value, list):
error_msg += f'"{key}" : {" ".join(value)}'
else:
error_msg += value
Expand Down
5 changes: 4 additions & 1 deletion tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,11 @@ 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
self, mock_open_file, mock_get_accept_file, mock_time
):
mock_get_accept_file.return_value = [
f'{os.getcwd()}/assets/image.jpg',
Expand All @@ -371,6 +372,8 @@ 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(
Expand Down

0 comments on commit eabc9f8

Please sign in to comment.