make perf platform client handle more stuff sensibly

specifically, all of the performance platform specific data layout now
happens in performance_platform_client.py - stuff like setting the
_timestamp, period etc, and the perf platform-specific nomenclature is
all handled there.
This commit is contained in:
Leo Hemsted
2017-08-24 17:08:39 +01:00
parent 412c87cfc8
commit e85b621cbc
8 changed files with 64 additions and 47 deletions

View File

@@ -270,7 +270,7 @@ def test_will_remove_csv_files_for_jobs_older_than_seven_days(
]
def test_send_daily_performance_stats_calls_does_not_send_if_inactive(mocker):
def test_send_daily_performance_stats_calls_does_not_send_if_inactive(client, mocker):
send_mock = mocker.patch('app.celery.scheduled_tasks.total_sent_notifications.send_total_notifications_sent_for_day_stats') # noqa
with patch.object(
@@ -322,8 +322,8 @@ def test_send_daily_performance_stats_calls_with_correct_totals(
send_daily_performance_platform_stats()
perf_mock.assert_has_calls([
call(get_london_midnight_in_utc(yesterday), 'sms', 2, 'day'),
call(get_london_midnight_in_utc(yesterday), 'email', 3, 'day')
call(get_london_midnight_in_utc(yesterday), 'sms', 2),
call(get_london_midnight_in_utc(yesterday), 'email', 3)
])

View File

@@ -6,7 +6,7 @@ from app.clients.performance_platform.performance_platform_client import Perform
@pytest.fixture(scope='function')
def perf_client(mocker):
def perf_client(client, mocker):
perf_client = PerformancePlatformClient()
current_app = mocker.Mock(config={
'PERFORMANCE_PLATFORM_ENABLED': True,
@@ -24,15 +24,15 @@ def test_should_not_call_if_not_enabled(perf_client):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://performance-platform-url/foo', json={}, status_code=200)
perf_client._active = False
perf_client.send_stats_to_performance_platform(dataset='foo', payload={})
perf_client.send_stats_to_performance_platform({'dataType': 'foo'})
assert request_mock.called is False
def test_should_call_if_enabled(perf_client):
def test_should_call_datatype_endpoint_if_enabled(perf_client):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://performance-platform-url/foo', json={}, status_code=200)
perf_client.send_stats_to_performance_platform(dataset='foo', payload={})
perf_client.send_stats_to_performance_platform({'dataType': 'foo'})
assert request_mock.call_count == 1
assert request_mock.last_request.method == 'POST'
@@ -46,7 +46,7 @@ def test_should_use_correct_token(perf_client, dataset, token):
with requests_mock.Mocker() as request_mock:
request_mock.post('https://performance-platform-url/foo', json={}, status_code=200)
request_mock.post('https://performance-platform-url/bar', json={}, status_code=200)
perf_client.send_stats_to_performance_platform(dataset=dataset, payload={})
perf_client.send_stats_to_performance_platform({'dataType': dataset})
assert request_mock.call_count == 1
assert request_mock.last_request.headers.get('authorization') == 'Bearer {}'.format(token)
@@ -55,4 +55,4 @@ def test_should_use_correct_token(perf_client, dataset, token):
def test_should_raise_for_status(perf_client):
with pytest.raises(requests.HTTPError), requests_mock.Mocker() as request_mock:
request_mock.post('https://performance-platform-url/foo', json={}, status_code=403)
perf_client.send_stats_to_performance_platform(dataset='foo', payload={})
perf_client.send_stats_to_performance_platform({'dataType': 'foo'})

View File

@@ -19,15 +19,13 @@ def test_send_total_notifications_sent_for_day_stats_stats_creates_correct_call(
send_total_notifications_sent_for_day_stats(
date=datetime(2016, 10, 15, 23, 0, 0),
channel='sms',
count=142,
period='day'
notification_type='sms',
count=142
)
assert send_stats.call_count == 1
assert send_stats.call_args[1]['dataset'] == 'notifications'
request_args = send_stats.call_args[1]['payload']
request_args = send_stats.call_args[0][0]
assert request_args['dataType'] == 'notifications'
assert request_args['service'] == 'govuk-notify'
assert request_args['period'] == 'day'