mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-05 00:30:04 -04:00
Merge pull request #1241 from alphagov/letter-received
Letters are accepted, not created or sending
This commit is contained in:
@@ -198,7 +198,10 @@ def test_add_monthly_billing_for_multiple_months_populate_correctly(
|
||||
create_or_update_monthly_billing(service_id=sample_template.service_id, billing_month=FEB_2016_MONTH_START)
|
||||
create_or_update_monthly_billing(service_id=sample_template.service_id, billing_month=MAR_2016_MONTH_START)
|
||||
|
||||
monthly_billing = MonthlyBilling.query.order_by(MonthlyBilling.notification_type).all()
|
||||
monthly_billing = MonthlyBilling.query.order_by(
|
||||
MonthlyBilling.notification_type,
|
||||
MonthlyBilling.start_date
|
||||
).all()
|
||||
|
||||
assert len(monthly_billing) == 4
|
||||
_assert_monthly_billing(
|
||||
|
||||
@@ -10,10 +10,12 @@ from app.models import (
|
||||
MOBILE_TYPE,
|
||||
EMAIL_TYPE,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_PENDING,
|
||||
NOTIFICATION_FAILED,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_STATUS_TYPES_FAILED
|
||||
NOTIFICATION_STATUS_TYPES_FAILED,
|
||||
NOTIFICATION_STATUS_LETTER_ACCEPTED
|
||||
)
|
||||
from tests.app.conftest import (
|
||||
sample_template as create_sample_template,
|
||||
@@ -55,8 +57,9 @@ def test_should_not_build_service_whitelist_from_invalid_contact(recipient_type,
|
||||
@pytest.mark.parametrize('initial_statuses, expected_statuses', [
|
||||
# passing in single statuses as strings
|
||||
(NOTIFICATION_FAILED, NOTIFICATION_STATUS_TYPES_FAILED),
|
||||
(NOTIFICATION_CREATED, NOTIFICATION_CREATED),
|
||||
(NOTIFICATION_TECHNICAL_FAILURE, NOTIFICATION_TECHNICAL_FAILURE),
|
||||
(NOTIFICATION_STATUS_LETTER_ACCEPTED, [NOTIFICATION_SENDING, NOTIFICATION_CREATED]),
|
||||
(NOTIFICATION_CREATED, [NOTIFICATION_CREATED]),
|
||||
(NOTIFICATION_TECHNICAL_FAILURE, [NOTIFICATION_TECHNICAL_FAILURE]),
|
||||
# passing in lists containing single statuses
|
||||
([NOTIFICATION_FAILED], NOTIFICATION_STATUS_TYPES_FAILED),
|
||||
([NOTIFICATION_CREATED], [NOTIFICATION_CREATED]),
|
||||
@@ -65,13 +68,17 @@ def test_should_not_build_service_whitelist_from_invalid_contact(recipient_type,
|
||||
([NOTIFICATION_FAILED, NOTIFICATION_CREATED], NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_CREATED]),
|
||||
([NOTIFICATION_CREATED, NOTIFICATION_PENDING], [NOTIFICATION_CREATED, NOTIFICATION_PENDING]),
|
||||
([NOTIFICATION_CREATED, NOTIFICATION_TECHNICAL_FAILURE], [NOTIFICATION_CREATED, NOTIFICATION_TECHNICAL_FAILURE]),
|
||||
(
|
||||
[NOTIFICATION_FAILED, NOTIFICATION_STATUS_LETTER_ACCEPTED],
|
||||
NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_SENDING, NOTIFICATION_CREATED]
|
||||
),
|
||||
# checking we don't end up with duplicates
|
||||
(
|
||||
[NOTIFICATION_FAILED, NOTIFICATION_CREATED, NOTIFICATION_TECHNICAL_FAILURE],
|
||||
NOTIFICATION_STATUS_TYPES_FAILED + [NOTIFICATION_CREATED]
|
||||
),
|
||||
])
|
||||
def test_status_conversion_handles_failed_statuses(initial_statuses, expected_statuses):
|
||||
def test_status_conversion(initial_statuses, expected_statuses):
|
||||
converted_statuses = Notification.substitute_status(initial_statuses)
|
||||
assert len(converted_statuses) == len(expected_statuses)
|
||||
assert set(converted_statuses) == set(expected_statuses)
|
||||
@@ -116,8 +123,9 @@ def test_notification_for_csv_returns_correct_job_row_number(notify_db, notify_d
|
||||
('sms', 'temporary-failure', 'Phone not accepting messages right now'),
|
||||
('sms', 'permanent-failure', 'Phone number doesn’t exist'),
|
||||
('sms', 'sent', 'Sent internationally'),
|
||||
('letter', 'permanent-failure', 'Permanent failure'),
|
||||
('letter', 'delivered', 'Delivered')
|
||||
('letter', 'created', 'Accepted'),
|
||||
('letter', 'sending', 'Accepted'),
|
||||
('letter', 'technical-failure', 'Technical failure')
|
||||
])
|
||||
def test_notification_for_csv_returns_formatted_status(
|
||||
notify_db,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
import pytest
|
||||
from flask import json
|
||||
from flask import json, url_for
|
||||
|
||||
from app import DATETIME_FORMAT
|
||||
from tests import create_authorization_header
|
||||
@@ -23,13 +23,20 @@ from tests.app.conftest import (
|
||||
def test_get_notification_by_id_returns_200(
|
||||
client, billable_units, provider, sample_template
|
||||
):
|
||||
sample_notification = create_notification(template=sample_template, billable_units=billable_units, sent_by=provider,
|
||||
scheduled_for="2017-05-12 15:15"
|
||||
)
|
||||
sample_notification = create_notification(
|
||||
template=sample_template,
|
||||
billable_units=billable_units,
|
||||
sent_by=provider,
|
||||
scheduled_for="2017-05-12 15:15"
|
||||
)
|
||||
|
||||
another = create_notification(
|
||||
template=sample_template,
|
||||
billable_units=billable_units,
|
||||
sent_by=provider,
|
||||
scheduled_for="2017-06-12 15:15"
|
||||
)
|
||||
|
||||
another = create_notification(template=sample_template, billable_units=billable_units, sent_by=provider,
|
||||
scheduled_for="2017-06-12 15:15"
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(sample_notification.id),
|
||||
@@ -75,9 +82,10 @@ def test_get_notification_by_id_returns_200(
|
||||
def test_get_notification_by_id_with_placeholders_returns_200(
|
||||
client, sample_email_template_with_placeholders
|
||||
):
|
||||
sample_notification = create_notification(template=sample_email_template_with_placeholders,
|
||||
personalisation={"name": "Bob"}
|
||||
)
|
||||
sample_notification = create_notification(
|
||||
template=sample_email_template_with_placeholders,
|
||||
personalisation={"name": "Bob"}
|
||||
)
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
@@ -385,7 +393,7 @@ def test_get_all_notifications_filter_by_status_invalid_status(client, sample_no
|
||||
assert json_response['status_code'] == 400
|
||||
assert len(json_response['errors']) == 1
|
||||
assert json_response['errors'][0]['message'] == "status elephant is not one of [created, sending, sent, " \
|
||||
"delivered, pending, failed, technical-failure, temporary-failure, permanent-failure]"
|
||||
"delivered, pending, failed, technical-failure, temporary-failure, permanent-failure, accepted]"
|
||||
|
||||
|
||||
def test_get_all_notifications_filter_by_multiple_statuses(client, sample_template):
|
||||
@@ -549,3 +557,40 @@ def test_get_all_notifications_filter_multiple_query_parameters(client, sample_e
|
||||
assert len(json_response['notifications']) == 1
|
||||
|
||||
assert json_response['notifications'][0]['id'] == str(older_notification.id)
|
||||
|
||||
|
||||
def test_get_all_notifications_renames_letter_statuses(
|
||||
client,
|
||||
sample_letter_notification,
|
||||
sample_notification,
|
||||
sample_email_notification,
|
||||
):
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_notifications'),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
assert response.status_code == 200
|
||||
|
||||
for noti in json_response['notifications']:
|
||||
if noti['type'] == 'sms' or noti['type'] == 'email':
|
||||
assert noti['status'] == 'created'
|
||||
elif noti['type'] == 'letter':
|
||||
assert noti['status'] == 'accepted'
|
||||
else:
|
||||
pytest.fail()
|
||||
|
||||
|
||||
def test_get_notifications_renames_letter_statuses(client, sample_letter_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_notification_by_id', id=sample_letter_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
)
|
||||
|
||||
json_response = json.loads(response.get_data(as_text=True))
|
||||
assert response.status_code == 200
|
||||
|
||||
assert json_response['status'] == 'accepted'
|
||||
|
||||
@@ -26,7 +26,7 @@ def test_get_notifications_request_invalid_statuses(
|
||||
):
|
||||
partial_error_status = "is not one of " \
|
||||
"[created, sending, sent, delivered, pending, failed, " \
|
||||
"technical-failure, temporary-failure, permanent-failure]"
|
||||
"technical-failure, temporary-failure, permanent-failure, accepted]"
|
||||
|
||||
with pytest.raises(ValidationError) as e:
|
||||
validate({'status': invalid_statuses + valid_statuses}, get_notifications_request)
|
||||
@@ -73,7 +73,7 @@ def test_get_notifications_request_invalid_statuses_and_template_types():
|
||||
error_messages = [error['message'] for error in errors]
|
||||
for invalid_status in ["elephant", "giraffe"]:
|
||||
assert "status {} is not one of [created, sending, sent, delivered, " \
|
||||
"pending, failed, technical-failure, temporary-failure, permanent-failure]".format(
|
||||
"pending, failed, technical-failure, temporary-failure, permanent-failure, accepted]".format(
|
||||
invalid_status
|
||||
) in error_messages
|
||||
|
||||
|
||||
Reference in New Issue
Block a user