Format date correctly for upload + refactor tests

This commit is contained in:
Imdad Ahad
2017-02-03 13:32:19 +00:00
parent 53b6cdcfab
commit 99cc2f5897
2 changed files with 8 additions and 10 deletions

View File

@@ -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
)

View File

@@ -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