mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 05:28:49 -04:00
progress on removing postage
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
from app.models import LETTER_TYPE, NOTIFICATION_CREATED, Notification
|
||||
from app.notifications.process_letter_notifications import (
|
||||
create_letter_notification,
|
||||
)
|
||||
from app.serialised_models import SerialisedTemplate
|
||||
|
||||
|
||||
def test_create_letter_notification_creates_notification(sample_letter_template, sample_api_key):
|
||||
data = {
|
||||
'personalisation': {
|
||||
'address_line_1': 'The Queen',
|
||||
'address_line_2': 'Buckingham Palace',
|
||||
'postcode': 'SW1 1AA',
|
||||
}
|
||||
}
|
||||
|
||||
template = SerialisedTemplate.from_id_and_service_id(
|
||||
sample_letter_template.id, sample_letter_template.service_id
|
||||
)
|
||||
|
||||
notification = create_letter_notification(
|
||||
data,
|
||||
template,
|
||||
sample_letter_template.service,
|
||||
sample_api_key,
|
||||
NOTIFICATION_CREATED,
|
||||
)
|
||||
|
||||
assert notification == Notification.query.one()
|
||||
assert notification.job is None
|
||||
assert notification.status == NOTIFICATION_CREATED
|
||||
assert notification.template_id == sample_letter_template.id
|
||||
assert notification.template_version == sample_letter_template.version
|
||||
assert notification.api_key == sample_api_key
|
||||
assert notification.notification_type == LETTER_TYPE
|
||||
assert notification.key_type == sample_api_key.key_type
|
||||
assert notification.reference is not None
|
||||
assert notification.client_reference is None
|
||||
assert notification.postage == 'second'
|
||||
|
||||
|
||||
def test_create_letter_notification_sets_reference(sample_letter_template, sample_api_key):
|
||||
data = {
|
||||
'personalisation': {
|
||||
'address_line_1': 'The Queen',
|
||||
'address_line_2': 'Buckingham Palace',
|
||||
'postcode': 'SW1 1AA',
|
||||
},
|
||||
'reference': 'foo'
|
||||
}
|
||||
|
||||
template = SerialisedTemplate.from_id_and_service_id(
|
||||
sample_letter_template.id, sample_letter_template.service_id
|
||||
)
|
||||
|
||||
notification = create_letter_notification(
|
||||
data,
|
||||
template,
|
||||
sample_letter_template.service,
|
||||
sample_api_key,
|
||||
NOTIFICATION_CREATED,
|
||||
)
|
||||
|
||||
assert notification.client_reference == 'foo'
|
||||
|
||||
|
||||
def test_create_letter_notification_sets_billable_units(sample_letter_template, sample_api_key):
|
||||
data = {
|
||||
'personalisation': {
|
||||
'address_line_1': 'The Queen',
|
||||
'address_line_2': 'Buckingham Palace',
|
||||
'postcode': 'SW1 1AA',
|
||||
},
|
||||
}
|
||||
|
||||
template = SerialisedTemplate.from_id_and_service_id(
|
||||
sample_letter_template.id, sample_letter_template.service_id
|
||||
)
|
||||
|
||||
notification = create_letter_notification(
|
||||
data,
|
||||
template,
|
||||
sample_letter_template.service,
|
||||
sample_api_key,
|
||||
NOTIFICATION_CREATED,
|
||||
billable_units=3,
|
||||
)
|
||||
|
||||
assert notification.billable_units == 3
|
||||
@@ -450,40 +450,6 @@ def test_persist_email_notification_stores_normalised_email(
|
||||
assert persisted_notification.normalised_to == expected_recipient_normalised
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"postage_argument, template_postage, expected_postage",
|
||||
[
|
||||
("second", "first", "second"),
|
||||
("first", "first", "first"),
|
||||
("first", "second", "first")
|
||||
]
|
||||
)
|
||||
def test_persist_letter_notification_finds_correct_postage(
|
||||
mocker,
|
||||
postage_argument,
|
||||
template_postage,
|
||||
expected_postage,
|
||||
sample_service_full_permissions,
|
||||
sample_api_key,
|
||||
):
|
||||
template = create_template(sample_service_full_permissions, template_type=LETTER_TYPE, postage=template_postage)
|
||||
mocker.patch('app.dao.templates_dao.dao_get_template_by_id', return_value=template)
|
||||
persist_notification(
|
||||
template_id=template.id,
|
||||
template_version=template.version,
|
||||
recipient="Jane Doe, 10 Downing Street, London",
|
||||
service=sample_service_full_permissions,
|
||||
personalisation=None,
|
||||
notification_type=LETTER_TYPE,
|
||||
api_key_id=sample_api_key.id,
|
||||
key_type=sample_api_key.key_type,
|
||||
postage=postage_argument
|
||||
)
|
||||
persisted_notification = Notification.query.all()[0]
|
||||
|
||||
assert persisted_notification.postage == expected_postage
|
||||
|
||||
|
||||
def test_persist_notification_with_billable_units_stores_correct_info(
|
||||
mocker
|
||||
):
|
||||
@@ -504,22 +470,3 @@ def test_persist_notification_with_billable_units_stores_correct_info(
|
||||
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
|
||||
|
||||
@@ -25,7 +25,6 @@ from app.notifications.validators import (
|
||||
check_template_is_active,
|
||||
check_template_is_for_notification_type,
|
||||
service_can_send_to_recipient,
|
||||
validate_address,
|
||||
validate_and_format_recipient,
|
||||
validate_template,
|
||||
)
|
||||
@@ -623,19 +622,3 @@ 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