Allow platform admins to clear cached broadcasts

When we add a new property to the broadcast model, we need to delete any
cached broadcasts from Redis that are missing the new property. So this
adds an option to do this to the cache page in platform admin.

I’ve also tried to make it more obvious what the magic numbers in the
test fixture are doing.
This commit is contained in:
Chris Hill-Scott
2020-10-08 14:30:09 +01:00
parent 850571cb8c
commit 54d4fb2a6c
2 changed files with 12 additions and 4 deletions

View File

@@ -432,6 +432,9 @@ def clear_cache():
'live-service-and-organisation-counts',
'organisation-????????-????-????-????-????????????-name',
]),
('broadcast', [
'service-????????-????-????-????-????????????-broadcast-message-????????-????-????-????-????????????',
]),
])
form = ClearCacheForm()

View File

@@ -692,7 +692,7 @@ def test_clear_cache_shows_form(client_request, platform_admin_user, mocker):
call('service-????????-????-????-????-????????????-templates'),
call('service-????????-????-????-????-????????????-template-????????-????-????-????-????????????-version-*'),
call('service-????????-????-????-????-????????????-template-????????-????-????-????-????????????-versions'),
], 'Removed 3 template objects from redis'),
], 'Removed 103 template objects from redis'),
('service', [
call('has_jobs-????????-????-????-????-????????????'),
call('service-????????-????-????-????-????????????'),
@@ -701,13 +701,16 @@ def test_clear_cache_shows_form(client_request, platform_admin_user, mocker):
call('service-????????-????-????-????-????????????-template-folders'),
call('service-????????-????-????-????-????????????-returned-letters-statistics'),
call('service-????????-????-????-????-????????????-returned-letters-summary'),
], 'Removed 3 service objects from redis'),
], 'Removed 107 service objects from redis'),
('organisation', [
call('organisations'),
call('domains'),
call('live-service-and-organisation-counts'),
call('organisation-????????-????-????-????-????????????-name'),
], 'Removed 3 organisation objects from redis'),
], 'Removed 104 organisation objects from redis'),
('broadcast', [
call('service-????????-????-????-????-????????????-broadcast-message-????????-????-????-????-????????????'),
], 'Removed 101 broadcast objects from redis'),
))
def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted(
client_request,
@@ -718,7 +721,9 @@ def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted(
expected_confirmation,
):
redis = mocker.patch('app.main.views.platform_admin.redis_client')
redis.delete_cache_keys_by_pattern.side_effect = [0, 3, 1, 0, 0, 0, 0, 0]
# The way this is set up means the first time `delete_cache_keys_by_pattern`
# is called it will return `101`, the second time it will return `102`, etc
redis.delete_cache_keys_by_pattern.side_effect = [101, 102, 103, 104, 105, 106, 107, 108, 109]
client_request.login(platform_admin_user)
page = client_request.post('main.clear_cache', _data={'model_type': model_type}, _expected_status=200)