mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-07 04:48:26 -04:00
Merge pull request #2943 from alphagov/international-postage
Set international postage and international flag for international letters
This commit is contained in:
@@ -18,6 +18,7 @@ from app.dao.services_dao import dao_update_service
|
||||
from app.dao.api_key_dao import save_model_api_key
|
||||
from app.errors import InvalidRequest
|
||||
from app.models import Template
|
||||
from app.service.send_notification import send_one_off_notification
|
||||
from app.v2.errors import RateLimitError
|
||||
|
||||
from tests import create_authorization_header
|
||||
@@ -1214,3 +1215,29 @@ def test_post_notification_should_set_reply_to_text(client, sample_service, mock
|
||||
notifications = Notification.query.all()
|
||||
assert len(notifications) == 1
|
||||
assert notifications[0].reply_to_text == expected_reply_to
|
||||
|
||||
|
||||
@pytest.mark.parametrize('last_line_of_address, expected_postage, expected_international',
|
||||
[('France', 'europe', True),
|
||||
('Canada', 'rest-of-world', True),
|
||||
('SW1 1AA', 'second', False)])
|
||||
def test_send_notification_should_send_international_letters(
|
||||
sample_letter_template, mocker, last_line_of_address, expected_postage, expected_international
|
||||
):
|
||||
deliver_mock = mocker.patch('app.celery.tasks.letters_pdf_tasks.get_pdf_for_templated_letter.apply_async')
|
||||
data = {
|
||||
'template_id': sample_letter_template.id,
|
||||
'personalisation': {
|
||||
'address_line_1': 'Jane',
|
||||
'address_line_2': 'Rue Vert',
|
||||
'address_line_3': last_line_of_address
|
||||
},
|
||||
'to': 'Jane',
|
||||
'created_by': sample_letter_template.service.created_by_id
|
||||
}
|
||||
|
||||
notification_id = send_one_off_notification(sample_letter_template.service_id, data)
|
||||
assert deliver_mock.called
|
||||
notification = Notification.query.get(notification_id['id'])
|
||||
assert notification.postage == expected_postage
|
||||
assert notification.international == expected_international
|
||||
|
||||
@@ -489,8 +489,7 @@ def test_persist_email_notification_stores_normalised_email(
|
||||
[
|
||||
("second", "first", "second"),
|
||||
("first", "first", "first"),
|
||||
("first", "second", "first"),
|
||||
(None, "second", "second")
|
||||
("first", "second", "first")
|
||||
]
|
||||
)
|
||||
def test_persist_letter_notification_finds_correct_postage(
|
||||
@@ -506,7 +505,6 @@ def test_persist_letter_notification_finds_correct_postage(
|
||||
persist_notification(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
template_postage=template.postage,
|
||||
recipient="Jane Doe, 10 Downing Street, London",
|
||||
service=sample_service_full_permissions,
|
||||
personalisation=None,
|
||||
@@ -536,8 +534,26 @@ def test_persist_notification_with_billable_units_stores_correct_info(
|
||||
api_key_id=None,
|
||||
key_type="normal",
|
||||
billable_units=3,
|
||||
template_postage=template.postage
|
||||
)
|
||||
persisted_notification = Notification.query.all()[0]
|
||||
|
||||
assert persisted_notification.billable_units == 3
|
||||
|
||||
|
||||
@pytest.mark.parametrize('postage', ['europe', 'rest-of-world'])
|
||||
def test_persist_notification_for_international_letter(sample_letter_template, postage):
|
||||
notification = persist_notification(
|
||||
template_id=sample_letter_template.id,
|
||||
template_version=sample_letter_template.version,
|
||||
recipient="123 Main Street",
|
||||
service=sample_letter_template.service,
|
||||
personalisation=None,
|
||||
notification_type=sample_letter_template.template_type,
|
||||
api_key_id=None,
|
||||
key_type="normal",
|
||||
billable_units=3,
|
||||
postage=postage,
|
||||
)
|
||||
persisted_notification = Notification.query.get(notification.id)
|
||||
assert persisted_notification.postage == postage
|
||||
assert persisted_notification.international
|
||||
|
||||
@@ -5,7 +5,12 @@ from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
||||
|
||||
import app
|
||||
from app.dao import templates_dao
|
||||
from app.models import SMS_TYPE, EMAIL_TYPE, LETTER_TYPE
|
||||
from app.models import (
|
||||
EMAIL_TYPE,
|
||||
INTERNATIONAL_LETTERS,
|
||||
LETTER_TYPE,
|
||||
SMS_TYPE,
|
||||
)
|
||||
from app.notifications.process_notifications import create_content_for_notification
|
||||
from app.notifications.validators import (
|
||||
check_content_char_count,
|
||||
@@ -20,6 +25,7 @@ from app.notifications.validators import (
|
||||
check_service_letter_contact_id,
|
||||
check_reply_to,
|
||||
service_can_send_to_recipient,
|
||||
validate_address,
|
||||
validate_and_format_recipient,
|
||||
validate_template,
|
||||
)
|
||||
@@ -619,3 +625,19 @@ def test_check_if_service_can_send_files_by_email_passes_if_contact_link_set(sam
|
||||
service_contact_link=sample_service.contact_link,
|
||||
service_id=sample_service.id
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('key, address_line_3, expected_postage',
|
||||
[('address_line_3', 'SW1 1AA', None),
|
||||
('address_line_5', 'CANADA', 'rest-of-world'),
|
||||
('address_line_3', 'GERMANY', 'europe')
|
||||
])
|
||||
def test_validate_address(notify_db_session, key, address_line_3, expected_postage):
|
||||
service = create_service(service_permissions=[LETTER_TYPE, INTERNATIONAL_LETTERS])
|
||||
data = {
|
||||
'address_line_1': 'Prince Harry',
|
||||
'address_line_2': 'Toronto',
|
||||
key: address_line_3,
|
||||
}
|
||||
postage = validate_address(service, data)
|
||||
assert postage == expected_postage
|
||||
|
||||
Reference in New Issue
Block a user