notify-api-412 use black to enforce python coding style

This commit is contained in:
Kenneth Kehl
2023-08-25 09:12:23 -07:00
parent c6eb007386
commit 8c9721d8e2
201 changed files with 31660 additions and 28105 deletions

View File

@@ -8,11 +8,17 @@ from tests import sample_uuid
from tests.conftest import ORGANISATION_ID, SERVICE_ONE_ID, normalize_spaces
@pytest.mark.parametrize('organization_type, expected_options', (
('other', [
('something_else', 'Something else'),
]),
))
@pytest.mark.parametrize(
"organization_type, expected_options",
(
(
"other",
[
("something_else", "Something else"),
],
),
),
)
def test_email_branding_request_page_when_no_branding_is_set(
service_one,
client_request,
@@ -21,33 +27,33 @@ def test_email_branding_request_page_when_no_branding_is_set(
organization_type,
expected_options,
):
service_one['email_branding'] = None
service_one['organization_type'] = organization_type
service_one["email_branding"] = None
service_one["organization_type"] = organization_type
mocker.patch(
'app.models.service.Service.email_branding_id',
"app.models.service.Service.email_branding_id",
new_callable=PropertyMock,
return_value=None,
)
page = client_request.get(
'.email_branding_request', service_id=SERVICE_ONE_ID
)
page = client_request.get(".email_branding_request", service_id=SERVICE_ONE_ID)
assert mock_get_email_branding.called is False
assert page.find_all('iframe')[1]['src'] == url_for('main.email_template', branding_style='__NONE__')
assert page.find_all("iframe")[1]["src"] == url_for(
"main.email_template", branding_style="__NONE__"
)
button_text = normalize_spaces(page.select_one('.page-footer button').text)
button_text = normalize_spaces(page.select_one(".page-footer button").text)
assert [
(
radio['value'],
page.select_one('label[for={}]'.format(radio['id'])).text.strip()
radio["value"],
page.select_one("label[for={}]".format(radio["id"])).text.strip(),
)
for radio in page.select('input[type=radio]')
for radio in page.select("input[type=radio]")
] == expected_options
assert button_text == 'Continue'
assert button_text == "Continue"
def test_email_branding_request_page_shows_branding_if_set(
@@ -58,52 +64,53 @@ def test_email_branding_request_page_shows_branding_if_set(
mock_get_service_organization,
):
mocker.patch(
'app.models.service.Service.email_branding_id',
"app.models.service.Service.email_branding_id",
new_callable=PropertyMock,
return_value='some-random-branding',
return_value="some-random-branding",
)
page = client_request.get(
'.email_branding_request', service_id=SERVICE_ONE_ID
page = client_request.get(".email_branding_request", service_id=SERVICE_ONE_ID)
assert page.find_all("iframe")[1]["src"] == url_for(
"main.email_template", branding_style="some-random-branding"
)
assert page.find_all('iframe')[1]['src'] == url_for('main.email_template', branding_style='some-random-branding')
def test_email_branding_request_page_back_link(
client_request,
):
page = client_request.get(
'.email_branding_request', service_id=SERVICE_ONE_ID
)
page = client_request.get(".email_branding_request", service_id=SERVICE_ONE_ID)
back_link = page.select_one('a.usa-back-link')
back_link = page.select_one("a.usa-back-link")
assert len(back_link) > 0, "No back link found on the page"
assert back_link['href'] == url_for('.service_settings', service_id=SERVICE_ONE_ID)
assert back_link["href"] == url_for(".service_settings", service_id=SERVICE_ONE_ID)
@pytest.mark.parametrize('data, org_type, endpoint', (
@pytest.mark.parametrize(
"data, org_type, endpoint",
(
{
'options': 'govuk',
},
'federal',
'main.email_branding_govuk',
(
{
"options": "govuk",
},
"federal",
"main.email_branding_govuk",
),
(
{
"options": "govuk_and_org",
},
"federal",
"main.email_branding_govuk_and_org",
),
(
{
"options": "something_else",
},
"federal",
"main.email_branding_something_else",
),
),
(
{
'options': 'govuk_and_org',
},
'federal',
'main.email_branding_govuk_and_org',
),
(
{
'options': 'something_else',
},
'federal',
'main.email_branding_something_else',
),
))
)
def test_email_branding_request_submit(
client_request,
service_one,
@@ -114,24 +121,24 @@ def test_email_branding_request_submit(
org_type,
endpoint,
):
organization_one['organization_type'] = org_type
service_one['email_branding'] = sample_uuid()
service_one['organization'] = organization_one
organization_one["organization_type"] = org_type
service_one["email_branding"] = sample_uuid()
service_one["organization"] = organization_one
mocker.patch(
'app.organizations_client.get_organization',
"app.organizations_client.get_organization",
return_value=organization_one,
)
client_request.post(
'.email_branding_request',
".email_branding_request",
service_id=SERVICE_ONE_ID,
_data=data,
_expected_status=302,
_expected_redirect=url_for(
endpoint,
service_id=SERVICE_ONE_ID,
)
),
)
@@ -140,20 +147,26 @@ def test_email_branding_request_submit_when_no_radio_button_is_selected(
service_one,
mock_get_email_branding,
):
service_one['email_branding'] = sample_uuid()
service_one["email_branding"] = sample_uuid()
page = client_request.post(
'.email_branding_request', service_id=SERVICE_ONE_ID,
_data={'options': ''},
".email_branding_request",
service_id=SERVICE_ONE_ID,
_data={"options": ""},
_follow_redirects=True,
)
assert page.h1.text == 'Change email branding'
assert normalize_spaces(page.select_one('.error-message').text) == 'Select an option'
assert page.h1.text == "Change email branding"
assert (
normalize_spaces(page.select_one(".error-message").text) == "Select an option"
)
@pytest.mark.parametrize('endpoint, expected_heading', [
('main.email_branding_govuk_and_org', 'Before you request new branding'),
])
@pytest.mark.parametrize(
"endpoint, expected_heading",
[
("main.email_branding_govuk_and_org", "Before you request new branding"),
],
)
def test_email_branding_description_pages_for_org_branding(
client_request,
mocker,
@@ -163,11 +176,11 @@ def test_email_branding_description_pages_for_org_branding(
endpoint,
expected_heading,
):
service_one['email_branding'] = sample_uuid()
service_one['organization'] = organization_one
service_one["email_branding"] = sample_uuid()
service_one["organization"] = organization_one
mocker.patch(
'app.organizations_client.get_organization',
"app.organizations_client.get_organization",
return_value=organization_one,
)
@@ -176,14 +189,20 @@ def test_email_branding_description_pages_for_org_branding(
service_id=SERVICE_ONE_ID,
)
assert page.h1.text == expected_heading
assert normalize_spaces(page.select_one('.page-footer button').text) == 'Request new branding'
assert (
normalize_spaces(page.select_one(".page-footer button").text)
== "Request new branding"
)
@pytest.mark.parametrize('endpoint, service_org_type, branding_preview_id', [
('main.email_branding_govuk', 'central', '__NONE__'),
# ('main.email_branding_nhs', 'nhs_local', NHS_EMAIL_BRANDING_ID),
])
@pytest.mark.skip(reason='Update for TTS')
@pytest.mark.parametrize(
"endpoint, service_org_type, branding_preview_id",
[
("main.email_branding_govuk", "central", "__NONE__"),
# ('main.email_branding_nhs', 'nhs_local', NHS_EMAIL_BRANDING_ID),
],
)
@pytest.mark.skip(reason="Update for TTS")
def test_email_branding_govuk_and_nhs_pages(
client_request,
mocker,
@@ -194,12 +213,12 @@ def test_email_branding_govuk_and_nhs_pages(
service_org_type,
branding_preview_id,
):
organization_one['organization_type'] = service_org_type
service_one['email_branding'] = sample_uuid()
service_one['organization'] = organization_one
organization_one["organization_type"] = service_org_type
service_one["email_branding"] = sample_uuid()
service_one["organization"] = organization_one
mocker.patch(
'app.organizations_client.get_organization',
"app.organizations_client.get_organization",
return_value=organization_one,
)
@@ -207,60 +226,71 @@ def test_email_branding_govuk_and_nhs_pages(
endpoint,
service_id=SERVICE_ONE_ID,
)
assert page.h1.text == 'Check your new branding'
assert 'Emails from service one will look like this' in normalize_spaces(page.text)
assert page.find('iframe')['src'] == url_for('main.email_template', branding_style=branding_preview_id)
assert normalize_spaces(page.select_one('.page-footer button').text) == 'Use this branding'
assert page.h1.text == "Check your new branding"
assert "Emails from service one will look like this" in normalize_spaces(page.text)
assert page.find("iframe")["src"] == url_for(
"main.email_template", branding_style=branding_preview_id
)
assert (
normalize_spaces(page.select_one(".page-footer button").text)
== "Use this branding"
)
@pytest.mark.skip(reason='Update for TTS')
@pytest.mark.skip(reason="Update for TTS")
def test_email_branding_something_else_page(client_request, service_one):
# expect to have a "NHS" option as well as the
# fallback, so back button goes to choices page
service_one['organization_type'] = 'nhs_central'
service_one["organization_type"] = "nhs_central"
page = client_request.get(
'main.email_branding_something_else',
"main.email_branding_something_else",
service_id=SERVICE_ONE_ID,
)
assert normalize_spaces(page.h1.text) == 'Describe the branding you want'
assert page.select_one('textarea')['name'] == ('something_else')
assert normalize_spaces(page.select_one('.page-footer button').text) == 'Request new branding'
assert page.select_one('.usa-back-link')['href'] == url_for(
'main.email_branding_request', service_id=SERVICE_ONE_ID,
assert normalize_spaces(page.h1.text) == "Describe the branding you want"
assert page.select_one("textarea")["name"] == ("something_else")
assert (
normalize_spaces(page.select_one(".page-footer button").text)
== "Request new branding"
)
assert page.select_one(".usa-back-link")["href"] == url_for(
"main.email_branding_request",
service_id=SERVICE_ONE_ID,
)
def test_get_email_branding_something_else_page_is_only_option(client_request, service_one):
def test_get_email_branding_something_else_page_is_only_option(
client_request, service_one
):
# should only have a "something else" option
# so back button goes back to settings page
service_one['organization_type'] = 'other'
service_one["organization_type"] = "other"
page = client_request.get(
'main.email_branding_something_else',
"main.email_branding_something_else",
service_id=SERVICE_ONE_ID,
)
assert page.select_one('.usa-back-link')['href'] == url_for(
'main.service_settings', service_id=SERVICE_ONE_ID,
assert page.select_one(".usa-back-link")["href"] == url_for(
"main.service_settings",
service_id=SERVICE_ONE_ID,
)
@pytest.mark.parametrize('endpoint', [
('main.email_branding_govuk'),
('main.email_branding_govuk_and_org'),
('main.email_branding_organization'),
])
@pytest.mark.parametrize(
"endpoint",
[
("main.email_branding_govuk"),
("main.email_branding_govuk_and_org"),
("main.email_branding_organization"),
],
)
def test_email_branding_pages_give_404_if_selected_branding_not_allowed(
client_request,
endpoint,
):
# The only email branding allowed is 'something_else', so trying to visit any of the other
# endpoints gives a 404 status code.
client_request.get(
endpoint,
service_id=SERVICE_ONE_ID,
_expected_status=404
)
client_request.get(endpoint, service_id=SERVICE_ONE_ID, _expected_status=404)
def test_email_branding_govuk_submit(
@@ -274,18 +304,18 @@ def test_email_branding_govuk_submit(
mock_update_service,
):
mocker.patch(
'app.organizations_client.get_organization',
"app.organizations_client.get_organization",
return_value=organization_one,
)
mocker.patch(
'app.models.service.Service.organization_id',
"app.models.service.Service.organization_id",
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
service_one['email_branding'] = sample_uuid()
service_one["email_branding"] = sample_uuid()
page = client_request.post(
'.email_branding_govuk',
".email_branding_govuk",
service_id=SERVICE_ONE_ID,
_follow_redirects=True,
)
@@ -294,11 +324,14 @@ def test_email_branding_govuk_submit(
SERVICE_ONE_ID,
email_branding=None,
)
assert page.h1.text == 'Settings'
assert normalize_spaces(page.select_one('.banner-default').text) == 'Youve updated your email branding'
assert page.h1.text == "Settings"
assert (
normalize_spaces(page.select_one(".banner-default").text)
== "Youve updated your email branding"
)
@pytest.mark.skip(reason='Update for TTS')
@pytest.mark.skip(reason="Update for TTS")
def test_email_branding_govuk_and_org_submit(
mocker,
client_request,
@@ -309,55 +342,57 @@ def test_email_branding_govuk_and_org_submit(
single_sms_sender,
):
mocker.patch(
'app.organizations_client.get_organization',
"app.organizations_client.get_organization",
return_value=organization_one,
)
mocker.patch(
'app.models.service.Service.organization_id',
"app.models.service.Service.organization_id",
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
service_one['email_branding'] = sample_uuid()
service_one["email_branding"] = sample_uuid()
mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
mock_create_ticket = mocker.spy(NotifySupportTicket, "__init__")
mock_send_ticket_to_zendesk = mocker.patch(
'app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk',
"app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk",
autospec=True,
)
page = client_request.post(
'.email_branding_govuk_and_org',
".email_branding_govuk_and_org",
service_id=SERVICE_ONE_ID,
_follow_redirects=True,
)
mock_create_ticket.assert_called_once_with(
ANY,
message='\n'.join([
'Organization: organization one',
'Service: service one',
'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb',
'',
'---',
'Current branding: Organization name',
'Branding requested: GOV.UK and organization one\n',
]),
subject='Email branding request - service one',
ticket_type='question',
user_name='Test User',
user_email='test@user.gsa.gov',
message="\n".join(
[
"Organization: organization one",
"Service: service one",
"http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb",
"",
"---",
"Current branding: Organization name",
"Branding requested: GOV.UK and organization one\n",
]
),
subject="Email branding request - service one",
ticket_type="question",
user_name="Test User",
user_email="test@user.gsa.gov",
org_id=ORGANISATION_ID,
org_type='central',
service_id=SERVICE_ONE_ID
org_type="central",
service_id=SERVICE_ONE_ID,
)
mock_send_ticket_to_zendesk.assert_called_once()
assert normalize_spaces(page.select_one('.banner-default').text) == (
'Thanks for your branding request. Well get back to you '
'within one working day.'
assert normalize_spaces(page.select_one(".banner-default").text) == (
"Thanks for your branding request. Well get back to you "
"within one working day."
)
@pytest.mark.skip(reason='Update for TTS')
@pytest.mark.skip(reason="Update for TTS")
def test_email_branding_organization_submit(
mocker,
client_request,
@@ -368,51 +403,53 @@ def test_email_branding_organization_submit(
single_sms_sender,
):
mocker.patch(
'app.organizations_client.get_organization',
"app.organizations_client.get_organization",
return_value=organization_one,
)
mocker.patch(
'app.models.service.Service.organization_id',
"app.models.service.Service.organization_id",
new_callable=PropertyMock,
return_value=ORGANISATION_ID,
)
service_one['email_branding'] = sample_uuid()
service_one["email_branding"] = sample_uuid()
mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
mock_create_ticket = mocker.spy(NotifySupportTicket, "__init__")
mock_send_ticket_to_zendesk = mocker.patch(
'app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk',
"app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk",
autospec=True,
)
page = client_request.post(
'.email_branding_organization',
".email_branding_organization",
service_id=SERVICE_ONE_ID,
_follow_redirects=True,
)
mock_create_ticket.assert_called_once_with(
ANY,
message='\n'.join([
'Organization: organization one',
'Service: service one',
'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb',
'',
'---',
'Current branding: Organization name',
'Branding requested: organization one\n',
]),
subject='Email branding request - service one',
ticket_type='question',
user_name='Test User',
user_email='test@user.gsa.gov',
message="\n".join(
[
"Organization: organization one",
"Service: service one",
"http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb",
"",
"---",
"Current branding: Organization name",
"Branding requested: organization one\n",
]
),
subject="Email branding request - service one",
ticket_type="question",
user_name="Test User",
user_email="test@user.gsa.gov",
org_id=ORGANISATION_ID,
org_type='central',
service_id=SERVICE_ONE_ID
org_type="central",
service_id=SERVICE_ONE_ID,
)
mock_send_ticket_to_zendesk.assert_called_once()
assert normalize_spaces(page.select_one('.banner-default').text) == (
'Thanks for your branding request. Well get back to you '
'within one working day.'
assert normalize_spaces(page.select_one(".banner-default").text) == (
"Thanks for your branding request. Well get back to you "
"within one working day."
)
@@ -424,46 +461,48 @@ def test_email_branding_something_else_submit(
mock_get_email_branding,
single_sms_sender,
):
service_one['email_branding'] = sample_uuid()
service_one['organization_type'] = 'nhs_local'
service_one["email_branding"] = sample_uuid()
service_one["organization_type"] = "nhs_local"
mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
mock_create_ticket = mocker.spy(NotifySupportTicket, "__init__")
mock_send_ticket_to_zendesk = mocker.patch(
'app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk',
"app.main.views.service_settings.zendesk_client.send_ticket_to_zendesk",
autospec=True,
)
page = client_request.post(
'.email_branding_something_else',
".email_branding_something_else",
service_id=SERVICE_ONE_ID,
_data={'something_else': 'Homer Simpson'},
_data={"something_else": "Homer Simpson"},
_follow_redirects=True,
)
mock_create_ticket.assert_called_once_with(
ANY,
message='\n'.join([
'Organization: Cant tell (domain is user.gsa.gov)',
'Service: service one',
'http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb',
'',
'---',
'Current branding: Organization name',
'Branding requested: Something else\n',
'Homer Simpson\n'
]),
subject='Email branding request - service one',
ticket_type='question',
user_name='Test User',
user_email='test@user.gsa.gov',
message="\n".join(
[
"Organization: Cant tell (domain is user.gsa.gov)",
"Service: service one",
"http://localhost/services/596364a0-858e-42c8-9062-a8fe822260eb",
"",
"---",
"Current branding: Organization name",
"Branding requested: Something else\n",
"Homer Simpson\n",
]
),
subject="Email branding request - service one",
ticket_type="question",
user_name="Test User",
user_email="test@user.gsa.gov",
org_id=None,
org_type='nhs_local',
service_id=SERVICE_ONE_ID
org_type="nhs_local",
service_id=SERVICE_ONE_ID,
)
mock_send_ticket_to_zendesk.assert_called_once()
assert normalize_spaces(page.select_one('.banner-default').text) == (
'Thanks for your branding request. Well get back to you '
'within one working day.'
assert normalize_spaces(page.select_one(".banner-default").text) == (
"Thanks for your branding request. Well get back to you "
"within one working day."
)
@@ -471,10 +510,13 @@ def test_email_branding_something_else_submit_shows_error_if_textbox_is_empty(
client_request,
):
page = client_request.post(
'.email_branding_something_else',
".email_branding_something_else",
service_id=SERVICE_ONE_ID,
_data={'something_else': ''},
_data={"something_else": ""},
_follow_redirects=True,
)
assert normalize_spaces(page.h1.text) == 'Describe the branding you want'
assert normalize_spaces(page.select_one('.usa-error-message').text) == 'Error: Cannot be empty'
assert normalize_spaces(page.h1.text) == "Describe the branding you want"
assert (
normalize_spaces(page.select_one(".usa-error-message").text)
== "Error: Cannot be empty"
)

View File

@@ -7,15 +7,15 @@ def test_set_inbound_sms_sets_a_number_for_service(
multiple_available_inbound_numbers,
fake_uuid,
mock_no_inbound_number_for_service,
mocker
mocker,
):
mocker.patch('app.service_api_client.update_service')
mocker.patch("app.service_api_client.update_service")
data = {
"inbound_number": "781d9c60-7a7e-46b7-9896-7b045b992fa5",
}
client_request.post(
'main.service_set_inbound_number',
"main.service_set_inbound_number",
service_id=SERVICE_ONE_ID,
_data=data,
_expected_status=302,
@@ -25,23 +25,25 @@ def test_set_inbound_sms_sets_a_number_for_service(
SERVICE_ONE_ID,
sms_sender="781d9c60-7a7e-46b7-9896-7b045b992fa5",
is_default=True,
inbound_number_id="781d9c60-7a7e-46b7-9896-7b045b992fa5"
inbound_number_id="781d9c60-7a7e-46b7-9896-7b045b992fa5",
)
def test_set_inbound_sms_when_no_available_inbound_numbers(
client_request,
service_one,
no_available_inbound_numbers,
mock_no_inbound_number_for_service,
mocker
client_request,
service_one,
no_available_inbound_numbers,
mock_no_inbound_number_for_service,
mocker,
):
page = client_request.get(
'main.service_set_inbound_number',
service_id=service_one['id']
"main.service_set_inbound_number", service_id=service_one["id"]
)
assert normalize_spaces(page.select_one('main p').text) == "No available inbound numbers"
assert (
normalize_spaces(page.select_one("main p").text)
== "No available inbound numbers"
)
def test_set_inbound_sms_when_service_already_has_sms(
@@ -50,13 +52,14 @@ def test_set_inbound_sms_when_service_already_has_sms(
multiple_available_inbound_numbers,
mock_get_inbound_number_for_service,
):
page = client_request.get(
'main.service_set_inbound_number',
service_id=service_one['id']
"main.service_set_inbound_number", service_id=service_one["id"]
)
assert normalize_spaces(page.select_one('main p').text) == "This service already has an inbound number"
assert (
normalize_spaces(page.select_one("main p").text)
== "This service already has an inbound number"
)
def test_set_inbound_sms_when_service_does_not_have_sms(
@@ -65,10 +68,8 @@ def test_set_inbound_sms_when_service_does_not_have_sms(
multiple_available_inbound_numbers,
mock_no_inbound_number_for_service,
):
page = client_request.get(
'main.service_set_inbound_number',
service_id=service_one['id']
"main.service_set_inbound_number", service_id=service_one["id"]
)
assert normalize_spaces(page.select_one('input')['name']) == "inbound_number"
assert normalize_spaces(page.select_one("input")["name"]) == "inbound_number"

View File

@@ -20,7 +20,9 @@ def get_service_settings_page(
mock_get_service_data_retention,
):
client_request.login(platform_admin_user)
return functools.partial(client_request.get, 'main.service_settings', service_id=service_one['id'])
return functools.partial(
client_request.get, "main.service_settings", service_id=service_one["id"]
)
def test_service_set_permission_requires_platform_admin(
@@ -30,38 +32,43 @@ def test_service_set_permission_requires_platform_admin(
mock_get_inbound_number_for_service,
):
client_request.post(
'main.service_set_permission', service_id=service_one['id'], permission='email_auth',
_data={'enabled': 'True'},
_expected_status=403
"main.service_set_permission",
service_id=service_one["id"],
permission="email_auth",
_data={"enabled": "True"},
_expected_status=403,
)
@pytest.mark.parametrize('initial_permissions, permission, form_data, expected_update', [
(
[],
'inbound_sms',
'True',
['inbound_sms'],
),
(
['inbound_sms'],
'inbound_sms',
'False',
[],
),
(
[],
'email_auth',
'True',
['email_auth'],
),
(
['email_auth'],
'email_auth',
'False',
[],
),
])
@pytest.mark.parametrize(
"initial_permissions, permission, form_data, expected_update",
[
(
[],
"inbound_sms",
"True",
["inbound_sms"],
),
(
["inbound_sms"],
"inbound_sms",
"False",
[],
),
(
[],
"email_auth",
"True",
["email_auth"],
),
(
["email_auth"],
"email_auth",
"False",
[],
),
],
)
def test_service_set_permission(
mocker,
client_request,
@@ -74,32 +81,49 @@ def test_service_set_permission(
form_data,
expected_update,
):
service_one['permissions'] = initial_permissions
mock_update_service = mocker.patch('app.service_api_client.update_service')
service_one["permissions"] = initial_permissions
mock_update_service = mocker.patch("app.service_api_client.update_service")
client_request.login(platform_admin_user)
client_request.post(
'main.service_set_permission',
service_id=service_one['id'],
"main.service_set_permission",
service_id=service_one["id"],
permission=permission,
_data={'enabled': form_data},
_data={"enabled": form_data},
_expected_redirect=url_for(
'main.service_settings',
service_id=service_one['id'],
)
"main.service_settings",
service_id=service_one["id"],
),
)
assert mock_update_service.call_args[0][0] == service_one['id']
new_permissions = mock_update_service.call_args[1]['permissions']
assert mock_update_service.call_args[0][0] == service_one["id"]
new_permissions = mock_update_service.call_args[1]["permissions"]
assert len(new_permissions) == len(set(new_permissions))
assert set(new_permissions) == set(expected_update)
@pytest.mark.parametrize('service_fields, endpoint, kwargs, text', [
({'restricted': True}, '.service_switch_live', {}, 'Live Off Change service status'),
({'restricted': False}, '.service_switch_live', {}, 'Live On Change service status'),
({'permissions': ['sms']}, '.service_set_inbound_number', {},
'Receive inbound SMS Off Change your settings for Receive inbound SMS'),
])
@pytest.mark.parametrize(
"service_fields, endpoint, kwargs, text",
[
(
{"restricted": True},
".service_switch_live",
{},
"Live Off Change service status",
),
(
{"restricted": False},
".service_switch_live",
{},
"Live On Change service status",
),
(
{"permissions": ["sms"]},
".service_set_inbound_number",
{},
"Receive inbound SMS Off Change your settings for Receive inbound SMS",
),
],
)
def test_service_setting_toggles_show(
mocker,
mock_get_service_organization,
@@ -110,19 +134,27 @@ def test_service_setting_toggles_show(
kwargs,
text,
):
link_url = url_for(endpoint, **kwargs, service_id=service_one['id'])
link_url = url_for(endpoint, **kwargs, service_id=service_one["id"])
service_one.update(service_fields)
page = get_service_settings_page()
assert normalize_spaces(page.find('a', {'href': link_url}).find_parent('tr').text.strip()) == text
assert (
normalize_spaces(
page.find("a", {"href": link_url}).find_parent("tr").text.strip()
)
== text
)
@pytest.mark.parametrize('service_fields, endpoint, index, text', [
({'active': True}, '.archive_service', 0, 'Delete this service'),
({'active': True}, '.suspend_service', 1, 'Suspend service'),
({'active': True}, '.history', 2, 'Service history'),
({'active': False}, '.resume_service', 0, 'Resume service'),
({'active': False}, '.history', 1, 'Service history'),
])
@pytest.mark.parametrize(
"service_fields, endpoint, index, text",
[
({"active": True}, ".archive_service", 0, "Delete this service"),
({"active": True}, ".suspend_service", 1, "Suspend service"),
({"active": True}, ".history", 2, "Service history"),
({"active": False}, ".resume_service", 0, "Resume service"),
({"active": False}, ".history", 1, "Service history"),
],
)
def test_service_setting_link_toggles(
get_service_settings_page,
service_one,
@@ -131,19 +163,25 @@ def test_service_setting_link_toggles(
index,
text,
):
link_url = url_for(endpoint, service_id=service_one['id'])
link_url = url_for(endpoint, service_id=service_one["id"])
service_one.update(service_fields)
page = get_service_settings_page()
link = page.select('.page-footer-link a')[index]
link = page.select(".page-footer-link a")[index]
assert normalize_spaces(link.text) == text
assert link['href'] == link_url
assert link["href"] == link_url
@pytest.mark.parametrize('service_fields, endpoint, index, text', [
pytest.param(
{'active': False}, '.archive_service', 2, 'Resume service',
)
])
@pytest.mark.parametrize(
"service_fields, endpoint, index, text",
[
pytest.param(
{"active": False},
".archive_service",
2,
"Resume service",
)
],
)
def test_service_setting_link_toggles_index_error(
get_service_settings_page,
service_one,
@@ -153,41 +191,45 @@ def test_service_setting_link_toggles_index_error(
text,
):
with pytest.raises(expected_exception=IndexError):
url_for(endpoint, service_id=service_one['id'])
url_for(endpoint, service_id=service_one["id"])
service_one.update(service_fields)
page = get_service_settings_page()
page.select('.page-footer-link a')[index]
page.select(".page-footer-link a")[index]
@pytest.mark.parametrize('permissions,permissions_text,visible', [
('sms', 'inbound SMS', True),
('inbound_sms', 'inbound SMS', False), # no sms parent permission
# also test no permissions set
('', 'inbound SMS', False),
])
@pytest.mark.parametrize(
"permissions,permissions_text,visible",
[
("sms", "inbound SMS", True),
("inbound_sms", "inbound SMS", False), # no sms parent permission
# also test no permissions set
("", "inbound SMS", False),
],
)
def test_service_settings_doesnt_show_option_if_parent_permission_disabled(
get_service_settings_page,
service_one,
permissions,
permissions_text,
visible
get_service_settings_page, service_one, permissions, permissions_text, visible
):
service_one['permissions'] = [permissions]
service_one["permissions"] = [permissions]
page = get_service_settings_page()
cells = page.find_all('td')
cells = page.find_all("td")
assert any(cell for cell in cells if permissions_text in cell.text) is visible
@pytest.mark.parametrize('service_fields, link_text', [
# can't archive or suspend inactive service. Can't resume active service.
({'active': False}, 'Archive service'),
({'active': False}, 'Suspend service'),
({'active': True}, 'Resume service'),
])
def test_service_setting_toggles_dont_show(get_service_settings_page, service_one, service_fields, link_text):
@pytest.mark.parametrize(
"service_fields, link_text",
[
# can't archive or suspend inactive service. Can't resume active service.
({"active": False}, "Archive service"),
({"active": False}, "Suspend service"),
({"active": True}, "Resume service"),
],
)
def test_service_setting_toggles_dont_show(
get_service_settings_page, service_one, service_fields, link_text
):
service_one.update(service_fields)
page = get_service_settings_page()
toggles = page.find_all('a', {'class': 'usa-link'})
toggles = page.find_all("a", {"class": "usa-link"})
assert not any(link for link in toggles if link_text in link.text)
@@ -199,10 +241,13 @@ def test_normal_user_doesnt_see_any_platform_admin_settings(
single_sms_sender,
mock_get_inbound_number_for_service,
mock_get_free_sms_fragment_limit,
mock_get_service_data_retention
mock_get_service_data_retention,
):
page = client_request.get('main.service_settings', service_id=service_one['id'])
platform_admin_settings = [permission['title'] for permission in PLATFORM_ADMIN_SERVICE_PERMISSIONS.values()]
page = client_request.get("main.service_settings", service_id=service_one["id"])
platform_admin_settings = [
permission["title"]
for permission in PLATFORM_ADMIN_SERVICE_PERMISSIONS.values()
]
for permission in platform_admin_settings:
assert permission not in page

File diff suppressed because it is too large Load Diff