mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 16:24:08 -04:00
Merge pull request #2896 from alphagov/remove-domains-yml
Use organisations from database rather than YAML file
This commit is contained in:
@@ -56,7 +56,6 @@ def test_should_add_service_and_redirect_to_tour_when_no_services(
|
||||
restricted=True,
|
||||
user_id=api_user_active.id,
|
||||
email_from='testing.the.post',
|
||||
service_domain=None
|
||||
)
|
||||
mock_create_service_template.assert_called_once_with(
|
||||
'Example text message template',
|
||||
@@ -71,10 +70,10 @@ def test_should_add_service_and_redirect_to_tour_when_no_services(
|
||||
mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, 25000)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('organisation_type, free_allowance, service_domain', [
|
||||
('central', 250 * 1000, None),
|
||||
('local', 25 * 1000, None),
|
||||
('nhs', 25 * 1000, 'nhs.uk'),
|
||||
@pytest.mark.parametrize('organisation_type, free_allowance', [
|
||||
('central', 250 * 1000),
|
||||
('local', 25 * 1000),
|
||||
('nhs', 25 * 1000),
|
||||
])
|
||||
def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
||||
app_,
|
||||
@@ -82,11 +81,9 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
||||
mock_create_service,
|
||||
mock_create_service_template,
|
||||
mock_get_services,
|
||||
mock_update_service,
|
||||
api_user_active,
|
||||
organisation_type,
|
||||
free_allowance,
|
||||
service_domain,
|
||||
mock_create_or_update_free_sms_fragment_limit,
|
||||
mock_get_all_email_branding,
|
||||
):
|
||||
@@ -111,56 +108,12 @@ def test_should_add_service_and_redirect_to_dashboard_when_existing_service(
|
||||
restricted=True,
|
||||
user_id=api_user_active.id,
|
||||
email_from='testing.the.post',
|
||||
service_domain=service_domain
|
||||
)
|
||||
mock_create_or_update_free_sms_fragment_limit.assert_called_once_with(101, free_allowance)
|
||||
assert len(mock_create_service_template.call_args_list) == 0
|
||||
assert session['service_id'] == 101
|
||||
|
||||
|
||||
@pytest.mark.parametrize('organisation_type, email_address, expected_branding', [
|
||||
('central', 'test@example.voa.gsi.gov.uk', '5'),
|
||||
('central', 'test@example.voa.gov.uk', '5'),
|
||||
('central', 'test@example.gov.uk', None),
|
||||
# Anyone choosing ‘NHS’ for organisation type gets NHS branding no
|
||||
# matter what their email domain is (but we look it up based on the
|
||||
# `nhs.uk` domain to avoid hard-coding a branding ID anywhere)
|
||||
('nhs', 'test@example.voa.gov.uk', '4'),
|
||||
('nhs', 'test@nhs.uk', '4'),
|
||||
])
|
||||
def test_should_lookup_branding_for_known_domain(
|
||||
app_,
|
||||
client_request,
|
||||
active_user_with_permissions,
|
||||
mock_create_service,
|
||||
mock_get_services,
|
||||
mock_update_service,
|
||||
mock_create_or_update_free_sms_fragment_limit,
|
||||
mock_get_all_email_branding,
|
||||
organisation_type,
|
||||
email_address,
|
||||
expected_branding,
|
||||
):
|
||||
active_user_with_permissions.email_address = email_address
|
||||
client_request.login(active_user_with_permissions)
|
||||
client_request.post(
|
||||
'main.add_service',
|
||||
_data={
|
||||
'name': 'testing the post',
|
||||
'organisation_type': organisation_type,
|
||||
}
|
||||
)
|
||||
mock_get_all_email_branding.assert_called_once_with()
|
||||
assert mock_create_service.called is True
|
||||
if expected_branding:
|
||||
mock_update_service.assert_called_once_with(
|
||||
101,
|
||||
email_branding=expected_branding,
|
||||
)
|
||||
else:
|
||||
assert mock_update_service.called is False
|
||||
|
||||
|
||||
def test_should_return_form_errors_when_service_name_is_empty(
|
||||
client_request
|
||||
):
|
||||
|
||||
@@ -4,7 +4,7 @@ from io import BytesIO
|
||||
import pytest
|
||||
from flask import url_for
|
||||
|
||||
from tests.conftest import active_user_with_permissions
|
||||
from tests.conftest import mock_get_organisation_by_domain
|
||||
|
||||
|
||||
class _MockS3Object():
|
||||
@@ -16,22 +16,22 @@ class _MockS3Object():
|
||||
return {'Body': BytesIO(self.data)}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address, expected_links', [
|
||||
@pytest.mark.parametrize('agreement_signed, crown, expected_links', [
|
||||
(
|
||||
'test@cabinet-office.gov.uk',
|
||||
True, True,
|
||||
[
|
||||
partial(url_for, 'main.download_agreement'),
|
||||
]
|
||||
),
|
||||
(
|
||||
'test@aylesburytowncouncil.gov.uk',
|
||||
False, False,
|
||||
[
|
||||
partial(url_for, 'main.download_agreement'),
|
||||
lambda: 'mailto:notify-support@digital.cabinet-office.gov.uk',
|
||||
]
|
||||
),
|
||||
(
|
||||
'test@unknown.gov.uk',
|
||||
None, None,
|
||||
[
|
||||
partial(url_for, 'main.public_download_agreement', variant='crown'),
|
||||
partial(url_for, 'main.public_download_agreement', variant='non-crown'),
|
||||
@@ -44,12 +44,15 @@ def test_show_agreement_page(
|
||||
client_request,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
email_address,
|
||||
agreement_signed,
|
||||
crown,
|
||||
expected_links,
|
||||
):
|
||||
user = active_user_with_permissions(fake_uuid)
|
||||
user.email_address = email_address
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
mock_get_organisation_by_domain(
|
||||
mocker,
|
||||
crown=crown,
|
||||
agreement_signed=agreement_signed,
|
||||
)
|
||||
page = client_request.get('main.agreement')
|
||||
links = page.select('main .column-two-thirds a')
|
||||
assert len(links) == len(expected_links)
|
||||
@@ -57,14 +60,14 @@ def test_show_agreement_page(
|
||||
assert link['href'] == expected_links[index]()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address, expected_file_fetched, expected_file_served', [
|
||||
@pytest.mark.parametrize('crown, expected_file_fetched, expected_file_served', [
|
||||
(
|
||||
'test@cabinet-office.gov.uk',
|
||||
True,
|
||||
'crown.pdf',
|
||||
'GOV.UK Notify data sharing and financial agreement.pdf',
|
||||
),
|
||||
(
|
||||
'test@aylesburytowncouncil.gov.uk',
|
||||
False,
|
||||
'non-crown.pdf',
|
||||
'GOV.UK Notify data sharing and financial agreement (non-crown).pdf',
|
||||
),
|
||||
@@ -73,7 +76,7 @@ def test_downloading_agreement(
|
||||
logged_in_client,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
email_address,
|
||||
crown,
|
||||
expected_file_fetched,
|
||||
expected_file_served,
|
||||
):
|
||||
@@ -81,9 +84,10 @@ def test_downloading_agreement(
|
||||
'app.s3_client.s3_mou_client.get_s3_object',
|
||||
return_value=_MockS3Object(b'foo')
|
||||
)
|
||||
user = active_user_with_permissions(fake_uuid)
|
||||
user.email_address = email_address
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
mock_get_organisation_by_domain(
|
||||
mocker,
|
||||
crown=crown,
|
||||
)
|
||||
response = logged_in_client.get(url_for('main.download_agreement'))
|
||||
assert response.status_code == 200
|
||||
assert response.get_data() == b'foo'
|
||||
@@ -103,9 +107,10 @@ def test_agreement_cant_be_downloaded_unknown_crown_status(
|
||||
'app.s3_client.s3_mou_client.get_s3_object',
|
||||
return_value=_MockS3Object()
|
||||
)
|
||||
user = active_user_with_permissions(fake_uuid)
|
||||
user.email_address = 'test@unknown.gov.uk'
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
mock_get_organisation_by_domain(
|
||||
mocker,
|
||||
crown=None,
|
||||
)
|
||||
response = logged_in_client.get(url_for('main.download_agreement'))
|
||||
assert response.status_code == 404
|
||||
assert mock_get_s3_object.call_args_list == []
|
||||
|
||||
@@ -28,7 +28,6 @@ def test_email_branding_page_shows_full_branding_list(
|
||||
links = page.select('.message-name a')
|
||||
brand_names = [normalize_spaces(link.text) for link in links]
|
||||
hrefs = [link['href'] for link in links]
|
||||
brand_hints = [normalize_spaces(hint.text) for hint in page.select('.message-type')]
|
||||
|
||||
assert normalize_spaces(
|
||||
page.select_one('h1').text
|
||||
@@ -36,14 +35,12 @@ def test_email_branding_page_shows_full_branding_list(
|
||||
|
||||
assert page.select_one('.column-three-quarters a')['href'] == url_for('main.create_email_branding')
|
||||
|
||||
assert list(zip(
|
||||
brand_names, brand_hints
|
||||
)) == [
|
||||
('org 1', '–'),
|
||||
('org 2', '–'),
|
||||
('org 3', '–'),
|
||||
('org 4', 'Default for nhs.uk'),
|
||||
('org 5', 'Default for voa.gov.uk'),
|
||||
assert brand_names == [
|
||||
'org 1',
|
||||
'org 2',
|
||||
'org 3',
|
||||
'org 4',
|
||||
'org 5',
|
||||
]
|
||||
assert hrefs == [
|
||||
url_for('.update_email_branding', branding_id=1),
|
||||
@@ -70,7 +67,6 @@ def test_edit_email_branding_shows_the_correct_branding_info(
|
||||
assert page.select_one('#name').attrs.get('value') == 'Organisation name'
|
||||
assert page.select_one('#text').attrs.get('value') == 'Organisation text'
|
||||
assert page.select_one('#colour').attrs.get('value') == '#f00'
|
||||
assert page.select_one('#domain').attrs.get('value') == 'sample.com'
|
||||
|
||||
|
||||
def test_create_email_branding_does_not_show_any_branding_info(
|
||||
@@ -89,27 +85,19 @@ def test_create_email_branding_does_not_show_any_branding_info(
|
||||
assert page.select_one('#name').attrs.get('value') == ''
|
||||
assert page.select_one('#text').attrs.get('value') == ''
|
||||
assert page.select_one('#colour').attrs.get('value') == ''
|
||||
assert page.select_one('#domain').attrs.get('value') == ''
|
||||
|
||||
|
||||
@pytest.mark.parametrize('posted_domain, persisted_domain', [
|
||||
('voa.gov.uk', 'voa.gov.uk'),
|
||||
('', None),
|
||||
])
|
||||
def test_create_new_email_branding_without_logo(
|
||||
logged_in_platform_admin_client,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
mock_create_email_branding,
|
||||
posted_domain,
|
||||
persisted_domain,
|
||||
):
|
||||
data = {
|
||||
'logo': None,
|
||||
'colour': '#ff0000',
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': posted_domain,
|
||||
'brand_type': 'org'
|
||||
}
|
||||
|
||||
@@ -128,96 +116,11 @@ def test_create_new_email_branding_without_logo(
|
||||
name=data['name'],
|
||||
text=data['text'],
|
||||
colour=data['colour'],
|
||||
domain=persisted_domain,
|
||||
brand_type=data['brand_type']
|
||||
)
|
||||
assert mock_persist.call_args_list == []
|
||||
|
||||
|
||||
def test_cant_create_new_email_branding_with_unknown_domain(
|
||||
client_request,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
mock_create_email_branding
|
||||
):
|
||||
mock_persist = mocker.patch('app.main.views.email_branding.persist_logo')
|
||||
mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
|
||||
client_request.login(platform_admin_user(fake_uuid))
|
||||
page = client_request.post(
|
||||
'.create_email_branding',
|
||||
content_type='multipart/form-data',
|
||||
_data={
|
||||
'logo': None,
|
||||
'colour': '#ff0000',
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': 'example.gov.uk',
|
||||
'brand_type': 'org',
|
||||
},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert mock_create_email_branding.called is False
|
||||
assert mock_persist.called is False
|
||||
|
||||
assert page.select_one('.error-message').text.strip() == (
|
||||
'Not a known government domain (you might need to update domains.yml)'
|
||||
)
|
||||
assert page.select_one('input[name=domain]')['value'] == (
|
||||
'example.gov.uk'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('posted_domain, expected_error', [
|
||||
(
|
||||
'voa.gsi.gov.uk',
|
||||
'Not a canonical domain (use voa.gov.uk if appropriate)',
|
||||
),
|
||||
(
|
||||
'hmcts.net',
|
||||
'Not a canonical domain (use hmcts.gov.uk if appropriate)',
|
||||
),
|
||||
(
|
||||
'southend.essex.gov.uk',
|
||||
'Not an organisation-level domain (use essex.gov.uk if appropriate)',
|
||||
),
|
||||
pytest.param(
|
||||
'voa.gov.uk',
|
||||
'',
|
||||
marks=pytest.mark.xfail(raises=AssertionError)
|
||||
),
|
||||
])
|
||||
def test_rejects_non_canonical_domain_when_adding_email_branding(
|
||||
client_request,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
mock_create_email_branding,
|
||||
posted_domain,
|
||||
expected_error,
|
||||
):
|
||||
mocker.patch('app.main.views.email_branding.persist_logo')
|
||||
mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
data = {
|
||||
'logo': None,
|
||||
'colour': '#ff0000',
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': posted_domain,
|
||||
'brand_type': 'org',
|
||||
}
|
||||
client_request.login(platform_admin_user(fake_uuid))
|
||||
page = client_request.post(
|
||||
'.create_email_branding',
|
||||
content_type='multipart/form-data',
|
||||
_data=data,
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert page.select_one('.error-message').text.strip() == expected_error
|
||||
assert mock_create_email_branding.called is False
|
||||
|
||||
|
||||
def test_create_email_branding_requires_a_name_when_submitting_logo_details(
|
||||
client_request,
|
||||
mocker,
|
||||
@@ -232,7 +135,6 @@ def test_create_email_branding_requires_a_name_when_submitting_logo_details(
|
||||
'colour': '#ff0000',
|
||||
'text': 'new text',
|
||||
'name': '',
|
||||
'domain': '',
|
||||
'brand_type': 'org',
|
||||
}
|
||||
client_request.login(platform_admin_user(fake_uuid))
|
||||
@@ -258,7 +160,6 @@ def test_create_email_branding_does_not_require_a_name_when_uploading_a_file(
|
||||
'colour': '',
|
||||
'text': '',
|
||||
'name': '',
|
||||
'domain': '',
|
||||
'brand_type': 'org',
|
||||
}
|
||||
client_request.login(platform_admin_user(fake_uuid))
|
||||
@@ -286,7 +187,6 @@ def test_create_new_email_branding_when_branding_saved(
|
||||
'colour': '#ff0000',
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': 'voa.gov.uk',
|
||||
'brand_type': 'org_banner'
|
||||
}
|
||||
|
||||
@@ -307,7 +207,6 @@ def test_create_new_email_branding_when_branding_saved(
|
||||
'name': data['name'],
|
||||
'text': data['text'],
|
||||
'cdn_url': 'https://static-logos.cdn.com',
|
||||
'domain': data['domain'],
|
||||
'brand_type': data['brand_type']
|
||||
}
|
||||
)
|
||||
@@ -320,7 +219,6 @@ def test_create_new_email_branding_when_branding_saved(
|
||||
name=data['name'],
|
||||
text=data['text'],
|
||||
colour=data['colour'],
|
||||
domain=data['domain'],
|
||||
brand_type=data['brand_type']
|
||||
)
|
||||
|
||||
@@ -387,7 +285,6 @@ def test_update_existing_branding(
|
||||
'colour': '#0000ff',
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': 'voa.gov.uk',
|
||||
'brand_type': 'both'
|
||||
}
|
||||
|
||||
@@ -405,7 +302,7 @@ def test_update_existing_branding(
|
||||
content_type='multipart/form-data',
|
||||
data={'colour': data['colour'], 'name': data['name'], 'text': data['text'],
|
||||
'cdn_url': 'https://static-logos.cdn.com',
|
||||
'domain': data['domain'], 'brand_type': data['brand_type']
|
||||
'brand_type': data['brand_type']
|
||||
}
|
||||
)
|
||||
|
||||
@@ -418,7 +315,6 @@ def test_update_existing_branding(
|
||||
name=data['name'],
|
||||
text=data['text'],
|
||||
colour=data['colour'],
|
||||
domain=data['domain'],
|
||||
brand_type=data['brand_type']
|
||||
)
|
||||
|
||||
@@ -526,7 +422,6 @@ def test_colour_regex_validation(
|
||||
'colour': colour_hex,
|
||||
'text': 'new text',
|
||||
'name': 'new name',
|
||||
'domain': 'voa.gov.uk',
|
||||
'brand_type': 'org'
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from flask import url_for
|
||||
|
||||
from app.main.forms import FieldWithNoneOption
|
||||
from tests.conftest import (
|
||||
active_user_with_permissions,
|
||||
mock_get_organisation_by_domain,
|
||||
normalize_spaces,
|
||||
sample_uuid,
|
||||
)
|
||||
@@ -82,6 +82,7 @@ def test_robots(client):
|
||||
])
|
||||
def test_static_pages(
|
||||
client_request,
|
||||
mock_get_organisation_by_domain,
|
||||
view,
|
||||
):
|
||||
page = client_request.get('main.{}'.format(view))
|
||||
@@ -179,13 +180,15 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
|
||||
|
||||
|
||||
@pytest.mark.parametrize((
|
||||
'email_address,'
|
||||
'name,'
|
||||
'agreement_signed,'
|
||||
'expected_terms_paragraph,'
|
||||
'expected_terms_link,'
|
||||
'expected_pricing_paragraph'
|
||||
), [
|
||||
(
|
||||
'test@cabinet-office.gov.uk',
|
||||
'Cabinet Office',
|
||||
True,
|
||||
(
|
||||
'Your organisation (Cabinet Office) has already accepted '
|
||||
'the GOV.UK Notify data sharing and financial agreement.'
|
||||
@@ -197,7 +200,8 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
|
||||
),
|
||||
),
|
||||
(
|
||||
'test@aylesburytowncouncil.gov.uk',
|
||||
'Aylesbury Town Council',
|
||||
False,
|
||||
(
|
||||
'Your organisation (Aylesbury Town Council) must also '
|
||||
'accept our data sharing and financial agreement. Download '
|
||||
@@ -213,7 +217,8 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
|
||||
),
|
||||
),
|
||||
(
|
||||
'larry@downing-street.gov.uk',
|
||||
None,
|
||||
None,
|
||||
(
|
||||
'Your organisation must also accept our data sharing and '
|
||||
'financial agreement. Download the agreement or contact us '
|
||||
@@ -230,7 +235,8 @@ def test_pricing_is_generic_if_user_is_not_logged_in(
|
||||
),
|
||||
),
|
||||
(
|
||||
'michael.fish@metoffice.gov.uk',
|
||||
'Met Office',
|
||||
False,
|
||||
(
|
||||
'Your organisation (Met Office) must also accept our data '
|
||||
'sharing and financial agreement. Download a copy.'
|
||||
@@ -249,14 +255,17 @@ def test_terms_tells_logged_in_users_what_we_know_about_their_agreement(
|
||||
mocker,
|
||||
fake_uuid,
|
||||
client_request,
|
||||
email_address,
|
||||
name,
|
||||
agreement_signed,
|
||||
expected_terms_paragraph,
|
||||
expected_terms_link,
|
||||
expected_pricing_paragraph,
|
||||
):
|
||||
user = active_user_with_permissions(fake_uuid)
|
||||
user.email_address = email_address
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
mock_get_organisation_by_domain(
|
||||
mocker,
|
||||
name=name,
|
||||
agreement_signed=agreement_signed,
|
||||
)
|
||||
terms_page = client_request.get('main.terms')
|
||||
pricing_page = client_request.get('main.pricing')
|
||||
assert normalize_spaces(terms_page.select('main p')[1].text) == expected_terms_paragraph
|
||||
@@ -269,7 +278,7 @@ def test_terms_tells_logged_in_users_what_we_know_about_their_agreement(
|
||||
|
||||
def test_css_is_served_from_correct_path(client_request):
|
||||
|
||||
page = client_request.get('main.pricing') # easy static page
|
||||
page = client_request.get('main.documentation') # easy static page
|
||||
|
||||
for index, link in enumerate(
|
||||
page.select('link[rel=stylesheet]')
|
||||
|
||||
@@ -2,7 +2,6 @@ from io import BytesIO
|
||||
from unittest.mock import Mock, call
|
||||
from uuid import UUID
|
||||
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError as BotoClientError
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import current_app, url_for
|
||||
@@ -29,7 +28,6 @@ def test_letter_branding_page_shows_full_branding_list(
|
||||
links = page.select('.message-name a')
|
||||
brand_names = [normalize_spaces(link.text) for link in links]
|
||||
hrefs = [link['href'] for link in links]
|
||||
brand_hints = [normalize_spaces(hint.text) for hint in page.select('.message-type')]
|
||||
|
||||
assert normalize_spaces(
|
||||
page.select_one('h1').text
|
||||
@@ -37,12 +35,10 @@ def test_letter_branding_page_shows_full_branding_list(
|
||||
|
||||
assert page.select_one('.column-three-quarters a')['href'] == url_for('main.create_letter_branding')
|
||||
|
||||
assert list(zip(
|
||||
brand_names, brand_hints
|
||||
)) == [
|
||||
('HM Government', '–'),
|
||||
('Land Registry', 'Default for landregistry.gov.uk'),
|
||||
('Animal and Plant Health Agency', '–'),
|
||||
assert brand_names == [
|
||||
'HM Government',
|
||||
'Land Registry',
|
||||
'Animal and Plant Health Agency',
|
||||
]
|
||||
|
||||
assert hrefs == [
|
||||
@@ -66,7 +62,6 @@ def test_update_letter_branding_shows_the_current_letter_brand(
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
assert page.select_one('#logo-img > img')['src'].endswith('/hm-government.svg')
|
||||
assert page.select_one('#name').attrs.get('value') == 'HM Government'
|
||||
assert page.select_one('#domain').attrs.get('value') == 'cabinet-office.gov.uk'
|
||||
|
||||
|
||||
def test_update_letter_branding_with_new_valid_file(
|
||||
@@ -95,7 +90,6 @@ def test_update_letter_branding_with_new_valid_file(
|
||||
|
||||
assert page.select_one('#logo-img > img')['src'].endswith(expected_temp_filename)
|
||||
assert page.select_one('#name').attrs.get('value') == 'HM Government'
|
||||
assert page.select_one('#domain').attrs.get('value') == 'cabinet-office.gov.uk'
|
||||
|
||||
assert mock_s3_upload.called
|
||||
mock_delete_temp_files.assert_not_called()
|
||||
@@ -161,7 +155,6 @@ def test_update_letter_branding_with_original_file_and_new_details(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid),
|
||||
data={
|
||||
'name': 'Updated name',
|
||||
'domain': 'bl.uk',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
@@ -175,42 +168,12 @@ def test_update_letter_branding_with_original_file_and_new_details(
|
||||
|
||||
mock_client_update.assert_called_once_with(
|
||||
branding_id=fake_uuid,
|
||||
domain='bl.uk',
|
||||
filename='hm-government',
|
||||
name='Updated name'
|
||||
)
|
||||
|
||||
|
||||
def test_update_letter_branding_does_not_require_a_domain(
|
||||
mocker,
|
||||
logged_in_platform_admin_client,
|
||||
mock_get_all_letter_branding,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid
|
||||
):
|
||||
mock_client_update = mocker.patch('app.main.views.letter_branding.letter_branding_client.update_letter_branding')
|
||||
logo = permanent_letter_logo_name('hm-government', 'svg')
|
||||
|
||||
response = logged_in_platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=logo),
|
||||
data={
|
||||
'name': 'Updated name',
|
||||
'domain': '',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
mock_client_update.assert_called_once_with(
|
||||
branding_id=fake_uuid,
|
||||
domain=None,
|
||||
filename='hm-government',
|
||||
name='Updated name'
|
||||
)
|
||||
|
||||
|
||||
def test_update_letter_branding_shows_form_errors_on_name_and_domain_fields(
|
||||
def test_update_letter_branding_shows_form_errors_on_name_fields(
|
||||
mocker,
|
||||
logged_in_platform_admin_client,
|
||||
mock_get_letter_branding_by_id,
|
||||
@@ -224,7 +187,6 @@ def test_update_letter_branding_shows_form_errors_on_name_and_domain_fields(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=logo),
|
||||
data={
|
||||
'name': '',
|
||||
'domain': 'example.com',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
@@ -234,18 +196,15 @@ def test_update_letter_branding_shows_form_errors_on_name_and_domain_fields(
|
||||
error_messages = page.find_all('span', class_='error-message')
|
||||
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
assert len(error_messages) == 2
|
||||
assert len(error_messages) == 1
|
||||
assert error_messages[0].text.strip() == 'This field is required.'
|
||||
assert error_messages[1].text.strip() == 'Not a known government domain (you might need to update domains.yml)'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('error_field', ['name', 'domain'])
|
||||
def test_update_letter_branding_shows_database_errors_on_name_and_domain_fields(
|
||||
def test_update_letter_branding_shows_database_errors_on_name_field(
|
||||
mocker,
|
||||
logged_in_platform_admin_client,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid,
|
||||
error_field
|
||||
):
|
||||
mocker.patch('app.main.views.letter_branding.get_png_file_from_svg')
|
||||
mocker.patch('app.main.views.letter_branding.letter_branding_client.update_letter_branding', side_effect=HTTPError(
|
||||
@@ -254,20 +213,19 @@ def test_update_letter_branding_shows_database_errors_on_name_and_domain_fields(
|
||||
json={
|
||||
'result': 'error',
|
||||
'message': {
|
||||
error_field: {
|
||||
'{} already in use'.format(error_field)
|
||||
'name': {
|
||||
'name already in use'
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
message={error_field: ['{} already in use'.format(error_field)]}
|
||||
message={'name': ['name already in use']}
|
||||
))
|
||||
|
||||
response = logged_in_platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id='abc'),
|
||||
data={
|
||||
'name': 'my brand',
|
||||
'domain': None,
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
)
|
||||
@@ -276,7 +234,7 @@ def test_update_letter_branding_shows_database_errors_on_name_and_domain_fields(
|
||||
error_message = page.find('span', class_='error-message').text.strip()
|
||||
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
assert error_message == '{} already in use'.format(error_field)
|
||||
assert error_message == 'name already in use'
|
||||
|
||||
|
||||
def test_update_letter_branding_with_new_file_and_new_details(
|
||||
@@ -300,7 +258,6 @@ def test_update_letter_branding_with_new_file_and_new_details(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=temp_logo),
|
||||
data={
|
||||
'name': 'Updated name',
|
||||
'domain': 'bl.uk',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
@@ -312,7 +269,6 @@ def test_update_letter_branding_with_new_file_and_new_details(
|
||||
assert mock_template_preview.called
|
||||
mock_client_update.assert_called_once_with(
|
||||
branding_id=fake_uuid,
|
||||
domain='bl.uk',
|
||||
filename='{}-new_file'.format(fake_uuid),
|
||||
name='Updated name'
|
||||
)
|
||||
@@ -343,7 +299,6 @@ def test_update_letter_branding_rolls_back_db_changes_and_shows_error_if_saving_
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=temp_logo),
|
||||
data={
|
||||
'name': 'Updated name',
|
||||
'domain': 'bl.uk',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
@@ -355,8 +310,8 @@ def test_update_letter_branding_rolls_back_db_changes_and_shows_error_if_saving_
|
||||
|
||||
assert mock_client_update.call_count == 2
|
||||
assert mock_client_update.call_args_list == [
|
||||
call(branding_id=fake_uuid, domain='bl.uk', filename='{}-new_file'.format(fake_uuid), name='Updated name'),
|
||||
call(branding_id=fake_uuid, domain='cabinet-office.gov.uk', filename='hm-government', name='HM Government')
|
||||
call(branding_id=fake_uuid, filename='{}-new_file'.format(fake_uuid), name='Updated name'),
|
||||
call(branding_id=fake_uuid, filename='hm-government', name='HM Government')
|
||||
]
|
||||
|
||||
|
||||
@@ -370,7 +325,6 @@ def test_create_letter_branding_does_not_show_branding_info(logged_in_platform_a
|
||||
|
||||
assert page.select_one('#logo-img > img') is None
|
||||
assert page.select_one('#name').attrs.get('value') == ''
|
||||
assert page.select_one('#domain').attrs.get('value') == ''
|
||||
|
||||
|
||||
def test_create_letter_branding_when_uploading_valid_file(
|
||||
@@ -472,7 +426,6 @@ def test_create_letter_branding_shows_an_error_when_submitting_details_with_no_l
|
||||
url_for('.create_letter_branding'),
|
||||
data={
|
||||
'name': 'Test brand',
|
||||
'domain': 'bl.uk',
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
)
|
||||
@@ -506,7 +459,6 @@ def test_create_letter_branding_persists_logo_when_all_data_is_valid(
|
||||
url_for('.create_letter_branding', logo=temp_logo),
|
||||
data={
|
||||
'name': 'Test brand',
|
||||
'domain': 'bl.uk',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
@@ -517,7 +469,7 @@ def test_create_letter_branding_persists_logo_when_all_data_is_valid(
|
||||
assert page.find('h1').text == 'Letter branding'
|
||||
|
||||
mock_letter_client.create_letter_branding.assert_called_once_with(
|
||||
domain='bl.uk', filename='{}-test'.format(fake_uuid), name='Test brand'
|
||||
filename='{}-test'.format(fake_uuid), name='Test brand'
|
||||
)
|
||||
assert mock_template_preview.called
|
||||
mock_persist_logo.assert_called_once_with(
|
||||
@@ -532,7 +484,7 @@ def test_create_letter_branding_persists_logo_when_all_data_is_valid(
|
||||
mock_delete_temp_files.assert_called_once_with(user_id)
|
||||
|
||||
|
||||
def test_create_letter_branding_shows_form_errors_on_name_and_domain_fields(
|
||||
def test_create_letter_branding_shows_form_errors_on_name_field(
|
||||
logged_in_platform_admin_client,
|
||||
fake_uuid
|
||||
):
|
||||
@@ -545,7 +497,6 @@ def test_create_letter_branding_shows_form_errors_on_name_and_domain_fields(
|
||||
url_for('.create_letter_branding', logo=temp_logo),
|
||||
data={
|
||||
'name': '',
|
||||
'domain': 'example.com',
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
)
|
||||
@@ -554,17 +505,14 @@ def test_create_letter_branding_shows_form_errors_on_name_and_domain_fields(
|
||||
error_messages = page.find_all('span', class_='error-message')
|
||||
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
assert len(error_messages) == 2
|
||||
assert len(error_messages) == 1
|
||||
assert error_messages[0].text.strip() == 'This field is required.'
|
||||
assert error_messages[1].text.strip() == 'Not a known government domain (you might need to update domains.yml)'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('error_field', ['name', 'domain'])
|
||||
def test_create_letter_branding_shows_database_errors_on_name_and_domain_fields(
|
||||
def test_create_letter_branding_shows_database_errors_on_name_fields(
|
||||
mocker,
|
||||
logged_in_platform_admin_client,
|
||||
fake_uuid,
|
||||
error_field
|
||||
):
|
||||
with logged_in_platform_admin_client.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
@@ -576,13 +524,13 @@ def test_create_letter_branding_shows_database_errors_on_name_and_domain_fields(
|
||||
json={
|
||||
'result': 'error',
|
||||
'message': {
|
||||
error_field: {
|
||||
'{} already in use'.format(error_field)
|
||||
'name': {
|
||||
'name already in use'
|
||||
}
|
||||
}
|
||||
}
|
||||
),
|
||||
message={error_field: ['{} already in use'.format(error_field)]}
|
||||
message={'name': ['name already in use']}
|
||||
))
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=user_id, unique_id=fake_uuid, filename='test.svg')
|
||||
@@ -591,7 +539,6 @@ def test_create_letter_branding_shows_database_errors_on_name_and_domain_fields(
|
||||
url_for('.create_letter_branding', logo=temp_logo),
|
||||
data={
|
||||
'name': 'my brand',
|
||||
'domain': None,
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
)
|
||||
@@ -600,7 +547,7 @@ def test_create_letter_branding_shows_database_errors_on_name_and_domain_fields(
|
||||
error_message = page.find('span', class_='error-message').text.strip()
|
||||
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
assert error_message == '{} already in use'.format(error_field)
|
||||
assert error_message == 'name already in use'
|
||||
|
||||
|
||||
def test_get_png_file_from_svg(client, mocker, fake_uuid):
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from collections import namedtuple
|
||||
from functools import partial
|
||||
from unittest.mock import ANY, PropertyMock, call
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
@@ -31,6 +30,7 @@ from tests.conftest import (
|
||||
get_non_default_letter_contact_block,
|
||||
get_non_default_reply_to_email_address,
|
||||
get_non_default_sms_sender,
|
||||
mock_get_service_organisation,
|
||||
multiple_letter_contact_blocks,
|
||||
multiple_reply_to_email_addresses,
|
||||
multiple_sms_senders,
|
||||
@@ -101,7 +101,7 @@ def mock_get_service_settings_page_common(
|
||||
'Label Value Action',
|
||||
'Live Off Change',
|
||||
'Count in list of live services Yes Change',
|
||||
'Organisation Org 1 Change',
|
||||
'Organisation Test Organisation Change',
|
||||
'Organisation type Central Change',
|
||||
'Free text message allowance 250,000 Change',
|
||||
'Email branding GOV.UK Change',
|
||||
@@ -616,6 +616,7 @@ def test_should_check_if_estimated_volumes_provided(
|
||||
single_reply_to_email_address,
|
||||
mock_get_service_templates,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_organisation,
|
||||
volumes,
|
||||
consent_to_research,
|
||||
expected_estimated_volumes_item,
|
||||
@@ -675,6 +676,7 @@ def test_should_check_if_estimated_volumes_provided(
|
||||
def test_should_check_for_sending_things_right(
|
||||
client_request,
|
||||
mocker,
|
||||
mock_get_service_organisation,
|
||||
single_sms_sender,
|
||||
count_of_users_with_manage_service,
|
||||
expected_user_checklist_item,
|
||||
@@ -685,7 +687,6 @@ def test_should_check_for_sending_things_right(
|
||||
reply_to_email_addresses,
|
||||
expected_reply_to_checklist_item,
|
||||
):
|
||||
|
||||
def _templates_by_type(template_type):
|
||||
return {
|
||||
'email': list(range(0, count_of_email_templates)),
|
||||
@@ -751,25 +752,22 @@ def test_should_not_show_go_live_button_if_checklist_not_complete(
|
||||
mocker,
|
||||
mock_get_service_templates,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_organisation,
|
||||
single_sms_sender,
|
||||
checklist_completed,
|
||||
agreement_signed,
|
||||
expected_button,
|
||||
):
|
||||
|
||||
def _agreement_info():
|
||||
return namedtuple(
|
||||
'AgreementInfo', ['agreement_signed']
|
||||
)(agreement_signed=agreement_signed)
|
||||
|
||||
mocker.patch(
|
||||
'app.models.service.Service.go_live_checklist_completed',
|
||||
new_callable=PropertyMock,
|
||||
return_value=checklist_completed,
|
||||
)
|
||||
mocker.patch(
|
||||
'app.utils.AgreementInfo.from_current_user',
|
||||
side_effect=_agreement_info,
|
||||
'app.models.organisation.Organisation.agreement_signed',
|
||||
new_callable=PropertyMock,
|
||||
return_value=agreement_signed,
|
||||
create=True,
|
||||
)
|
||||
|
||||
for channel in ('email', 'sms', 'letter'):
|
||||
@@ -894,13 +892,13 @@ def test_should_check_for_sms_sender_on_go_live(
|
||||
client_request,
|
||||
service_one,
|
||||
mocker,
|
||||
mock_get_service_organisation,
|
||||
organisation_type,
|
||||
count_of_sms_templates,
|
||||
sms_senders,
|
||||
expected_sms_sender_checklist_item,
|
||||
estimated_sms_volume,
|
||||
):
|
||||
|
||||
service_one['organisation_type'] = organisation_type
|
||||
|
||||
def _templates_by_type(template_type):
|
||||
@@ -953,18 +951,18 @@ def test_should_check_for_sms_sender_on_go_live(
|
||||
mock_get_sms_senders.assert_called_once_with(SERVICE_ONE_ID)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address, expected_item', (
|
||||
@pytest.mark.parametrize('agreement_signed, expected_item', (
|
||||
pytest.param(
|
||||
'test@unknown.gov.uk',
|
||||
None,
|
||||
'',
|
||||
marks=pytest.mark.xfail(raises=IndexError)
|
||||
),
|
||||
(
|
||||
'test@education.gov.uk',
|
||||
True,
|
||||
'Sign our data sharing and financial agreement Completed',
|
||||
),
|
||||
(
|
||||
'test@aylesbury.gov.uk',
|
||||
False,
|
||||
'Sign our data sharing and financial agreement Not completed',
|
||||
),
|
||||
))
|
||||
@@ -972,7 +970,7 @@ def test_should_check_for_mou_on_request_to_go_live(
|
||||
client_request,
|
||||
service_one,
|
||||
mocker,
|
||||
email_address,
|
||||
agreement_signed,
|
||||
expected_item,
|
||||
):
|
||||
mocker.patch(
|
||||
@@ -1000,9 +998,10 @@ def test_should_check_for_mou_on_request_to_go_live(
|
||||
return_value=None,
|
||||
)
|
||||
|
||||
user = active_user_with_permissions(uuid4())
|
||||
user.email_address = email_address
|
||||
client_request.login(user)
|
||||
mock_get_service_organisation(
|
||||
mocker,
|
||||
agreement_signed=agreement_signed,
|
||||
)
|
||||
|
||||
page = client_request.get(
|
||||
'main.request_to_go_live', service_id=SERVICE_ONE_ID
|
||||
@@ -1017,6 +1016,7 @@ def test_non_gov_user_is_told_they_cant_go_live(
|
||||
client_request,
|
||||
api_nongov_user_active,
|
||||
mocker,
|
||||
mock_get_service_organisation,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.main.views.service_settings.user_api_client.get_count_of_users_with_permission',
|
||||
@@ -1287,7 +1287,6 @@ def test_should_redirect_after_request_to_go_live(
|
||||
active_user_with_permissions,
|
||||
single_reply_to_email_address,
|
||||
single_letter_contact_block,
|
||||
mock_get_service_organisation,
|
||||
mock_get_organisations_and_services_for_user,
|
||||
single_sms_sender,
|
||||
mock_get_service_settings_page_common,
|
||||
@@ -1298,6 +1297,11 @@ def test_should_redirect_after_request_to_go_live(
|
||||
formatted_displayed_volumes,
|
||||
extra_tags,
|
||||
):
|
||||
mock_get_service_organisation(
|
||||
mocker,
|
||||
name=None,
|
||||
agreement_signed=None,
|
||||
)
|
||||
for channel, volume in volumes:
|
||||
mocker.patch(
|
||||
'app.models.service.Service.volume_{}'.format(channel),
|
||||
@@ -1516,6 +1520,11 @@ def test_ready_to_go_live(
|
||||
agreement_signed,
|
||||
expected_tags,
|
||||
):
|
||||
mock_get_service_organisation(
|
||||
mocker,
|
||||
agreement_signed=agreement_signed,
|
||||
)
|
||||
|
||||
for prop in {
|
||||
'has_team_members',
|
||||
'has_templates',
|
||||
@@ -1546,10 +1555,9 @@ def test_ready_to_go_live(
|
||||
'id': SERVICE_ONE_ID
|
||||
}).go_live_checklist_completed_as_yes_no == expected_readyness
|
||||
|
||||
assert list(app.main.views.service_settings._get_request_to_go_live_tags(
|
||||
app.models.service.Service({'id': SERVICE_ONE_ID}),
|
||||
agreement_signed,
|
||||
)) == expected_tags
|
||||
assert app.models.service.Service(
|
||||
{'id': SERVICE_ONE_ID}
|
||||
).request_to_go_live_tags == expected_tags
|
||||
|
||||
|
||||
@pytest.mark.parametrize('route', [
|
||||
@@ -3966,6 +3974,10 @@ def test_show_email_branding_request_page_when_email_branding_is_set(
|
||||
('org_banner', 'Your logo on a colour'),
|
||||
pytest.param('foo', 'Nope', marks=pytest.mark.xfail(raises=AssertionError)),
|
||||
))
|
||||
@pytest.mark.parametrize('org_name, expected_organisation', (
|
||||
(None, 'Can’t tell (domain is user.gov.uk)'),
|
||||
('Test Organisation', 'Test Organisation'),
|
||||
))
|
||||
def test_submit_email_branding_request(
|
||||
client_request,
|
||||
mocker,
|
||||
@@ -3974,10 +3986,16 @@ def test_submit_email_branding_request(
|
||||
mock_get_service_settings_page_common,
|
||||
no_reply_to_email_addresses,
|
||||
no_letter_contact_blocks,
|
||||
mock_get_service_organisation,
|
||||
single_sms_sender,
|
||||
org_name,
|
||||
expected_organisation,
|
||||
):
|
||||
|
||||
mock_get_service_organisation(
|
||||
mocker,
|
||||
name=org_name,
|
||||
)
|
||||
|
||||
zendesk = mocker.patch(
|
||||
'app.main.views.service_settings.zendesk_client.create_ticket',
|
||||
autospec=True,
|
||||
@@ -3993,14 +4011,14 @@ def test_submit_email_branding_request(
|
||||
|
||||
zendesk.assert_called_once_with(
|
||||
message='\n'.join([
|
||||
'Organisation: Can’t tell (domain is user.gov.uk)',
|
||||
'Organisation: {}',
|
||||
'Service: service one',
|
||||
'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb',
|
||||
'',
|
||||
'---',
|
||||
'Current branding: GOV.UK',
|
||||
'Branding requested: {}',
|
||||
]).format(requested_branding),
|
||||
]).format(expected_organisation, requested_branding),
|
||||
subject='Email branding request - service one',
|
||||
ticket_type='question',
|
||||
user_email='test@user.gov.uk',
|
||||
|
||||
@@ -53,13 +53,13 @@ def test_get_all_email_branding(mocker):
|
||||
|
||||
def test_create_email_branding(mocker):
|
||||
org_data = {'logo': 'test.png', 'name': 'test name', 'text': 'test name', 'colour': 'red',
|
||||
'domain': 'sample.com', 'brand_type': 'org'}
|
||||
'brand_type': 'org'}
|
||||
|
||||
mock_post = mocker.patch('app.notify_client.email_branding_client.EmailBrandingClient.post')
|
||||
mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete')
|
||||
EmailBrandingClient().create_email_branding(
|
||||
logo=org_data['logo'], name=org_data['name'], text=org_data['text'], colour=org_data['colour'],
|
||||
domain=org_data['domain'], brand_type='org'
|
||||
brand_type='org'
|
||||
)
|
||||
|
||||
mock_post.assert_called_once_with(
|
||||
@@ -72,13 +72,13 @@ def test_create_email_branding(mocker):
|
||||
|
||||
def test_update_email_branding(mocker, fake_uuid):
|
||||
org_data = {'logo': 'test.png', 'name': 'test name', 'text': 'test name', 'colour': 'red',
|
||||
'domain': 'sample.com', 'brand_type': 'org'}
|
||||
'brand_type': 'org'}
|
||||
|
||||
mock_post = mocker.patch('app.notify_client.email_branding_client.EmailBrandingClient.post')
|
||||
mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete')
|
||||
EmailBrandingClient().update_email_branding(
|
||||
branding_id=fake_uuid, logo=org_data['logo'], name=org_data['name'], text=org_data['text'],
|
||||
colour=org_data['colour'], domain=org_data['domain'], brand_type='org')
|
||||
colour=org_data['colour'], brand_type='org')
|
||||
|
||||
mock_post.assert_called_once_with(
|
||||
url='/email-branding/{}'.format(fake_uuid),
|
||||
|
||||
@@ -39,13 +39,13 @@ def test_get_all_letter_branding(mocker):
|
||||
|
||||
|
||||
def test_create_letter_branding(mocker):
|
||||
new_branding = {'filename': 'uuid-test', 'name': 'my letters', 'domain': 'example.com'}
|
||||
new_branding = {'filename': 'uuid-test', 'name': 'my letters'}
|
||||
|
||||
mock_post = mocker.patch('app.notify_client.letter_branding_client.LetterBrandingClient.post')
|
||||
mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete')
|
||||
|
||||
LetterBrandingClient().create_letter_branding(
|
||||
filename=new_branding['filename'], name=new_branding['name'], domain=new_branding['domain']
|
||||
filename=new_branding['filename'], name=new_branding['name'],
|
||||
)
|
||||
mock_post.assert_called_once_with(
|
||||
url='/letter-branding',
|
||||
@@ -56,12 +56,12 @@ def test_create_letter_branding(mocker):
|
||||
|
||||
|
||||
def test_update_letter_branding(mocker, fake_uuid):
|
||||
branding = {'filename': 'uuid-test', 'name': 'my letters', 'domain': 'example.com'}
|
||||
branding = {'filename': 'uuid-test', 'name': 'my letters'}
|
||||
|
||||
mock_post = mocker.patch('app.notify_client.letter_branding_client.LetterBrandingClient.post')
|
||||
mock_redis_delete = mocker.patch('app.extensions.RedisClient.delete')
|
||||
LetterBrandingClient().update_letter_branding(
|
||||
branding_id=fake_uuid, filename=branding['filename'], name=branding['name'], domain=branding['domain'])
|
||||
branding_id=fake_uuid, filename=branding['filename'], name=branding['name'])
|
||||
|
||||
mock_post.assert_called_once_with(
|
||||
url='/letter-branding/{}'.format(fake_uuid),
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
from collections import Counter, OrderedDict
|
||||
from collections import OrderedDict
|
||||
from csv import DictReader
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from freezegun import freeze_time
|
||||
from notifications_utils.recipients import validate_email_address
|
||||
|
||||
from app import format_datetime_relative
|
||||
from app.utils import (
|
||||
AgreementInfo,
|
||||
GovernmentEmailDomain,
|
||||
Spreadsheet,
|
||||
email_safe,
|
||||
generate_next_dict,
|
||||
@@ -292,159 +289,6 @@ def test_get_cdn_domain_on_non_localhost(client, mocker):
|
||||
assert domain == 'static-logos.admintest.com'
|
||||
|
||||
|
||||
@pytest.mark.parametrize("domain_or_email_address", (
|
||||
"test@dclgdatamart.co.uk", "test@communities.gsi.gov.uk", "test@communities.gov.uk",
|
||||
))
|
||||
def test_get_valid_agreement_info_known_details(domain_or_email_address):
|
||||
agreement_info = AgreementInfo(domain_or_email_address)
|
||||
assert agreement_info.crown_status is None
|
||||
assert agreement_info.owner == "Ministry of Housing, Communities & Local Government"
|
||||
assert agreement_info.agreement_signed is True
|
||||
assert agreement_info.as_human_readable == (
|
||||
'Yes, on behalf of Ministry of Housing, Communities & Local Government'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("domain_or_email_address", (
|
||||
"test@dwp.gov.uk", "test@dwp.gsi.gov.uk",
|
||||
))
|
||||
def test_dwp_go_live_requests_are_flagged(domain_or_email_address):
|
||||
agreement_info = AgreementInfo(domain_or_email_address)
|
||||
assert agreement_info.owner == "Department for Work and Pensions"
|
||||
assert agreement_info.agreement_signed is True
|
||||
assert agreement_info.as_human_readable == (
|
||||
'DWP - Requires OED approval'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("domain_or_email_address, is_canonical", (
|
||||
("test@dclgdatamart.co.uk", False),
|
||||
("test@communities.gsi.gov.uk", False),
|
||||
("test@communities.gov.uk", True),
|
||||
))
|
||||
def test_get_canonical_domain(domain_or_email_address, is_canonical):
|
||||
assert AgreementInfo(domain_or_email_address).canonical_domain == 'communities.gov.uk'
|
||||
assert AgreementInfo(domain_or_email_address).is_canonical == is_canonical
|
||||
|
||||
|
||||
def test_get_canonical_domain_passes_through_unknown_domain():
|
||||
assert AgreementInfo('example.com').canonical_domain is None
|
||||
assert AgreementInfo('example.com').is_canonical is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize("domain_or_email_address", (
|
||||
"test@police.gov.uk", "police.gov.uk",
|
||||
))
|
||||
def test_get_valid_agreement_info_unknown_details(domain_or_email_address):
|
||||
government_domain = AgreementInfo(domain_or_email_address)
|
||||
assert government_domain.crown_status is None
|
||||
assert government_domain.owner is None
|
||||
assert government_domain.agreement_signed is None
|
||||
assert government_domain.as_human_readable == 'Can’t tell (domain is police.gov.uk)'
|
||||
|
||||
|
||||
def test_get_valid_agreement_info_only_org_known():
|
||||
agreement_info = AgreementInfo('nhs.net')
|
||||
# Some parts of the NHS are Crown, some aren’t
|
||||
assert agreement_info.crown_status is None
|
||||
assert agreement_info.owner == 'NHS'
|
||||
assert agreement_info.agreement_signed is None
|
||||
assert agreement_info.as_human_readable == 'Can’t tell (organisation is NHS, crown status unknown)'
|
||||
|
||||
|
||||
def test_get_valid_agreement_info_some_known_details():
|
||||
agreement_info = AgreementInfo("marinemanagement.org.uk")
|
||||
assert agreement_info.crown_status is None
|
||||
assert agreement_info.owner == "Marine Management Organisation"
|
||||
assert agreement_info.agreement_signed is True
|
||||
assert agreement_info.as_human_readable == (
|
||||
'Yes, on behalf of Marine Management Organisation'
|
||||
)
|
||||
|
||||
|
||||
def test_get_valid_local_agreement_info_some_known_details():
|
||||
# This example may need to be updated to use a different council if
|
||||
# Babergh every sign the agreement
|
||||
agreement_info = AgreementInfo("babergh.gov.uk")
|
||||
assert agreement_info.crown_status is False
|
||||
assert agreement_info.owner == "Babergh District Council"
|
||||
assert agreement_info.agreement_signed is False
|
||||
assert agreement_info.as_human_readable == (
|
||||
'No (organisation is Babergh District Council, a non-crown body)'
|
||||
)
|
||||
|
||||
|
||||
def test_get_valid_government_domain_gets_most_specific_first():
|
||||
|
||||
generic = AgreementInfo("gov.uk")
|
||||
assert generic.crown_status is None
|
||||
assert generic.owner is None
|
||||
assert generic.agreement_signed is None
|
||||
assert generic.as_human_readable == (
|
||||
'Can’t tell (domain is gov.uk)'
|
||||
)
|
||||
|
||||
specific = AgreementInfo("dacorum.gov.uk")
|
||||
assert specific.crown_status is False
|
||||
assert specific.owner == 'Dacorum Borough Council'
|
||||
assert specific.agreement_signed is True
|
||||
assert specific.as_human_readable == (
|
||||
'Yes, on behalf of Dacorum Borough Council'
|
||||
)
|
||||
|
||||
|
||||
def test_get_domain_info_for_branding_request():
|
||||
|
||||
assert AgreementInfo("gov.uk").as_info_for_branding_request == (
|
||||
'Can’t tell (domain is gov.uk)'
|
||||
)
|
||||
assert AgreementInfo("dacorum.gov.uk").as_info_for_branding_request == (
|
||||
'Dacorum Borough Council'
|
||||
)
|
||||
|
||||
|
||||
def test_domains_are_lowercased():
|
||||
for domain in AgreementInfo.domains.keys():
|
||||
assert domain == domain.lower()
|
||||
|
||||
|
||||
def test_validate_government_domain_data():
|
||||
|
||||
for domain in AgreementInfo.domains.keys():
|
||||
|
||||
validate_email_address('test@{}'.format(domain))
|
||||
|
||||
agreement_info = AgreementInfo(domain)
|
||||
|
||||
assert agreement_info.crown_status in {
|
||||
True, False, None
|
||||
}
|
||||
|
||||
assert isinstance(agreement_info.owner, str) and agreement_info.owner.strip()
|
||||
|
||||
assert agreement_info.agreement_signed in {
|
||||
True, False, None
|
||||
}
|
||||
|
||||
|
||||
def test_domain_data_is_canonicalized():
|
||||
for owner, count in Counter(
|
||||
AgreementInfo(domain).owner
|
||||
for domain in AgreementInfo.domains.keys()
|
||||
if AgreementInfo(domain).is_canonical
|
||||
).most_common():
|
||||
if count > 1:
|
||||
raise ValueError(
|
||||
'{} entries in domains.yml for {}'.format(count, owner)
|
||||
)
|
||||
|
||||
|
||||
def test_validate_email_domain_data():
|
||||
|
||||
for domain in GovernmentEmailDomain.domains.keys():
|
||||
validate_email_address('test@{}'.format(domain))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('time, human_readable_datetime', [
|
||||
('2018-03-14 09:00', '14 March at 9:00am'),
|
||||
('2018-03-14 15:00', '14 March at 3:00pm'),
|
||||
|
||||
Reference in New Issue
Block a user