mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -04:00
big commit with letters removal
This commit is contained in:
@@ -3,16 +3,15 @@ from unittest.mock import PropertyMock
|
||||
import pytest
|
||||
|
||||
from app.models.service import Service
|
||||
from app.utils.branding import get_email_choices, get_letter_choices
|
||||
from app.utils.branding import get_email_choices
|
||||
from tests import organisation_json
|
||||
from tests.conftest import create_email_branding
|
||||
|
||||
|
||||
@pytest.mark.parametrize('function', [get_email_choices, get_letter_choices])
|
||||
@pytest.mark.parametrize('function', [get_email_choices])
|
||||
@pytest.mark.parametrize('org_type, expected_options', [
|
||||
('federal', []),
|
||||
('state', []),
|
||||
# ('nhs_central', [('nhs', 'NHS')]),
|
||||
])
|
||||
def test_get_choices_service_not_assigned_to_org(
|
||||
service_one,
|
||||
@@ -155,113 +154,3 @@ def test_get_email_choices_branding_name_in_use(
|
||||
options = get_email_choices(service)
|
||||
# don't show option if its name is similar to current branding
|
||||
assert list(options) == expected_options
|
||||
|
||||
|
||||
@pytest.mark.parametrize('org_type, branding_id, expected_options', [
|
||||
('federal', None, [
|
||||
('organisation', 'Test Organisation')
|
||||
]),
|
||||
('state', None, [
|
||||
('organisation', 'Test Organisation')
|
||||
]),
|
||||
('state', 'some-random-branding', [
|
||||
('organisation', 'Test Organisation')
|
||||
]),
|
||||
# ('nhs_central', None, [
|
||||
# ('nhs', 'NHS')
|
||||
# ]),
|
||||
])
|
||||
def test_get_letter_choices_service_assigned_to_org(
|
||||
mocker,
|
||||
service_one,
|
||||
org_type,
|
||||
branding_id,
|
||||
expected_options,
|
||||
mock_get_service_organisation,
|
||||
):
|
||||
service = Service(service_one)
|
||||
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_json(organisation_type=org_type)
|
||||
)
|
||||
mocker.patch(
|
||||
'app.models.service.Service.letter_branding_id',
|
||||
new_callable=PropertyMock,
|
||||
return_value=branding_id,
|
||||
)
|
||||
|
||||
options = get_letter_choices(service)
|
||||
assert list(options) == expected_options
|
||||
|
||||
|
||||
@pytest.mark.parametrize('branding_id, expected_options', [
|
||||
('some-branding-id', [
|
||||
# show org option if it's not the current branding
|
||||
('organisation', 'Test Organisation'),
|
||||
]),
|
||||
('org-branding-id', [
|
||||
# don't show org option if it's the current branding
|
||||
]),
|
||||
])
|
||||
def test_get_letter_choices_org_has_default_branding(
|
||||
mocker,
|
||||
service_one,
|
||||
branding_id,
|
||||
expected_options,
|
||||
mock_get_service_organisation,
|
||||
):
|
||||
service = Service(service_one)
|
||||
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_json(
|
||||
organisation_type='federal',
|
||||
letter_branding_id='org-branding-id'
|
||||
)
|
||||
)
|
||||
mocker.patch(
|
||||
'app.models.service.Service.letter_branding_id',
|
||||
new_callable=PropertyMock,
|
||||
return_value=branding_id
|
||||
)
|
||||
|
||||
options = get_letter_choices(service)
|
||||
# don't show org option if it's the current branding
|
||||
assert list(options) == expected_options
|
||||
|
||||
|
||||
@pytest.mark.parametrize('branding_name, expected_options', [
|
||||
('NHS something else', [
|
||||
('nhs', 'NHS'),
|
||||
]),
|
||||
('NHS', [
|
||||
# don't show NHS option if it's the current branding
|
||||
])
|
||||
])
|
||||
@pytest.mark.skip(reason='Update for TTS')
|
||||
def test_get_letter_choices_branding_name_in_use(
|
||||
mocker,
|
||||
service_one,
|
||||
branding_name,
|
||||
expected_options,
|
||||
mock_get_service_organisation,
|
||||
):
|
||||
service = Service(service_one)
|
||||
|
||||
mocker.patch(
|
||||
'app.organisations_client.get_organisation',
|
||||
return_value=organisation_json(organisation_type='nhs_central')
|
||||
)
|
||||
mocker.patch(
|
||||
'app.models.service.Service.letter_branding_id',
|
||||
new_callable=PropertyMock,
|
||||
return_value='org-branding-id',
|
||||
)
|
||||
mocker.patch(
|
||||
'app.letter_branding_client.get_letter_branding',
|
||||
return_value={'name': branding_name}
|
||||
)
|
||||
|
||||
options = get_letter_choices(service)
|
||||
assert list(options) == expected_options
|
||||
|
||||
@@ -251,16 +251,6 @@ MockRecipients = namedtuple(
|
||||
'email',
|
||||
['fix 3 email addresses']
|
||||
),
|
||||
(
|
||||
{2}, [], [], [],
|
||||
'letter',
|
||||
['fix 1 address']
|
||||
),
|
||||
(
|
||||
{2, 4}, [], [], [],
|
||||
'letter',
|
||||
['fix 2 addresses']
|
||||
),
|
||||
(
|
||||
{2}, {3}, [], [],
|
||||
'sms',
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
|
||||
from app.utils.letters import get_letter_validation_error
|
||||
|
||||
|
||||
@pytest.mark.parametrize('error_message, invalid_pages, expected_title, expected_content, expected_summary', [
|
||||
(
|
||||
'letter-not-a4-portrait-oriented',
|
||||
[2],
|
||||
'Your letter is not A4 portrait size',
|
||||
(
|
||||
'You need to change the size or orientation of page 2. '
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
(
|
||||
'Validation failed because page 2 is not A4 portrait size.'
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'letter-not-a4-portrait-oriented',
|
||||
[2, 3, 4],
|
||||
'Your letter is not A4 portrait size',
|
||||
(
|
||||
'You need to change the size or orientation of pages 2, 3 and 4. '
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
(
|
||||
'Validation failed because pages 2, 3 and 4 are not A4 portrait size.'
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'content-outside-printable-area',
|
||||
[2],
|
||||
'Your content is outside the printable area',
|
||||
(
|
||||
'You need to edit page 2.'
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
(
|
||||
'Validation failed because content is outside the printable area '
|
||||
'on page 2.'
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'letter-too-long',
|
||||
None,
|
||||
'Your letter is too long',
|
||||
(
|
||||
'Letters must be 10 pages or less (5 double-sided sheets of paper). '
|
||||
'Your letter is 13 pages long.'
|
||||
),
|
||||
(
|
||||
'Validation failed because this letter is 13 pages long.'
|
||||
'Letters must be 10 pages or less (5 double-sided sheets of paper).'
|
||||
),
|
||||
),
|
||||
(
|
||||
'unable-to-read-the-file',
|
||||
None,
|
||||
'There’s a problem with your file',
|
||||
(
|
||||
'Notify cannot read this PDF.'
|
||||
'Save a new copy of your file and try again.'
|
||||
),
|
||||
(
|
||||
'Validation failed because Notify cannot read this PDF.'
|
||||
'Save a new copy of your file and try again.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'address-is-empty',
|
||||
None,
|
||||
'The address block is empty',
|
||||
(
|
||||
'You need to add a recipient address.'
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
(
|
||||
'Validation failed because the address block is empty.'
|
||||
'Files must meet our letter specification.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'not-a-real-uk-postcode',
|
||||
None,
|
||||
'There’s a problem with the address for this letter',
|
||||
(
|
||||
'The last line of the address must be a real UK postcode.'
|
||||
),
|
||||
(
|
||||
'Validation failed because the last line of the address is not a real UK postcode.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'cant-send-international-letters',
|
||||
None,
|
||||
'There’s a problem with the address for this letter',
|
||||
(
|
||||
'You do not have permission to send letters to other countries.'
|
||||
),
|
||||
(
|
||||
'Validation failed because your service cannot send letters to other countries.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'not-a-real-uk-postcode-or-country',
|
||||
None,
|
||||
'There’s a problem with the address for this letter',
|
||||
(
|
||||
'The last line of the address must be a UK postcode or '
|
||||
'another country.'
|
||||
),
|
||||
(
|
||||
'Validation failed because the last line of the address is '
|
||||
'not a UK postcode or another country.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'not-enough-address-lines',
|
||||
None,
|
||||
'There’s a problem with the address for this letter',
|
||||
(
|
||||
'The address must be at least 3 lines long.'
|
||||
),
|
||||
(
|
||||
'Validation failed because the address must be at least 3 lines long.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'too-many-address-lines',
|
||||
None,
|
||||
'There’s a problem with the address for this letter',
|
||||
(
|
||||
'The address must be no more than 7 lines long.'
|
||||
),
|
||||
(
|
||||
'Validation failed because the address must be no more than 7 lines long.'
|
||||
),
|
||||
),
|
||||
(
|
||||
'invalid-char-in-address',
|
||||
None,
|
||||
'There’s a problem with the address for this letter',
|
||||
(
|
||||
'Address lines must not start with any of the following characters: @ ( ) = [ ] ” \\ / , < > ~'
|
||||
),
|
||||
(
|
||||
'Validation failed because address lines must not start with any of the following '
|
||||
'characters: @ ( ) = [ ] ” \\ / , < > ~'
|
||||
),
|
||||
),
|
||||
])
|
||||
def test_get_letter_validation_error_for_known_errors(
|
||||
client_request,
|
||||
error_message,
|
||||
invalid_pages,
|
||||
expected_title,
|
||||
expected_content,
|
||||
expected_summary,
|
||||
):
|
||||
error = get_letter_validation_error(error_message, invalid_pages=invalid_pages, page_count=13)
|
||||
detail = BeautifulSoup(error['detail'], 'html.parser')
|
||||
summary = BeautifulSoup(error['summary'], 'html.parser')
|
||||
|
||||
assert error['title'] == expected_title
|
||||
|
||||
assert detail.text == expected_content
|
||||
if detail.select_one('a'):
|
||||
assert detail.select_one('a')['href'] == url_for('.letter_specification')
|
||||
|
||||
assert summary.text == expected_summary
|
||||
if summary.select_one('a'):
|
||||
assert summary.select_one('a')['href'] == url_for('.letter_specification')
|
||||
@@ -4,7 +4,7 @@ from notifications_utils.template import Template
|
||||
from app.utils.templates import get_sample_template
|
||||
|
||||
|
||||
@pytest.mark.parametrize("template_type", ["sms", "letter", "email"])
|
||||
@pytest.mark.parametrize("template_type", ["sms", "email"])
|
||||
def test_get_sample_template_returns_template(template_type):
|
||||
template = get_sample_template(template_type)
|
||||
assert isinstance(template, Template)
|
||||
|
||||
@@ -12,7 +12,7 @@ from app.utils.user_permissions import (
|
||||
{'manage_templates'},
|
||||
),
|
||||
(
|
||||
['send_texts', 'send_emails', 'send_letters', 'manage_templates', 'some_unknown_permission'],
|
||||
['send_texts', 'send_emails', 'manage_templates', 'some_unknown_permission'],
|
||||
{'send_messages', 'manage_templates', 'some_unknown_permission'},
|
||||
),
|
||||
])
|
||||
@@ -29,5 +29,5 @@ def test_translate_permissions_from_ui_to_db():
|
||||
db_permissions = translate_permissions_from_ui_to_db(ui_permissions)
|
||||
|
||||
assert db_permissions == {
|
||||
'send_texts', 'send_emails', 'send_letters', 'manage_templates', 'some_unknown_permission'
|
||||
'send_texts', 'send_emails', 'manage_templates', 'some_unknown_permission'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user