mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-21 14:59:26 -04:00
Remove the use of schedule_for in post_notifications.
Years ago we started to implement a way to schedule a notification. We hit a problem but we never came up with a good solution and the feature never made it back to the top of the priority list. This PR removes the code for scheduled_for. There will be another PR to drop the scheduled_notifications table and remove the schedule_notifications service permission Unfortunately, I don't think we can remove the `scheduled_for` attribute from the notification.serialized method because out clients might fail if something is missing. For now I have left it in but defaulted the value to None.
This commit is contained in:
@@ -70,7 +70,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:15:00.000000Z',
|
||||
'scheduled_for': None,
|
||||
'postage': None,
|
||||
}
|
||||
|
||||
@@ -166,26 +166,6 @@ def test_get_notification_by_id_returns_created_by_name_if_notification_created_
|
||||
assert json_response['created_by_name'] == 'Test User'
|
||||
|
||||
|
||||
def test_get_notifications_returns_scheduled_for(client, sample_template):
|
||||
sample_notification_with_reference = create_notification(template=sample_template,
|
||||
client_reference='some-client-reference',
|
||||
scheduled_for='2017-05-23 17:15')
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_notification_with_reference.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?reference={}'.format(sample_notification_with_reference.client_reference),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers['Content-type'] == 'application/json'
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
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:15:00.000000Z"
|
||||
|
||||
|
||||
def test_get_notification_by_reference_nonexistent_reference_returns_no_notifications(client, sample_service):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
response = client.get(
|
||||
|
||||
@@ -3,16 +3,13 @@ from unittest import mock
|
||||
from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
from boto.exception import SQSError
|
||||
|
||||
from app.dao import templates_dao
|
||||
from app.dao.service_sms_sender_dao import dao_update_service_sms_sender
|
||||
from app.models import (
|
||||
ScheduledNotification,
|
||||
EMAIL_TYPE,
|
||||
NOTIFICATION_CREATED,
|
||||
SCHEDULE_NOTIFICATIONS,
|
||||
SMS_TYPE,
|
||||
INTERNATIONAL_SMS_TYPE
|
||||
)
|
||||
@@ -712,56 +709,6 @@ def test_post_sms_should_persist_supplied_sms_number(client, sample_template_wit
|
||||
assert mocked.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type, key_send_to, send_to",
|
||||
[("sms", "phone_number", "07700 900 855"),
|
||||
("email", "email_address", "sample@email.com")])
|
||||
@freeze_time("2017-05-14 14:00:00")
|
||||
def test_post_notification_with_scheduled_for(
|
||||
client, notify_db_session, notification_type, key_send_to, send_to
|
||||
):
|
||||
service = create_service(service_name=str(uuid.uuid4()),
|
||||
service_permissions=[EMAIL_TYPE, SMS_TYPE, SCHEDULE_NOTIFICATIONS])
|
||||
template = create_template(service=service, template_type=notification_type)
|
||||
data = {
|
||||
key_send_to: send_to,
|
||||
'template_id': str(template.id) if notification_type == EMAIL_TYPE else str(template.id),
|
||||
'scheduled_for': '2017-05-14 14:15'
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post('/v2/notifications/{}'.format(notification_type),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 201
|
||||
resp_json = json.loads(response.get_data(as_text=True))
|
||||
scheduled_notification = ScheduledNotification.query.filter_by(notification_id=resp_json["id"]).all()
|
||||
assert len(scheduled_notification) == 1
|
||||
assert resp_json["id"] == str(scheduled_notification[0].notification_id)
|
||||
assert resp_json["scheduled_for"] == '2017-05-14 14:15'
|
||||
|
||||
|
||||
@pytest.mark.parametrize("notification_type, key_send_to, send_to",
|
||||
[("sms", "phone_number", "07700 900 855"),
|
||||
("email", "email_address", "sample@email.com")])
|
||||
@freeze_time("2017-05-14 14:00:00")
|
||||
def test_post_notification_raises_bad_request_if_service_not_invited_to_schedule(
|
||||
client, sample_template, sample_email_template, notification_type, key_send_to, send_to):
|
||||
data = {
|
||||
key_send_to: send_to,
|
||||
'template_id': str(sample_email_template.id) if notification_type == EMAIL_TYPE else str(sample_template.id),
|
||||
'scheduled_for': '2017-05-14 14:15'
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
|
||||
response = client.post('/v2/notifications/{}'.format(notification_type),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
assert response.status_code == 400
|
||||
error_json = json.loads(response.get_data(as_text=True))
|
||||
assert error_json['errors'] == [
|
||||
{"error": "BadRequestError", "message": 'Cannot schedule notifications (this feature is invite-only)'}]
|
||||
|
||||
|
||||
def test_post_notification_raises_bad_request_if_not_valid_notification_type(client, sample_service):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
response = client.post(
|
||||
|
||||
Reference in New Issue
Block a user