Delete service cache when changing an organisation's sector

When we change an organisation's sector we now also change the sector of
all its services, so we need to delete those services from Redis.
This commit is contained in:
Katie Smith
2019-07-24 11:57:42 +01:00
parent eb7504bc0d
commit dc1c73c647
4 changed files with 99 additions and 5 deletions

View File

@@ -359,17 +359,17 @@ def test_view_organisation_settings(
(
'.edit_organisation_type',
{'organisation_type': 'central'},
{'organisation_type': 'central'},
{'cached_service_ids': [], 'organisation_type': 'central'},
),
(
'.edit_organisation_type',
{'organisation_type': 'local'},
{'organisation_type': 'local'},
{'cached_service_ids': [], 'organisation_type': 'local'},
),
(
'.edit_organisation_type',
{'organisation_type': 'nhs_local'},
{'organisation_type': 'nhs_local'},
{'cached_service_ids': [], 'organisation_type': 'nhs_local'},
),
(
'.edit_organisation_crown_status',
@@ -412,6 +412,7 @@ def test_view_organisation_settings(
),
))
def test_update_organisation_settings(
mocker,
client_request,
fake_uuid,
organisation_one,
@@ -422,6 +423,7 @@ def test_update_organisation_settings(
expected_persisted,
user,
):
mocker.patch('app.organisations_client.get_organisation_services', return_value=[])
client_request.login(user(fake_uuid))
client_request.post(
@@ -442,6 +444,35 @@ def test_update_organisation_settings(
)
def test_update_organisation_sector_sends_service_id_data_to_api_client(
client_request,
mock_get_organisation,
organisation_one,
mock_get_organisation_services,
mock_update_organisation,
platform_admin_user,
):
client_request.login(platform_admin_user)
client_request.post(
'main.edit_organisation_type',
org_id=organisation_one['id'],
_data={'organisation_type': 'central'},
_expected_status=302,
_expected_redirect=url_for(
'main.organisation_settings',
org_id=organisation_one['id'],
_external=True,
),
)
mock_update_organisation.assert_called_once_with(
organisation_one['id'],
cached_service_ids=['12345', '67890', SERVICE_ONE_ID],
organisation_type='central'
)
@pytest.mark.parametrize('user', (
pytest.param(
platform_admin_user,

View File

@@ -138,3 +138,57 @@ def test_deletes_domain_cache(
assert call('domains') in mock_redis_delete.call_args_list
assert len(mock_request.call_args_list) == 1
def test_update_organisation_when_not_updating_org_type(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_organisation(fake_uuid, foo='bar')
mock_post.assert_called_with(
url='/organisations/{}'.format(fake_uuid),
data={'foo': 'bar'}
)
assert mock_redis_delete.call_args_list == [call('domains'), call('organisations')]
def test_update_organisation_when_updating_org_type_and_org_has_services(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_organisation(
fake_uuid,
cached_service_ids=['a', 'b', 'c'],
organisation_type='central',
)
mock_post.assert_called_with(
url='/organisations/{}'.format(fake_uuid),
data={'organisation_type': 'central'}
)
assert mock_redis_delete.call_args_list == [
call('domains'),
call('organisations'),
call('service-a', 'service-b', 'service-c'),
]
def test_update_organisation_when_updating_org_type_but_org_has_no_services(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_organisation(
fake_uuid,
cached_service_ids=[],
organisation_type='central',
)
mock_post.assert_called_with(
url='/organisations/{}'.format(fake_uuid),
data={'organisation_type': 'central'}
)
assert mock_redis_delete.call_args_list == [
call('domains'),
call('organisations'),
]