From c36180741b6014597b0eb6eaac77e370a2e5da9b Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 12 Jan 2021 13:45:28 +0000 Subject: [PATCH 1/2] Clear the organisation cache when a service's organisation is changed. The /organisations page was showing the wrong live services count after a change is made to the service organisation. --- app/notify_client/organisations_api_client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/notify_client/organisations_api_client.py b/app/notify_client/organisations_api_client.py index 617859cba..b94b45139 100644 --- a/app/notify_client/organisations_api_client.py +++ b/app/notify_client/organisations_api_client.py @@ -64,6 +64,7 @@ class OrganisationsClient(NotifyAdminAPIClient): @cache.delete('service-{service_id}') @cache.delete('live-service-and-organisation-counts') + @cache.delete('organisations') def update_service_organisation(self, service_id, org_id): data = { 'service_id': service_id From 6639dc6061ffd2a99f173441e1c3c3cc771f61c9 Mon Sep 17 00:00:00 2001 From: Rebecca Law Date: Tue, 12 Jan 2021 15:39:51 +0000 Subject: [PATCH 2/2] Add a test that the redis delete cache is being called. --- .../notify_client/test_organisation_client.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/app/notify_client/test_organisation_client.py b/tests/app/notify_client/test_organisation_client.py index 0ec857f50..53aff113e 100644 --- a/tests/app/notify_client/test_organisation_client.py +++ b/tests/app/notify_client/test_organisation_client.py @@ -1,4 +1,4 @@ -from unittest.mock import call +from unittest.mock import ANY, call import pytest @@ -192,3 +192,23 @@ def test_update_organisation_when_updating_org_type_but_org_has_no_services(mock call('organisations'), call('domains'), ] + + +def test_update_service_organisation_deletes_cache(mocker, fake_uuid): + mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete') + mock_post = mocker.patch('app.notify_client.organisations_api_client.OrganisationsClient.post') + + organisations_client.update_service_organisation( + service_id=fake_uuid, + org_id=fake_uuid + ) + + assert sorted(mock_redis_delete.call_args_list) == [ + call('live-service-and-organisation-counts'), + call('organisations'), + call('service-{}'.format(fake_uuid)), + ] + mock_post.assert_called_with( + url='/organisations/{}/service'.format(fake_uuid), + data=ANY + )