From 99cc2f589706f27fdd17ed238ecd53e33761ad87 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 3 Feb 2017 13:32:19 +0000 Subject: [PATCH 1/3] Format date correctly for upload + refactor tests --- .../performance_platform_client.py | 10 ++++------ tests/app/clients/test_performance_platform.py | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/clients/performance_platform/performance_platform_client.py b/app/clients/performance_platform/performance_platform_client.py index a1d6ca17f..f55881413 100644 --- a/app/clients/performance_platform/performance_platform_client.py +++ b/app/clients/performance_platform/performance_platform_client.py @@ -1,8 +1,7 @@ import base64 import json +import requests from datetime import datetime -from requests import request - from flask import current_app from app.utils import ( @@ -30,7 +29,7 @@ class PerformancePlatformClient: def send_performance_stats(self, date, channel, count, period): if self.active: payload = { - '_timestamp': str(date), + '_timestamp': date.isoformat(), 'service': 'govuk-notify', 'channel': channel, 'count': count, @@ -62,10 +61,9 @@ class PerformancePlatformClient: 'Content-Type': "application/json", 'Authorization': 'Bearer {}'.format(self.bearer_token) } - resp = request( - "POST", + resp = requests.post( self.performance_platform_url, - data=json.dumps(payload), + json=payload, headers=headers ) diff --git a/tests/app/clients/test_performance_platform.py b/tests/app/clients/test_performance_platform.py index 530398dc9..2dd9a9b69 100644 --- a/tests/app/clients/test_performance_platform.py +++ b/tests/app/clients/test_performance_platform.py @@ -40,7 +40,7 @@ def test_should_not_call_if_not_enabled(notify_api, client, mocker): def test_should_call_if_enabled(notify_api, client, mocker): mocker.patch.object(client, '_send_stats_to_performance_platform') client.send_performance_stats( - date='2016-10-16T00:00:00+00:00', + date=datetime(2016, 10, 16, 0, 0, 0), channel='sms', count=142, period='day' @@ -57,7 +57,7 @@ def test_send_platform_stats_creates_correct_call(notify_api, client): status_code=200 ) client.send_performance_stats( - date='2016-10-16T00:00:00+00:00', + date=datetime(2016, 10, 16, 0, 0, 0), channel='sms', count=142, period='day' @@ -73,9 +73,9 @@ def test_send_platform_stats_creates_correct_call(notify_api, client): assert request_args['service'] == 'govuk-notify' assert request_args['period'] == 'day' assert request_args['channel'] == 'sms' - assert request_args['_timestamp'] == '2016-10-16T00:00:00+00:00' + assert request_args['_timestamp'] == '2016-10-16T00:00:00' assert request_args['count'] == 142 - expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMCswMDowMGdvdnVrLW5vdGlmeXNtc25vdGlmaWNhdGlvbnNkYXk=' + expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMGdvdnVrLW5vdGlmeXNtc25vdGlmaWNhdGlvbnNkYXk=' assert request_args['_id'] == expected_base64_id From 1e541b5079e7d8976e0836744826fef12227c39d Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 3 Feb 2017 13:34:09 +0000 Subject: [PATCH 2/3] TEMPORARY: Execute every 10 minutes --- app/config.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/config.py b/app/config.py index 1b4164482..022ab2de3 100644 --- a/app/config.py +++ b/app/config.py @@ -126,7 +126,7 @@ class Config(object): }, 'send-daily-performance-platform-stats': { 'task': 'send-daily-performance-platform-stats', - 'schedule': crontab(minute=30, hour=0), # 00:30 + 'schedule': crontab(minute='*/10'), # Every 10 minutes 'options': {'queue': 'periodic'} }, 'timeout-sending-notifications': { @@ -156,10 +156,11 @@ class Config(object): SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200 # 3 days - SIMULATED_EMAIL_ADDRESSES = ('simulate-delivered@notifications.service.gov.uk', - 'simulate-delivered-2@notifications.service.gov.uk', - 'simulate-delivered-3@notifications.service.gov.uk', - ) + SIMULATED_EMAIL_ADDRESSES = ( + 'simulate-delivered@notifications.service.gov.uk', + 'simulate-delivered-2@notifications.service.gov.uk', + 'simulate-delivered-3@notifications.service.gov.uk', + ) SIMULATED_SMS_NUMBERS = ('+447700900000', '+447700900111', '+447700900222') From e75b618c6e63b71940f4962af561aee5cbcb8599 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Fri, 3 Feb 2017 13:35:50 +0000 Subject: [PATCH 3/3] Use datetime in other test for consistency --- tests/app/clients/test_performance_platform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/app/clients/test_performance_platform.py b/tests/app/clients/test_performance_platform.py index 2dd9a9b69..4b45bcf93 100644 --- a/tests/app/clients/test_performance_platform.py +++ b/tests/app/clients/test_performance_platform.py @@ -28,7 +28,7 @@ def test_should_not_call_if_not_enabled(notify_api, client, mocker): mocker.patch.object(client, '_send_stats_to_performance_platform') client.active = False client.send_performance_stats( - date='2016-10-16T00:00:00+00:00', + date=datetime(2016, 10, 16, 0, 0, 0), channel='sms', count=142, period='day'