Changed the scheduled_for datetime to only send and hour of a day to send.

Also expect the date being passed in is BST. The date is converted to UTC before saving. And converted to BST when returning a notification.
This commit is contained in:
Rebecca Law
2017-05-17 15:06:15 +01:00
parent 5f8338dd80
commit 973cc2c4c9
14 changed files with 64 additions and 46 deletions

View File

@@ -20,12 +20,12 @@ def test_get_notification_by_id_returns_200(
):
sample_notification = create_sample_notification(
notify_db, notify_db_session, billable_units=billable_units, sent_by=provider,
scheduled_for="2017-05-12 14:00:00"
scheduled_for="2017-05-12 14"
)
another = create_sample_notification(
notify_db, notify_db_session, billable_units=billable_units, sent_by=provider,
scheduled_for="2017-06-12 14:00:00"
scheduled_for="2017-06-12 14"
)
auth_header = create_authorization_header(service_id=sample_notification.service_id)
response = client.get(
@@ -63,7 +63,7 @@ def test_get_notification_by_id_returns_200(
"subject": None,
'sent_at': sample_notification.sent_at,
'completed_at': sample_notification.completed_at(),
'scheduled_for': '2017-05-12T14:00:00.000000Z'
'scheduled_for': '2017-05-12 14'
}
assert json_response == expected_response
@@ -139,7 +139,7 @@ def test_get_notification_by_reference_returns_200(client, notify_db, notify_db_
def test_get_notifications_returns_scheduled_for(client, notify_db, notify_db_session):
sample_notification_with_reference = create_sample_notification(
notify_db, notify_db_session, client_reference='some-client-reference', scheduled_for='2017-05-23 16:00:00')
notify_db, notify_db_session, client_reference='some-client-reference', scheduled_for='2017-05-23 16')
auth_header = create_authorization_header(service_id=sample_notification_with_reference.service_id)
response = client.get(
@@ -153,7 +153,7 @@ def test_get_notifications_returns_scheduled_for(client, notify_db, notify_db_se
assert len(json_response['notifications']) == 1
assert json_response['notifications'][0]['id'] == str(sample_notification_with_reference.id)
assert json_response['notifications'][0]['scheduled_for'] == "2017-05-23T16:00:00.000000Z"
assert json_response['notifications'][0]['scheduled_for'] == "2017-05-23 16"
def test_get_notification_by_reference_nonexistent_reference_returns_no_notifications(client, sample_service):

View File

@@ -360,7 +360,7 @@ def test_get_notifications_response_with_email_and_phone_number():
def test_post_schema_valid_scheduled_for(schema):
j = {"template_id": str(uuid.uuid4()),
"email_address": "joe@gmail.com",
"scheduled_for": "2017-05-12 13:00:00"}
"scheduled_for": "2017-05-12 13"}
if schema == post_email_request_schema:
j.update({"email_address": "joe@gmail.com"})
else:
@@ -369,7 +369,7 @@ def test_post_schema_valid_scheduled_for(schema):
@pytest.mark.parametrize("invalid_datetime",
["2017-05-12 13:00", "13:00:00 2017-01-01"])
["2017-05-12 13:00:00", "13:00:00 2017-01-01"])
@pytest.mark.parametrize("schema",
[post_email_request_schema, post_sms_request_schema])
def test_post_email_schema_invalid_scheduled_for(invalid_datetime, schema):
@@ -385,4 +385,4 @@ def test_post_email_schema_invalid_scheduled_for(invalid_datetime, schema):
assert error['status_code'] == 400
assert error['errors'] == [{'error': 'ValidationError',
'message': "scheduled_for datetime format is invalid. Use the format: "
"YYYY-MM-DD HH:MM:SS, for example 2017-05-30 13:00:00"}]
"YYYY-MM-DD HH, for example 2017-05-30 13"}]

View File

@@ -1,8 +1,8 @@
import uuid
import pytest
from flask import json
from app import DATETIME_FORMAT
from app.models import Notification, ScheduledNotification
from app.v2.errors import RateLimitError
from tests import create_authorization_header
@@ -358,7 +358,7 @@ def test_post_notification_with_scheduled_for(client, sample_template, sample_em
data = {
key_send_to: send_to,
'template_id': str(sample_email_template.id) if notification_type == 'email' else str(sample_template.id),
'scheduled_for': '2017-05-14 15:00:00'
'scheduled_for': '2017-05-14 14'
}
auth_header = create_authorization_header(service_id=sample_template.service_id)
@@ -370,4 +370,4 @@ def test_post_notification_with_scheduled_for(client, sample_template, sample_em
scheduled_notification = ScheduledNotification.query.all()
assert len(scheduled_notification) == 1
assert resp_json["id"] == str(scheduled_notification[0].notification_id)
assert resp_json["scheduled_for"] == scheduled_notification[0].scheduled_for.strftime(DATETIME_FORMAT)
assert resp_json["scheduled_for"] == '2017-05-14 14'