Update dateformat for scheduled_for to include minutes.

This commit is contained in:
Rebecca Law
2017-05-22 14:15:35 +01:00
parent 3a3161ecc4
commit 751abb4b99
5 changed files with 9 additions and 9 deletions

View File

@@ -128,7 +128,7 @@ def simulated_recipient(to_address, notification_type):
def persist_scheduled_notification(notification_id, scheduled_for): def persist_scheduled_notification(notification_id, scheduled_for):
scheduled_datetime = convert_bst_to_utc(datetime.strptime(scheduled_for, "%Y-%m-%d %H")) scheduled_datetime = convert_bst_to_utc(datetime.strptime(scheduled_for, "%Y-%m-%d %H:%M"))
scheduled_notification = ScheduledNotification(notification_id=notification_id, scheduled_notification = ScheduledNotification(notification_id=notification_id,
scheduled_for=scheduled_datetime) scheduled_for=scheduled_datetime)
dao_created_scheduled_notification(scheduled_notification) dao_created_scheduled_notification(scheduled_notification)

View File

@@ -25,10 +25,10 @@ def validate(json_to_validate, schema):
def validate_schema_date_with_hour(instance): def validate_schema_date_with_hour(instance):
if isinstance(instance, str): if isinstance(instance, str):
try: try:
datetime.strptime(instance, "%Y-%m-%d %H") datetime.strptime(instance, "%Y-%m-%d %H:%M")
except ValueError as e: except ValueError as e:
raise ValidationError("datetime format is invalid. Use the format: " raise ValidationError("datetime format is invalid. Use the format: "
"YYYY-MM-DD HH, for example 2017-05-30 13") "YYYY-MM-DD HH:MI, for example 2017-05-30 13:15")
return True return True
validator = Draft4Validator(schema, format_checker=format_checker) validator = Draft4Validator(schema, format_checker=format_checker)

View File

@@ -343,8 +343,8 @@ def test_persist_notification_with_international_info_does_not_store_for_email(
def test_persist_scheduled_notification(sample_notification): def test_persist_scheduled_notification(sample_notification):
persist_scheduled_notification(sample_notification.id, '2017-05-12 14') persist_scheduled_notification(sample_notification.id, '2017-05-12 14:15')
scheduled_notification = ScheduledNotification.query.all() scheduled_notification = ScheduledNotification.query.all()
assert len(scheduled_notification) == 1 assert len(scheduled_notification) == 1
assert scheduled_notification[0].notification_id == sample_notification.id assert scheduled_notification[0].notification_id == sample_notification.id
assert scheduled_notification[0].scheduled_for == datetime.datetime(2017, 5, 12, 13, 0) assert scheduled_notification[0].scheduled_for == datetime.datetime(2017, 5, 12, 13, 15)

View File

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

View File

@@ -358,7 +358,7 @@ def test_post_notification_with_scheduled_for(client, sample_template, sample_em
data = { data = {
key_send_to: send_to, key_send_to: send_to,
'template_id': str(sample_email_template.id) if notification_type == 'email' else str(sample_template.id), 'template_id': str(sample_email_template.id) if notification_type == 'email' else str(sample_template.id),
'scheduled_for': '2017-05-14 14' 'scheduled_for': '2017-05-14 14:15'
} }
auth_header = create_authorization_header(service_id=sample_template.service_id) 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() scheduled_notification = ScheduledNotification.query.all()
assert len(scheduled_notification) == 1 assert len(scheduled_notification) == 1
assert resp_json["id"] == str(scheduled_notification[0].notification_id) assert resp_json["id"] == str(scheduled_notification[0].notification_id)
assert resp_json["scheduled_for"] == '2017-05-14 14' assert resp_json["scheduled_for"] == '2017-05-14 14:15'