Send results of processing-time query to performance platform

This commit is contained in:
Katie Smith
2017-08-30 14:36:16 +01:00
parent 132d65bc75
commit a1a5fdedb1
4 changed files with 111 additions and 22 deletions

View File

@@ -29,7 +29,8 @@ from app.celery.scheduled_tasks import (
switch_current_sms_provider_on_slow_delivery,
timeout_job_statistics,
timeout_notifications,
populate_monthly_billing)
populate_monthly_billing,
send_total_sent_notifications_to_performance_platform)
from app.clients.performance_platform.performance_platform_client import PerformancePlatformClient
from app.config import QueueNames, TaskNames
from app.dao.jobs_dao import dao_get_job_by_id
@@ -285,7 +286,7 @@ def test_send_daily_performance_stats_calls_does_not_send_if_inactive(client, mo
@freeze_time("2016-01-11 12:30:00")
def test_send_daily_performance_stats_calls_with_correct_totals(
def test_send_total_sent_notifications_to_performance_platform_calls_with_correct_totals(
notify_db,
notify_db_session,
sample_template,
@@ -319,7 +320,7 @@ def test_send_daily_performance_stats_calls_with_correct_totals(
new_callable=PropertyMock
) as mock_active:
mock_active.return_value = True
send_daily_performance_platform_stats()
send_total_sent_notifications_to_performance_platform()
perf_mock.assert_has_calls([
call(get_london_midnight_in_utc(yesterday), 'sms', 2),

View File

@@ -0,0 +1,47 @@
from datetime import datetime, timedelta
from freezegun import freeze_time
from tests.app.db import create_notification
from app.performance_platform.processing_time import (
send_processing_time_to_performance_platform,
send_processing_time_data
)
@freeze_time('2016-10-18T02:00')
def test_send_processing_time_to_performance_platform_generates_correct_calls(mocker, sample_template):
send_mock = mocker.patch('app.performance_platform.processing_time.send_processing_time_data')
created_at = datetime.utcnow() - timedelta(days=1)
create_notification(sample_template, created_at=created_at, sent_at=created_at + timedelta(seconds=5))
create_notification(sample_template, created_at=created_at, sent_at=created_at + timedelta(seconds=15))
create_notification(sample_template, created_at=datetime.utcnow() - timedelta(days=2))
send_processing_time_to_performance_platform()
send_mock.assert_any_call(datetime(2016, 10, 16, 23, 0), 'messages-total', 2)
send_mock.assert_any_call(datetime(2016, 10, 16, 23, 0), 'messages-within-10-secs', 1)
def test_send_processing_time_to_performance_platform_creates_correct_call_to_perf_platform(mocker):
send_stats = mocker.patch('app.performance_platform.total_sent_notifications.performance_platform_client.send_stats_to_performance_platform') # noqa
send_processing_time_data(
date=datetime(2016, 10, 15, 23, 0, 0),
status='foo',
count=142
)
assert send_stats.call_count == 1
request_args = send_stats.call_args[0][0]
assert request_args['dataType'] == 'processing-time'
assert request_args['service'] == 'govuk-notify'
assert request_args['period'] == 'day'
assert request_args['status'] == 'foo'
assert request_args['_timestamp'] == '2016-10-16T00:00:00'
assert request_args['count'] == 142
expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMGdvdnVrLW5vdGlmeWZvb3Byb2Nlc3NpbmctdGltZWRheQ=='
assert request_args['_id'] == expected_base64_id