mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-18 21:44:11 -04:00
Merge pull request #4077 from alphagov/reduce-redis-cache-ttl
Reduce impact of bug with performance page caching stale data
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from datetime import date
|
||||
from unittest.mock import call
|
||||
|
||||
from app.notify_client.performance_dashboard_api_client import (
|
||||
PerformanceDashboardAPIClient,
|
||||
@@ -42,21 +41,15 @@ def test_sets_value_in_cache(mocker):
|
||||
end_date=date(2022, 2, 2),
|
||||
) == {'data_from': 'api'}
|
||||
|
||||
assert mock_redis_get.call_args_list == [
|
||||
call('performance-stats-2021-01-01-to-2022-02-02'),
|
||||
]
|
||||
assert mock_api_get.call_args_list == [
|
||||
call('/performance-dashboard', params={
|
||||
mock_redis_get.assert_called_once_with('performance-stats-2021-01-01-to-2022-02-02')
|
||||
mock_api_get.assert_called_once_with('/performance-dashboard', params={
|
||||
'start_date': '2021-01-01', 'end_date': '2022-02-02'
|
||||
}),
|
||||
]
|
||||
assert mock_redis_set.call_args_list == [
|
||||
call(
|
||||
'performance-stats-2021-01-01-to-2022-02-02',
|
||||
'{"data_from": "api"}',
|
||||
ex=604800,
|
||||
),
|
||||
]
|
||||
})
|
||||
mock_redis_set.assert_called_once_with(
|
||||
'performance-stats-2021-01-01-to-2022-02-02',
|
||||
'{"data_from": "api"}',
|
||||
ex=3600,
|
||||
)
|
||||
|
||||
|
||||
def test_returns_value_from_cache(mocker):
|
||||
@@ -78,8 +71,6 @@ def test_returns_value_from_cache(mocker):
|
||||
end_date=date(2022, 2, 2),
|
||||
) == {'data_from': 'cache'}
|
||||
|
||||
assert mock_redis_get.call_args_list == [
|
||||
call('performance-stats-2021-01-01-to-2022-02-02'),
|
||||
]
|
||||
mock_redis_get.assert_called_once_with('performance-stats-2021-01-01-to-2022-02-02')
|
||||
assert mock_api_get.called is False
|
||||
assert mock_redis_set.called is False
|
||||
|
||||
59
tests/app/notify_client/test_status_api_client.py
Normal file
59
tests/app/notify_client/test_status_api_client.py
Normal file
@@ -0,0 +1,59 @@
|
||||
from app.notify_client.status_api_client import StatusApiClient
|
||||
|
||||
|
||||
def test_get_count_of_live_services_and_organisations(mocker):
|
||||
mocker.patch('app.extensions.RedisClient.get', return_value=None)
|
||||
client = StatusApiClient()
|
||||
mock = mocker.patch.object(client, 'get', return_value={})
|
||||
|
||||
client.get_count_of_live_services_and_organisations()
|
||||
|
||||
mock.assert_called_once_with(url='/_status/live-service-and-organisation-counts')
|
||||
|
||||
|
||||
def test_sets_value_in_cache(mocker):
|
||||
client = StatusApiClient()
|
||||
|
||||
mock_redis_get = mocker.patch(
|
||||
'app.extensions.RedisClient.get',
|
||||
return_value=None
|
||||
)
|
||||
mock_api_get = mocker.patch(
|
||||
'app.notify_client.NotifyAdminAPIClient.get',
|
||||
return_value={'data_from': 'api'},
|
||||
)
|
||||
mock_redis_set = mocker.patch(
|
||||
'app.extensions.RedisClient.set',
|
||||
)
|
||||
|
||||
assert client.get_count_of_live_services_and_organisations() == {'data_from': 'api'}
|
||||
|
||||
mock_redis_get.assert_called_once_with('live-service-and-organisation-counts')
|
||||
mock_api_get.assert_called_once_with(url='/_status/live-service-and-organisation-counts')
|
||||
mock_redis_set.assert_called_once_with(
|
||||
'live-service-and-organisation-counts',
|
||||
'{"data_from": "api"}',
|
||||
ex=3600
|
||||
)
|
||||
|
||||
|
||||
def test_returns_value_from_cache(mocker):
|
||||
client = StatusApiClient()
|
||||
|
||||
mock_redis_get = mocker.patch(
|
||||
'app.extensions.RedisClient.get',
|
||||
return_value=b'{"data_from": "cache"}',
|
||||
)
|
||||
mock_api_get = mocker.patch(
|
||||
'app.notify_client.NotifyAdminAPIClient.get',
|
||||
)
|
||||
mock_redis_set = mocker.patch(
|
||||
'app.extensions.RedisClient.set',
|
||||
)
|
||||
|
||||
assert client.get_count_of_live_services_and_organisations() == {'data_from': 'cache'}
|
||||
|
||||
mock_redis_get.assert_called_once_with('live-service-and-organisation-counts')
|
||||
|
||||
assert mock_api_get.called is False
|
||||
assert mock_redis_set.called is False
|
||||
Reference in New Issue
Block a user