mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
Format date correctly for upload + refactor tests
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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -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