From c27b97380dd08c9c2c04e5237e1c9e5c1835a52c Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Tue, 13 Nov 2018 11:43:59 +0000 Subject: [PATCH] Add decorator deleting cache for template folder client update method --- .../template_folder_api_client.py | 1 + .../test_template_folder_client.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/notify_client/template_folder_api_client.py b/app/notify_client/template_folder_api_client.py index ea078b716..0a8952e9e 100644 --- a/app/notify_client/template_folder_api_client.py +++ b/app/notify_client/template_folder_api_client.py @@ -43,6 +43,7 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient): template_ids, )) + @cache.delete('service-{service_id}-template-folders') def update_template_folder(self, service_id, template_folder_id, name): self.post( '/service/{}/template-folder/{}'.format(service_id, template_folder_id), diff --git a/tests/app/notify_client/test_template_folder_client.py b/tests/app/notify_client/test_template_folder_client.py index 3a6687a66..7a6a121c5 100644 --- a/tests/app/notify_client/test_template_folder_client.py +++ b/tests/app/notify_client/test_template_folder_client.py @@ -103,3 +103,21 @@ def test_move_templates_and_folders_to_root(mocker, api_user_active): 'templates': ['a', 'b', 'c'], }, ) + + +def test_update_template_folder_calls_correct_api_endpoint(mocker, api_user_active): + mock_redis_delete = mocker.patch('app.notify_client.RedisClient.delete') + + some_service_id = uuid.uuid4() + template_folder_id = uuid.uuid4() + expected_url = '/service/{}/template-folder/{}'.format(some_service_id, template_folder_id) + data = {'name': 'foo'} + + client = TemplateFolderAPIClient() + + mock_post = mocker.patch('app.notify_client.template_folder_api_client.TemplateFolderAPIClient.post') + + client.update_template_folder(some_service_id, template_folder_id, name='foo') + + mock_post.assert_called_once_with(expected_url, data) + mock_redis_delete.assert_called_once_with('service-{}-template-folders'.format(some_service_id))