Remove dependence on domains.yml from settings

Settings looked at `domains.yml` when users were making go live requests
or email branding requests.

This will allow us to remove the `domains.yml` file, by using
information about organisations that is now stored in the database
instead.
This commit is contained in:
Chris Hill-Scott
2019-04-04 11:23:40 +01:00
parent 835d11d8d6
commit 3565ffc33f
6 changed files with 72 additions and 54 deletions

View File

@@ -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',
@@ -1547,8 +1556,7 @@ def test_ready_to_go_live(
}).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,
app.models.service.Service({'id': SERVICE_ONE_ID})
)) == expected_tags
@@ -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, 'Cant 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: Cant 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',