mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 14:31:57 -05:00
Merge pull request #815 from alphagov/fix-perf-platform-stats-job
Fix perf platform stats job
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from requests import request
|
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
@@ -30,7 +29,7 @@ class PerformancePlatformClient:
|
|||||||
def send_performance_stats(self, date, channel, count, period):
|
def send_performance_stats(self, date, channel, count, period):
|
||||||
if self.active:
|
if self.active:
|
||||||
payload = {
|
payload = {
|
||||||
'_timestamp': str(date),
|
'_timestamp': date.isoformat(),
|
||||||
'service': 'govuk-notify',
|
'service': 'govuk-notify',
|
||||||
'channel': channel,
|
'channel': channel,
|
||||||
'count': count,
|
'count': count,
|
||||||
@@ -62,10 +61,9 @@ class PerformancePlatformClient:
|
|||||||
'Content-Type': "application/json",
|
'Content-Type': "application/json",
|
||||||
'Authorization': 'Bearer {}'.format(self.bearer_token)
|
'Authorization': 'Bearer {}'.format(self.bearer_token)
|
||||||
}
|
}
|
||||||
resp = request(
|
resp = requests.post(
|
||||||
"POST",
|
|
||||||
self.performance_platform_url,
|
self.performance_platform_url,
|
||||||
data=json.dumps(payload),
|
json=payload,
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class Config(object):
|
|||||||
},
|
},
|
||||||
'send-daily-performance-platform-stats': {
|
'send-daily-performance-platform-stats': {
|
||||||
'task': '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'}
|
'options': {'queue': 'periodic'}
|
||||||
},
|
},
|
||||||
'timeout-sending-notifications': {
|
'timeout-sending-notifications': {
|
||||||
@@ -156,10 +156,11 @@ class Config(object):
|
|||||||
|
|
||||||
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200 # 3 days
|
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200 # 3 days
|
||||||
|
|
||||||
SIMULATED_EMAIL_ADDRESSES = ('simulate-delivered@notifications.service.gov.uk',
|
SIMULATED_EMAIL_ADDRESSES = (
|
||||||
'simulate-delivered-2@notifications.service.gov.uk',
|
'simulate-delivered@notifications.service.gov.uk',
|
||||||
'simulate-delivered-3@notifications.service.gov.uk',
|
'simulate-delivered-2@notifications.service.gov.uk',
|
||||||
)
|
'simulate-delivered-3@notifications.service.gov.uk',
|
||||||
|
)
|
||||||
|
|
||||||
SIMULATED_SMS_NUMBERS = ('+447700900000', '+447700900111', '+447700900222')
|
SIMULATED_SMS_NUMBERS = ('+447700900000', '+447700900111', '+447700900222')
|
||||||
|
|
||||||
|
|||||||
@@ -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')
|
mocker.patch.object(client, '_send_stats_to_performance_platform')
|
||||||
client.active = False
|
client.active = False
|
||||||
client.send_performance_stats(
|
client.send_performance_stats(
|
||||||
date='2016-10-16T00:00:00+00:00',
|
date=datetime(2016, 10, 16, 0, 0, 0),
|
||||||
channel='sms',
|
channel='sms',
|
||||||
count=142,
|
count=142,
|
||||||
period='day'
|
period='day'
|
||||||
@@ -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):
|
def test_should_call_if_enabled(notify_api, client, mocker):
|
||||||
mocker.patch.object(client, '_send_stats_to_performance_platform')
|
mocker.patch.object(client, '_send_stats_to_performance_platform')
|
||||||
client.send_performance_stats(
|
client.send_performance_stats(
|
||||||
date='2016-10-16T00:00:00+00:00',
|
date=datetime(2016, 10, 16, 0, 0, 0),
|
||||||
channel='sms',
|
channel='sms',
|
||||||
count=142,
|
count=142,
|
||||||
period='day'
|
period='day'
|
||||||
@@ -57,7 +57,7 @@ def test_send_platform_stats_creates_correct_call(notify_api, client):
|
|||||||
status_code=200
|
status_code=200
|
||||||
)
|
)
|
||||||
client.send_performance_stats(
|
client.send_performance_stats(
|
||||||
date='2016-10-16T00:00:00+00:00',
|
date=datetime(2016, 10, 16, 0, 0, 0),
|
||||||
channel='sms',
|
channel='sms',
|
||||||
count=142,
|
count=142,
|
||||||
period='day'
|
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['service'] == 'govuk-notify'
|
||||||
assert request_args['period'] == 'day'
|
assert request_args['period'] == 'day'
|
||||||
assert request_args['channel'] == 'sms'
|
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
|
assert request_args['count'] == 142
|
||||||
expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMCswMDowMGdvdnVrLW5vdGlmeXNtc25vdGlmaWNhdGlvbnNkYXk='
|
expected_base64_id = 'MjAxNi0xMC0xNlQwMDowMDowMGdvdnVrLW5vdGlmeXNtc25vdGlmaWNhdGlvbnNkYXk='
|
||||||
assert request_args['_id'] == expected_base64_id
|
assert request_args['_id'] == expected_base64_id
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user