mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-04 13:41:38 -04:00
Tell template preview whether a letter can be sent internationally
If a service has permission to send international letters then the admin app should tell template preview, so that template preview knows what rules to apply when it’s validating the address of the letter. We don’t need to wait for template preview to start looking at this query string argument – it will just ignore it for now.
This commit is contained in:
@@ -143,16 +143,22 @@ def test_get_upload_letter(client_request):
|
||||
assert normalize_spaces(page.find('label', class_='file-upload-button').text) == 'Choose file'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('extra_permissions, expected_allow_international', (
|
||||
([], False),
|
||||
(['international_letters'], True),
|
||||
))
|
||||
def test_post_upload_letter_redirects_for_valid_file(
|
||||
mocker,
|
||||
active_user_with_permissions,
|
||||
service_one,
|
||||
client_request,
|
||||
fake_uuid,
|
||||
extra_permissions,
|
||||
expected_allow_international,
|
||||
):
|
||||
mocker.patch('uuid.uuid4', return_value=fake_uuid)
|
||||
antivirus_mock = mocker.patch('app.main.views.uploads.antivirus_client.scan', return_value=True)
|
||||
mocker.patch(
|
||||
mock_sanitise = mocker.patch(
|
||||
'app.main.views.uploads.sanitise_letter',
|
||||
return_value=Mock(
|
||||
content='The sanitised content',
|
||||
@@ -169,6 +175,7 @@ def test_post_upload_letter_redirects_for_valid_file(
|
||||
mocker.patch('app.main.views.uploads.service_api_client.get_precompiled_template')
|
||||
|
||||
service_one['restricted'] = False
|
||||
service_one['permissions'] += extra_permissions
|
||||
client_request.login(active_user_with_permissions, service=service_one)
|
||||
|
||||
with open('tests/test_pdf_files/one_page_pdf.pdf', 'rb') as file:
|
||||
@@ -188,6 +195,10 @@ def test_post_upload_letter_redirects_for_valid_file(
|
||||
filename='tests/test_pdf_files/one_page_pdf.pdf',
|
||||
recipient='The Queen',
|
||||
)
|
||||
mock_sanitise.assert_called_once_with(
|
||||
ANY,
|
||||
allow_international_letters=expected_allow_international,
|
||||
)
|
||||
|
||||
assert 'The Queen' in page.find('div', class_='js-stick-at-bottom-when-scrolling').text
|
||||
assert page.find('h1').text == 'tests/test_pdf_files/one_page_pdf.pdf'
|
||||
|
||||
@@ -164,13 +164,21 @@ def test_from_example_template_makes_request(mocker):
|
||||
)
|
||||
|
||||
|
||||
def test_sanitise_letter_calls_template_preview_sanitise_endoint_with_file(mocker):
|
||||
@pytest.mark.parametrize('allow_international_letters, expected_url', (
|
||||
(False, 'http://localhost:9999/precompiled/sanitise?allow_international_letters=false'),
|
||||
(True, 'http://localhost:9999/precompiled/sanitise?allow_international_letters=true'),
|
||||
))
|
||||
def test_sanitise_letter_calls_template_preview_sanitise_endoint_with_file(
|
||||
mocker,
|
||||
allow_international_letters,
|
||||
expected_url,
|
||||
):
|
||||
request_mock = mocker.patch('app.template_previews.requests.post')
|
||||
|
||||
sanitise_letter('pdf_data')
|
||||
sanitise_letter('pdf_data', allow_international_letters=allow_international_letters)
|
||||
|
||||
request_mock.assert_called_once_with(
|
||||
'http://localhost:9999/precompiled/sanitise',
|
||||
expected_url,
|
||||
headers={'Authorization': 'Token my-secret-key'},
|
||||
data='pdf_data'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user