mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
Stop using platform_admin_client fixture
We have a `client_request` fixture which does a bunch of useful stuff like: - checking the status code of the response - returning a `BeautifulSoup` object For most tests of a platform admin view we used `platform_admin_client` instead. This is not as good because it returns a raw `Response` object and doesn’t do the additional checks. This commit converts all the tests using `platform_admin_client` to: use new `client_request` and log in as `platform_admin_user` before making any requests. This is also nice because it makes any test easy to parametrize with additional users, for example to test differences in behaviour dependant on being platform admin or not.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
from notifications_python_client.errors import HTTPError
|
||||
@@ -17,7 +16,8 @@ from tests.conftest import (
|
||||
|
||||
|
||||
def test_organisation_page_shows_all_organisations(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker
|
||||
):
|
||||
orgs = [
|
||||
@@ -29,12 +29,8 @@ def test_organisation_page_shows_all_organisations(
|
||||
get_organisations = mocker.patch(
|
||||
'app.models.organisation.AllOrganisations.client_method', return_value=orgs
|
||||
)
|
||||
response = platform_admin_client.get(
|
||||
url_for('.organisations')
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('.organisations')
|
||||
|
||||
assert normalize_spaces(
|
||||
page.select_one('h1').text
|
||||
@@ -1204,21 +1200,22 @@ def test_update_organisation_domains_when_domain_already_exists(
|
||||
|
||||
|
||||
def test_update_organisation_name(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
mock_organisation_name_is_unique
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for('.edit_organisation_name', org_id=organisation_one['id']),
|
||||
data={'name': 'TestNewOrgName'}
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'.confirm_edit_organisation_name',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True
|
||||
_data={'name': 'TestNewOrgName'},
|
||||
_expected_redirect=url_for(
|
||||
'.confirm_edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
assert mock_organisation_name_is_unique.called
|
||||
|
||||
@@ -1229,64 +1226,65 @@ def test_update_organisation_name(
|
||||
('a' * 256, 'Organisation name must be 255 characters or fewer'),
|
||||
])
|
||||
def test_update_organisation_with_incorrect_input(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
name,
|
||||
error_message
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for('.edit_organisation_name', org_id=organisation_one['id']),
|
||||
data={'name': name}
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_data={'name': name},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert error_message in page.select_one('.govuk-error-message').text
|
||||
|
||||
|
||||
def test_update_organisation_with_non_unique_name(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
mock_organisation_name_is_not_unique
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for('.edit_organisation_name', org_id=organisation_one['id']),
|
||||
data={'name': 'TestNewOrgName'}
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_data={'name': 'TestNewOrgName'},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert 'This organisation name is already in use' in page.select_one('.govuk-error-message').text
|
||||
|
||||
assert mock_organisation_name_is_not_unique.called
|
||||
|
||||
|
||||
def test_confirm_update_organisation(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
mock_verify_password,
|
||||
mock_update_organisation,
|
||||
mocker
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['organisation_name_change'] = 'newName'
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'.confirm_edit_organisation_name',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.confirm_edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_data={'password': 'validPassword'},
|
||||
_expected_redirect=url_for(
|
||||
'.organisation_settings',
|
||||
org_id=organisation_one['id'],
|
||||
data={'password', 'validPassword'}
|
||||
)
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('.organisation_settings', org_id=organisation_one['id'], _external=True)
|
||||
|
||||
mock_update_organisation.assert_called_with(
|
||||
organisation_one['id'],
|
||||
name=session['organisation_name_change']
|
||||
@@ -1294,39 +1292,38 @@ def test_confirm_update_organisation(
|
||||
|
||||
|
||||
def test_confirm_update_organisation_with_incorrect_password(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
mocker
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['organisation_name_change'] = 'newName'
|
||||
|
||||
mocker.patch('app.user_api_client.verify_password', return_value=False)
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'.confirm_edit_organisation_name',
|
||||
org_id=organisation_one['id']
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.confirm_edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert normalize_spaces(
|
||||
page.select_one('.govuk-error-message').text
|
||||
) == 'Error: Invalid password'
|
||||
|
||||
|
||||
def test_confirm_update_organisation_with_name_already_in_use(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
mock_verify_password,
|
||||
mocker
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['organisation_name_change'] = 'newName'
|
||||
|
||||
mocker.patch(
|
||||
@@ -1340,32 +1337,29 @@ def test_confirm_update_organisation_with_name_already_in_use(
|
||||
)
|
||||
)
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'.confirm_edit_organisation_name',
|
||||
org_id=organisation_one['id']
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.confirm_edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_expected_redirect=url_for(
|
||||
'main.edit_organisation_name',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.edit_organisation_name', org_id=organisation_one['id'], _external=True)
|
||||
|
||||
|
||||
def test_get_edit_organisation_go_live_notes_page(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_organisation,
|
||||
organisation_one,
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for(
|
||||
'.edit_organisation_go_live_notes',
|
||||
org_id=organisation_one['id']
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.edit_organisation_go_live_notes',
|
||||
org_id=organisation_one['id'],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.find('textarea', id='request_to_go_live_notes')
|
||||
|
||||
|
||||
@@ -1374,77 +1368,81 @@ def test_get_edit_organisation_go_live_notes_page(
|
||||
(' ', None)
|
||||
])
|
||||
def test_post_edit_organisation_go_live_notes_updates_go_live_notes(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_organisation,
|
||||
mock_update_organisation,
|
||||
organisation_one,
|
||||
input_note,
|
||||
saved_note,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'.edit_organisation_go_live_notes',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.edit_organisation_go_live_notes',
|
||||
org_id=organisation_one['id'],
|
||||
_data={'request_to_go_live_notes': input_note},
|
||||
_expected_redirect=url_for(
|
||||
'.organisation_settings',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True,
|
||||
),
|
||||
data={'request_to_go_live_notes': input_note}
|
||||
)
|
||||
|
||||
mock_update_organisation.assert_called_once_with(
|
||||
organisation_one['id'],
|
||||
request_to_go_live_notes=saved_note
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'.organisation_settings',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True
|
||||
)
|
||||
|
||||
|
||||
def test_organisation_settings_links_to_edit_organisation_notes_page(
|
||||
mocker,
|
||||
mock_get_organisation,
|
||||
organisation_one,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.organisation_settings', org_id=organisation_one['id']
|
||||
))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
)
|
||||
assert len(page.find_all(
|
||||
'a', attrs={'href': '/organisations/{}/settings/notes'.format(organisation_one['id'])}
|
||||
)) == 1
|
||||
|
||||
|
||||
def test_view_edit_organisation_notes(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
):
|
||||
response = platform_admin_client.get(url_for('main.edit_organisation_notes', org_id=organisation_one['id']))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.edit_organisation_notes',
|
||||
org_id=organisation_one['id'],
|
||||
)
|
||||
assert page.select_one('h1').text == "Edit organisation notes"
|
||||
assert page.find('label', class_="form-label").text.strip() == "Notes"
|
||||
assert page.find('textarea').attrs["name"] == "notes"
|
||||
|
||||
|
||||
def test_update_organisation_notes(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
mock_update_organisation,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_organisation_notes',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.edit_organisation_notes',
|
||||
org_id=organisation_one['id'],
|
||||
_data={'notes': "Very fluffy"},
|
||||
_expected_redirect=url_for(
|
||||
'main.organisation_settings',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True,
|
||||
),
|
||||
data={'notes': "Very fluffy"}
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.organisation_settings', org_id=organisation_one['id'], _external=True)
|
||||
assert settings_url == response.location
|
||||
mock_update_organisation.assert_called_with(
|
||||
organisation_one['id'],
|
||||
cached_service_ids=None,
|
||||
@@ -1467,7 +1465,8 @@ def test_update_organisation_notes_errors_when_user_not_platform_admin(
|
||||
|
||||
|
||||
def test_update_organisation_notes_doesnt_call_api_when_notes_dont_change(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_update_organisation,
|
||||
mocker
|
||||
@@ -1477,17 +1476,17 @@ def test_update_organisation_notes_doesnt_call_api_when_notes_dont_change(
|
||||
name="Test Org",
|
||||
notes="Very fluffy"
|
||||
))
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_organisation_notes',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.edit_organisation_notes',
|
||||
org_id=organisation_one['id'],
|
||||
_data={'notes': "Very fluffy"},
|
||||
_expected_redirect=url_for(
|
||||
'main.organisation_settings',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True,
|
||||
),
|
||||
data={'notes': "Very fluffy"}
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.organisation_settings', org_id=organisation_one['id'], _external=True)
|
||||
assert response.location == settings_url
|
||||
assert not mock_update_organisation.called
|
||||
|
||||
|
||||
@@ -1495,26 +1494,29 @@ def test_organisation_settings_links_to_edit_organisation_billing_details_page(
|
||||
mocker,
|
||||
mock_get_organisation,
|
||||
organisation_one,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.organisation_settings', org_id=organisation_one['id']
|
||||
))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
)
|
||||
assert len(page.find_all(
|
||||
'a', attrs={'href': '/organisations/{}/settings/edit-billing-details'.format(organisation_one['id'])}
|
||||
)) == 1
|
||||
|
||||
|
||||
def test_view_edit_organisation_billing_details(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for('main.edit_organisation_billing_details', org_id=organisation_one['id'])
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.edit_organisation_billing_details',
|
||||
org_id=organisation_one['id'],
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.select_one('h1').text == "Edit organisation billing details"
|
||||
labels = page.find_all('label', class_="form-label")
|
||||
labels_list = [
|
||||
@@ -1541,28 +1543,29 @@ def test_view_edit_organisation_billing_details(
|
||||
|
||||
|
||||
def test_update_organisation_billing_details(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
organisation_one,
|
||||
mock_get_organisation,
|
||||
mock_update_organisation,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_organisation_billing_details',
|
||||
org_id=organisation_one['id'],
|
||||
),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.edit_organisation_billing_details',
|
||||
org_id=organisation_one['id'],
|
||||
_data={
|
||||
'billing_contact_email_addresses': 'accounts@fluff.gov.uk',
|
||||
'billing_contact_names': 'Flannellette von Fluff',
|
||||
'billing_reference': '',
|
||||
'purchase_order_number': 'PO1234',
|
||||
'notes': 'very fluffy, give extra allowance'
|
||||
}
|
||||
},
|
||||
_expected_redirect=url_for(
|
||||
'main.organisation_settings',
|
||||
org_id=organisation_one['id'],
|
||||
_external=True,
|
||||
)
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.organisation_settings', org_id=organisation_one['id'], _external=True)
|
||||
assert settings_url == response.location
|
||||
mock_update_organisation.assert_called_with(
|
||||
organisation_one['id'],
|
||||
cached_service_ids=None,
|
||||
@@ -1606,7 +1609,7 @@ def test_organisation_billing_page_not_accessible_if_not_platform_admin(
|
||||
])
|
||||
def test_organisation_billing_page_when_the_agreement_is_signed_by_a_known_person(
|
||||
organisation_one,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
api_user_active,
|
||||
mocker,
|
||||
platform_admin_user,
|
||||
@@ -1623,12 +1626,15 @@ def test_organisation_billing_page_when_the_agreement_is_signed_by_a_known_perso
|
||||
organisation_one['agreement_signed_at'] = 'Thu, 20 Feb 2020 00:00:00 GMT'
|
||||
|
||||
mocker.patch('app.organisations_client.get_organisation', return_value=organisation_one)
|
||||
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
mocker.patch('app.user_api_client.get_user', side_effect=[platform_admin_user, api_user_active])
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('.organisation_billing', org_id=ORGANISATION_ID)
|
||||
page = client_request.get(
|
||||
'.organisation_billing',
|
||||
org_id=ORGANISATION_ID,
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.h1.string == 'Billing'
|
||||
assert '2.5 of the GOV.UK Notify data sharing and financial agreement on 20 February 2020' in normalize_spaces(
|
||||
@@ -1639,16 +1645,18 @@ def test_organisation_billing_page_when_the_agreement_is_signed_by_a_known_perso
|
||||
|
||||
def test_organisation_billing_page_when_the_agreement_is_signed_by_an_unknown_person(
|
||||
organisation_one,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
organisation_one['agreement_signed'] = True
|
||||
mocker.patch('app.organisations_client.get_organisation', return_value=organisation_one)
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('.organisation_billing', org_id=ORGANISATION_ID)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.organisation_billing',
|
||||
org_id=ORGANISATION_ID,
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.h1.string == 'Billing'
|
||||
assert (f'{organisation_one["name"]} has accepted the GOV.UK Notify data '
|
||||
@@ -1662,7 +1670,8 @@ def test_organisation_billing_page_when_the_agreement_is_signed_by_an_unknown_pe
|
||||
])
|
||||
def test_organisation_billing_page_when_the_agreement_is_not_signed(
|
||||
organisation_one,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
agreement_signed,
|
||||
expected_content,
|
||||
@@ -1670,10 +1679,11 @@ def test_organisation_billing_page_when_the_agreement_is_not_signed(
|
||||
organisation_one['agreement_signed'] = agreement_signed
|
||||
mocker.patch('app.organisations_client.get_organisation', return_value=organisation_one)
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('.organisation_billing', org_id=ORGANISATION_ID)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.organisation_billing',
|
||||
org_id=ORGANISATION_ID,
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.h1.string == 'Billing'
|
||||
assert f'{organisation_one["name"]} {expected_content}' in page.text
|
||||
@@ -1694,7 +1704,8 @@ def test_organisation_billing_page_when_the_agreement_is_not_signed(
|
||||
),
|
||||
))
|
||||
def test_download_organisation_agreement(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
crown,
|
||||
expected_status,
|
||||
@@ -1712,11 +1723,13 @@ def test_download_organisation_agreement(
|
||||
return_value=MockS3Object(b'foo')
|
||||
)
|
||||
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.get(
|
||||
'main.organisation_download_agreement',
|
||||
org_id=ORGANISATION_ID,
|
||||
))
|
||||
assert response.status_code == expected_status
|
||||
_expected_status=expected_status,
|
||||
_raw_response=True
|
||||
)
|
||||
|
||||
if expected_file_served:
|
||||
assert response.get_data() == b'foo'
|
||||
|
||||
@@ -92,7 +92,8 @@ def test_service_set_permission_does_not_exist_for_broadcast_permission(
|
||||
])
|
||||
def test_service_set_permission(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_get_inbound_number_for_service,
|
||||
mock_update_service_organisation,
|
||||
@@ -103,12 +104,18 @@ def test_service_set_permission(
|
||||
):
|
||||
service_one['permissions'] = initial_permissions
|
||||
mock_update_service = mocker.patch('app.service_api_client.update_service')
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.service_set_permission', service_id=service_one['id'], permission=permission),
|
||||
data={'enabled': form_data}
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.service_set_permission',
|
||||
service_id=service_one['id'],
|
||||
permission=permission,
|
||||
_data={'enabled': form_data},
|
||||
_expected_redirect=url_for(
|
||||
'main.service_settings',
|
||||
service_id=service_one['id'],
|
||||
_external=True,
|
||||
)
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=service_one['id'], _external=True)
|
||||
|
||||
assert mock_update_service.call_args[0][0] == service_one['id']
|
||||
new_permissions = mock_update_service.call_args[1]['permissions']
|
||||
|
||||
@@ -1693,7 +1693,7 @@ def test_org_breadcrumbs_show_if_user_is_platform_admin(
|
||||
mock_get_free_sms_fragment_limit,
|
||||
mock_get_returned_letter_statistics_with_no_returned_letters,
|
||||
platform_admin_user,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
):
|
||||
service_one_json = service_json(SERVICE_ONE_ID,
|
||||
users=[platform_admin_user['id']],
|
||||
@@ -1704,8 +1704,8 @@ def test_org_breadcrumbs_show_if_user_is_platform_admin(
|
||||
id_=ORGANISATION_ID,
|
||||
))
|
||||
|
||||
response = platform_admin_client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user, service_one_json)
|
||||
page = client_request.get('main.service_dashboard', service_id=SERVICE_ONE_ID)
|
||||
|
||||
assert page.select_one('.navigation-organisation-link')['href'] == url_for(
|
||||
'main.organisation_dashboard',
|
||||
|
||||
@@ -2,7 +2,6 @@ from io import BytesIO
|
||||
from unittest.mock import call
|
||||
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
from notifications_python_client.errors import HTTPError
|
||||
|
||||
@@ -11,16 +10,14 @@ from tests.conftest import create_email_branding, normalize_spaces
|
||||
|
||||
|
||||
def test_email_branding_page_shows_full_branding_list(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_all_email_branding
|
||||
):
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('.email_branding')
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('.email_branding')
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
links = page.select('.message-name a')
|
||||
brand_names = [normalize_spaces(link.text) for link in links]
|
||||
hrefs = [link['href'] for link in links]
|
||||
@@ -48,17 +45,18 @@ def test_email_branding_page_shows_full_branding_list(
|
||||
|
||||
|
||||
def test_edit_email_branding_shows_the_correct_branding_info(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_email_branding,
|
||||
fake_uuid
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for('.update_email_branding', branding_id=fake_uuid)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.update_email_branding',
|
||||
branding_id=fake_uuid,
|
||||
_test_page_title=False, # TODO: Fix page titles
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.select_one('#logo-img > img')['src'].endswith('/example.png')
|
||||
assert page.select_one('#name').attrs.get('value') == 'Organisation name'
|
||||
assert page.select_one('#file').attrs.get('accept') == '.png'
|
||||
@@ -67,17 +65,16 @@ def test_edit_email_branding_shows_the_correct_branding_info(
|
||||
|
||||
|
||||
def test_create_email_branding_does_not_show_any_branding_info(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_no_email_branding
|
||||
):
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('.create_email_branding')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.create_email_branding',
|
||||
_test_page_title=False, # TODO: Fix page titles
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.select_one('#logo-img > img') is None
|
||||
assert page.select_one('#name').attrs.get('value') is None
|
||||
assert page.select_one('#file').attrs.get('accept') == '.png'
|
||||
@@ -86,7 +83,8 @@ def test_create_email_branding_does_not_show_any_branding_info(
|
||||
|
||||
|
||||
def test_create_new_email_branding_without_logo(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
mock_create_email_branding,
|
||||
@@ -102,10 +100,11 @@ def test_create_new_email_branding_without_logo(
|
||||
mock_persist = mocker.patch('app.main.views.email_branding.persist_logo')
|
||||
mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
|
||||
platform_admin_client.post(
|
||||
url_for('.create_email_branding'),
|
||||
content_type='multipart/form-data',
|
||||
data=data
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.create_email_branding',
|
||||
_content_type='multipart/form-data',
|
||||
_data=data,
|
||||
)
|
||||
|
||||
assert mock_create_email_branding.called
|
||||
@@ -138,7 +137,7 @@ def test_create_email_branding_requires_a_name_when_submitting_logo_details(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_email_branding',
|
||||
content_type='multipart/form-data',
|
||||
_content_type='multipart/form-data',
|
||||
_data=data,
|
||||
_expected_status=200,
|
||||
)
|
||||
@@ -163,7 +162,7 @@ def test_create_email_branding_does_not_require_a_name_when_uploading_a_file(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_email_branding',
|
||||
content_type='multipart/form-data',
|
||||
_content_type='multipart/form-data',
|
||||
_data=data,
|
||||
_follow_redirects=True
|
||||
)
|
||||
@@ -172,12 +171,13 @@ def test_create_email_branding_does_not_require_a_name_when_uploading_a_file(
|
||||
|
||||
|
||||
def test_create_new_email_branding_when_branding_saved(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
mock_create_email_branding,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
data = {
|
||||
@@ -197,10 +197,12 @@ def test_create_new_email_branding_when_branding_saved(
|
||||
mocker.patch('app.main.views.email_branding.persist_logo')
|
||||
mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
|
||||
platform_admin_client.post(
|
||||
url_for('.create_email_branding', logo=temp_filename),
|
||||
content_type='multipart/form-data',
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.create_email_branding',
|
||||
logo=temp_filename,
|
||||
_content_type='multipart/form-data',
|
||||
_data={
|
||||
'colour': data['colour'],
|
||||
'name': data['name'],
|
||||
'text': data['text'],
|
||||
@@ -226,7 +228,8 @@ def test_create_new_email_branding_when_branding_saved(
|
||||
('main.update_email_branding', True),
|
||||
])
|
||||
def test_deletes_previous_temp_logo_after_uploading_logo(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
endpoint,
|
||||
has_data,
|
||||
@@ -235,7 +238,7 @@ def test_deletes_previous_temp_logo_after_uploading_logo(
|
||||
if has_data:
|
||||
mocker.patch('app.email_branding_client.get_email_branding', return_value=create_email_branding(fake_uuid))
|
||||
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_old_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format(
|
||||
@@ -257,10 +260,13 @@ def test_deletes_previous_temp_logo_after_uploading_logo(
|
||||
|
||||
mocked_delete_email_temp_file = mocker.patch('app.main.views.email_branding.delete_email_temp_file')
|
||||
|
||||
platform_admin_client.post(
|
||||
url_for('main.create_email_branding', logo=temp_old_filename, branding_id=fake_uuid),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
content_type='multipart/form-data'
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.create_email_branding',
|
||||
logo=temp_old_filename,
|
||||
branding_id=fake_uuid,
|
||||
_data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
_content_type='multipart/form-data',
|
||||
)
|
||||
|
||||
assert mocked_upload_email_logo.called
|
||||
@@ -269,13 +275,14 @@ def test_deletes_previous_temp_logo_after_uploading_logo(
|
||||
|
||||
|
||||
def test_update_existing_branding(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
mock_get_email_branding,
|
||||
mock_update_email_branding
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
data = {
|
||||
@@ -295,13 +302,19 @@ def test_update_existing_branding(
|
||||
mocker.patch('app.main.views.email_branding.persist_logo')
|
||||
mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
|
||||
platform_admin_client.post(
|
||||
url_for('.update_email_branding', logo=temp_filename, branding_id=fake_uuid),
|
||||
content_type='multipart/form-data',
|
||||
data={'colour': data['colour'], 'name': data['name'], 'text': data['text'],
|
||||
'cdn_url': 'https://static-logos.cdn.com',
|
||||
'brand_type': data['brand_type']
|
||||
}
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.update_email_branding',
|
||||
logo=temp_filename,
|
||||
branding_id=fake_uuid,
|
||||
_content_type='multipart/form-data',
|
||||
_data={
|
||||
'colour': data['colour'],
|
||||
'name': data['name'],
|
||||
'text': data['text'],
|
||||
'cdn_url': 'https://static-logos.cdn.com',
|
||||
'brand_type': data['brand_type'],
|
||||
},
|
||||
)
|
||||
|
||||
updated_logo_name = '{}-{}'.format(fake_uuid, data['logo'])
|
||||
@@ -318,11 +331,12 @@ def test_update_existing_branding(
|
||||
|
||||
|
||||
def test_temp_logo_is_shown_after_uploading_logo(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format(
|
||||
@@ -334,27 +348,25 @@ def test_temp_logo_is_shown_after_uploading_logo(
|
||||
mocker.patch('app.main.views.email_branding.upload_email_logo', return_value=temp_filename)
|
||||
mocker.patch('app.main.views.email_branding.delete_email_temp_file')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.create_email_branding'),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
content_type='multipart/form-data',
|
||||
follow_redirects=True
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'main.create_email_branding',
|
||||
_data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
_content_type='multipart/form-data',
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.select_one('#logo-img > img').attrs['src'].endswith(temp_filename)
|
||||
|
||||
|
||||
def test_logo_persisted_when_organisation_saved(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_create_email_branding,
|
||||
mocker,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format(
|
||||
@@ -364,11 +376,12 @@ def test_logo_persisted_when_organisation_saved(
|
||||
mocked_persist_logo = mocker.patch('app.main.views.email_branding.persist_logo')
|
||||
mocked_delete_email_temp_files_by = mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
|
||||
resp = platform_admin_client.post(
|
||||
url_for('.create_email_branding', logo=temp_filename),
|
||||
content_type='multipart/form-data'
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.create_email_branding',
|
||||
logo=temp_filename,
|
||||
_content_type='multipart/form-data',
|
||||
)
|
||||
assert resp.status_code == 302
|
||||
|
||||
assert not mocked_upload_email_logo.called
|
||||
assert mocked_persist_logo.called
|
||||
@@ -378,12 +391,13 @@ def test_logo_persisted_when_organisation_saved(
|
||||
|
||||
|
||||
def test_logo_does_not_get_persisted_if_updating_email_branding_client_throws_an_error(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_create_email_branding,
|
||||
mocker,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_filename = EMAIL_LOGO_LOCATION_STRUCTURE.format(
|
||||
@@ -393,9 +407,12 @@ def test_logo_does_not_get_persisted_if_updating_email_branding_client_throws_an
|
||||
mocked_delete_email_temp_files_by = mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
mocker.patch('app.main.views.email_branding.email_branding_client.create_email_branding', side_effect=HTTPError())
|
||||
|
||||
platform_admin_client.post(
|
||||
url_for('.create_email_branding', logo=temp_filename),
|
||||
content_type='multipart/form-data'
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.create_email_branding',
|
||||
logo=temp_filename,
|
||||
_content_type='multipart/form-data',
|
||||
_expected_status=500,
|
||||
)
|
||||
|
||||
assert not mocked_persist_logo.called
|
||||
@@ -408,7 +425,8 @@ def test_logo_does_not_get_persisted_if_updating_email_branding_client_throws_an
|
||||
('', 302),
|
||||
])
|
||||
def test_colour_regex_validation(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
colour_hex,
|
||||
@@ -425,9 +443,10 @@ def test_colour_regex_validation(
|
||||
|
||||
mocker.patch('app.main.views.email_branding.delete_email_temp_files_created_by')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_email_branding'),
|
||||
content_type='multipart/form-data',
|
||||
data=data
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.create_email_branding',
|
||||
_content_type='multipart/form-data',
|
||||
_data=data,
|
||||
_expected_status=expected_status_code,
|
||||
)
|
||||
assert response.status_code == expected_status_code
|
||||
|
||||
@@ -157,14 +157,15 @@ def test_user_information_page_displays_if_there_are_failed_login_attempts(
|
||||
|
||||
|
||||
def test_user_information_page_shows_archive_link_for_active_users(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
api_user_active,
|
||||
mock_get_organisations_and_services_for_user,
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for('main.user_information', user_id=api_user_active['id'])
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.user_information', user_id=api_user_active['id']
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
archive_url = url_for('main.archive_user', user_id=api_user_active['id'])
|
||||
|
||||
link = page.find('a', {'href': archive_url})
|
||||
@@ -190,40 +191,46 @@ def test_user_information_page_does_not_show_archive_link_for_inactive_users(
|
||||
|
||||
|
||||
def test_archive_user_prompts_for_confirmation(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
api_user_active,
|
||||
mock_get_organisations_and_services_for_user,
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for('main.archive_user', user_id=api_user_active['id'])
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.archive_user', user_id=api_user_active['id']
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert 'Are you sure you want to archive this user?' in page.find('div', class_='banner-dangerous').text
|
||||
|
||||
|
||||
def test_archive_user_posts_to_user_client(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
api_user_active,
|
||||
mocker,
|
||||
mock_events,
|
||||
):
|
||||
mock_user_client = mocker.patch('app.user_api_client.post')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.archive_user', user_id=api_user_active['id'])
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.archive_user', user_id=api_user_active['id'],
|
||||
_expected_redirect=url_for(
|
||||
'main.user_information',
|
||||
user_id=api_user_active['id'],
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.user_information', user_id=api_user_active['id'], _external=True)
|
||||
mock_user_client.assert_called_once_with('/user/{}/archive'.format(api_user_active['id']), data=None)
|
||||
|
||||
assert mock_events.called
|
||||
|
||||
|
||||
def test_archive_user_shows_error_message_if_user_cannot_be_archived(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
api_user_active,
|
||||
mocker,
|
||||
mock_get_non_empty_organisations_and_services_for_user,
|
||||
@@ -242,13 +249,13 @@ def test_archive_user_shows_error_message_if_user_cannot_be_archived(
|
||||
)
|
||||
)
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.archive_user', user_id=api_user_active['id']),
|
||||
follow_redirects=True
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'main.archive_user',
|
||||
user_id=api_user_active['id'],
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert normalize_spaces(page.find('h1').text) == 'Platform admin user'
|
||||
assert normalize_spaces(
|
||||
page.select_one('.banner-dangerous').text
|
||||
@@ -256,14 +263,16 @@ def test_archive_user_shows_error_message_if_user_cannot_be_archived(
|
||||
|
||||
|
||||
def test_archive_user_does_not_create_event_if_user_client_raises_unexpected_exception(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
api_user_active,
|
||||
mocker,
|
||||
mock_events,
|
||||
):
|
||||
with pytest.raises(Exception):
|
||||
platform_admin_client.post(
|
||||
url_for('main.archive_user', user_id=api_user_active.id)
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.archive_user', user_id=api_user_active.id,
|
||||
)
|
||||
|
||||
assert not mock_events.called
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
|
||||
sample_inbound_sms = {'data': [{"id": "activated",
|
||||
"number": "0784121212",
|
||||
"provider": "provider_one",
|
||||
@@ -25,10 +22,12 @@ sample_inbound_sms = {'data': [{"id": "activated",
|
||||
]}
|
||||
|
||||
|
||||
def test_inbound_sms_admin(platform_admin_client, mocker):
|
||||
def test_inbound_sms_admin(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
mocker.patch("app.inbound_number_client.get_all_inbound_sms_number_service", return_value=sample_inbound_sms)
|
||||
response = platform_admin_client.get(url_for("main.inbound_sms_admin"))
|
||||
assert response.status_code == 200
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get("main.inbound_sms_admin")
|
||||
assert page.h1.string.strip() == "Inbound SMS"
|
||||
|
||||
@@ -4,7 +4,6 @@ from uuid import UUID
|
||||
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError as BotoClientError
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
from notifications_python_client.errors import HTTPError
|
||||
|
||||
@@ -16,15 +15,13 @@ from tests.conftest import normalize_spaces
|
||||
|
||||
|
||||
def test_letter_branding_page_shows_full_branding_list(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_all_letter_branding
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for('.letter_branding')
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('.letter_branding')
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
links = page.select('.message-name a')
|
||||
brand_names = [normalize_spaces(link.text) for link in links]
|
||||
hrefs = [link['href'] for link in links]
|
||||
@@ -49,17 +46,17 @@ def test_letter_branding_page_shows_full_branding_list(
|
||||
|
||||
|
||||
def test_update_letter_branding_shows_the_current_letter_brand(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid,
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
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'
|
||||
@@ -68,11 +65,12 @@ def test_update_letter_branding_shows_the_current_letter_brand(
|
||||
|
||||
def test_update_letter_branding_with_new_valid_file(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
filename = 'new_file.svg'
|
||||
@@ -82,13 +80,13 @@ def test_update_letter_branding_with_new_valid_file(
|
||||
mocker.patch('app.s3_client.s3_logo_client.uuid.uuid4', return_value=fake_uuid)
|
||||
mock_delete_temp_files = mocker.patch('app.main.views.letter_branding.delete_letter_temp_file')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), filename)},
|
||||
follow_redirects=True
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
_data={'file': (BytesIO(''.encode('utf-8')), filename)},
|
||||
_follow_redirects=True,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.select_one('#logo-img > img')['src'].endswith(expected_temp_filename)
|
||||
assert page.select_one('#name').attrs.get('value') == 'HM Government'
|
||||
@@ -98,30 +96,31 @@ def test_update_letter_branding_with_new_valid_file(
|
||||
|
||||
|
||||
def test_update_letter_branding_when_uploading_invalid_file(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
follow_redirects=True
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
_data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
_follow_redirects=True
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
assert page.select_one('.error-message').text.strip() == 'SVG Images only!'
|
||||
|
||||
|
||||
def test_update_letter_branding_deletes_any_temp_files_when_uploading_a_file(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=user_id, unique_id=fake_uuid, filename='temp.svg')
|
||||
@@ -129,15 +128,15 @@ def test_update_letter_branding_deletes_any_temp_files_when_uploading_a_file(
|
||||
mock_s3_upload = mocker.patch('app.s3_client.s3_logo_client.utils_s3upload')
|
||||
mock_delete_temp_files = mocker.patch('app.main.views.letter_branding.delete_letter_temp_file')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=temp_logo),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'new_uploaded_file.svg')},
|
||||
follow_redirects=True
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
logo=temp_logo,
|
||||
_data={'file': (BytesIO(''.encode('utf-8')), 'new_uploaded_file.svg')},
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert mock_s3_upload.called
|
||||
assert mock_delete_temp_files.called
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
@@ -145,7 +144,8 @@ def test_update_letter_branding_deletes_any_temp_files_when_uploading_a_file(
|
||||
|
||||
def test_update_letter_branding_with_original_file_and_new_details(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_all_letter_branding,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid
|
||||
@@ -153,18 +153,18 @@ def test_update_letter_branding_with_original_file_and_new_details(
|
||||
mock_client_update = mocker.patch('app.main.views.letter_branding.letter_branding_client.update_letter_branding')
|
||||
mock_upload_logos = mocker.patch('app.main.views.letter_branding.upload_letter_svg_logo')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
_data={
|
||||
'name': 'Updated name',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
_follow_redirects=True,
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert response.status_code == 200
|
||||
assert page.find('h1').text == 'Letter branding'
|
||||
|
||||
assert page.find('h1').text == 'Letter branding'
|
||||
assert mock_upload_logos.called is False
|
||||
|
||||
mock_client_update.assert_called_once_with(
|
||||
@@ -176,7 +176,8 @@ def test_update_letter_branding_with_original_file_and_new_details(
|
||||
|
||||
def test_update_letter_branding_shows_form_errors_on_name_fields(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid
|
||||
):
|
||||
@@ -184,16 +185,18 @@ def test_update_letter_branding_shows_form_errors_on_name_fields(
|
||||
|
||||
logo = permanent_letter_logo_name('hm-government', 'svg')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=logo),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
logo=logo,
|
||||
_data={
|
||||
'name': '',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
_follow_redirects=True
|
||||
)
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
error_messages = page.find_all('span', class_='govuk-error-message')
|
||||
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
@@ -203,7 +206,8 @@ def test_update_letter_branding_shows_form_errors_on_name_fields(
|
||||
|
||||
def test_update_letter_branding_shows_database_errors_on_name_field(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid,
|
||||
):
|
||||
@@ -222,15 +226,17 @@ def test_update_letter_branding_shows_database_errors_on_name_field(
|
||||
message={'name': ['name already in use']}
|
||||
))
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
_data={
|
||||
'name': 'my brand',
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
error_message = page.find('span', class_='govuk-error-message').text.strip()
|
||||
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
@@ -239,7 +245,8 @@ def test_update_letter_branding_shows_database_errors_on_name_field(
|
||||
|
||||
def test_update_letter_branding_with_new_file_and_new_details(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_all_letter_branding,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid
|
||||
@@ -250,16 +257,17 @@ def test_update_letter_branding_with_new_file_and_new_details(
|
||||
mock_persist_logo = mocker.patch('app.main.views.letter_branding.persist_logo')
|
||||
mock_delete_temp_files = mocker.patch('app.main.views.letter_branding.delete_letter_temp_files_created_by')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=temp_logo),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
logo=temp_logo,
|
||||
_data={
|
||||
'name': 'Updated name',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
_follow_redirects=True
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert response.status_code == 200
|
||||
assert page.find('h1').text == 'Letter branding'
|
||||
|
||||
mock_client_update.assert_called_once_with(
|
||||
@@ -276,7 +284,8 @@ def test_update_letter_branding_with_new_file_and_new_details(
|
||||
|
||||
def test_update_letter_branding_rolls_back_db_changes_and_shows_error_if_saving_to_s3_fails(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_letter_branding_by_id,
|
||||
fake_uuid
|
||||
):
|
||||
@@ -284,16 +293,17 @@ def test_update_letter_branding_rolls_back_db_changes_and_shows_error_if_saving_
|
||||
mocker.patch('app.main.views.letter_branding.upload_letter_svg_logo', side_effect=BotoClientError({}, 'error'))
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=fake_uuid, unique_id=fake_uuid, filename='new_file.svg')
|
||||
response = platform_admin_client.post(
|
||||
url_for('.update_letter_branding', branding_id=fake_uuid, logo=temp_logo),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.update_letter_branding',
|
||||
branding_id=fake_uuid,
|
||||
logo=temp_logo,
|
||||
_data={
|
||||
'name': 'Updated name',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
_follow_redirects=True,
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert response.status_code == 200
|
||||
assert page.find('h1').text == 'Update letter branding'
|
||||
assert page.select_one('.error-message').text.strip() == 'Error saving uploaded file - try uploading again'
|
||||
|
||||
@@ -304,13 +314,12 @@ def test_update_letter_branding_rolls_back_db_changes_and_shows_error_if_saving_
|
||||
]
|
||||
|
||||
|
||||
def test_create_letter_branding_does_not_show_branding_info(platform_admin_client):
|
||||
response = platform_admin_client.get(
|
||||
url_for('.create_letter_branding')
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
def test_create_letter_branding_does_not_show_branding_info(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('.create_letter_branding')
|
||||
|
||||
assert page.select_one('#logo-img > img') is None
|
||||
assert page.select_one('#name').attrs.get('value') is None
|
||||
@@ -319,10 +328,11 @@ def test_create_letter_branding_does_not_show_branding_info(platform_admin_clien
|
||||
|
||||
def test_create_letter_branding_when_uploading_valid_file(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
filename = 'test.svg'
|
||||
@@ -332,18 +342,16 @@ def test_create_letter_branding_when_uploading_valid_file(
|
||||
mocker.patch('app.s3_client.s3_logo_client.uuid.uuid4', return_value=fake_uuid)
|
||||
mock_delete_temp_files = mocker.patch('app.main.views.letter_branding.delete_letter_temp_file')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_letter_branding'),
|
||||
data={'file': (BytesIO("""
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_letter_branding',
|
||||
_data={'file': (BytesIO("""
|
||||
<svg height="100" width="100">
|
||||
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>
|
||||
""".encode('utf-8')), filename)},
|
||||
follow_redirects=True
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.select_one('#logo-img > img').attrs['src'].endswith(expected_temp_filename)
|
||||
assert mock_s3_upload.called
|
||||
assert mock_delete_temp_files.called is False
|
||||
@@ -393,26 +401,27 @@ def test_create_letter_branding_fails_validation_when_uploading_SVG_with_bad_ele
|
||||
assert mock_s3_upload.called is False
|
||||
|
||||
|
||||
def test_create_letter_branding_when_uploading_invalid_file(platform_admin_client):
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_letter_branding'),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
follow_redirects=True
|
||||
def test_create_letter_branding_when_uploading_invalid_file(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_letter_branding',
|
||||
_data={'file': (BytesIO(''.encode('utf-8')), 'test.png')},
|
||||
_follow_redirects=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
assert page.select_one('.error-message').text.strip() == 'SVG Images only!'
|
||||
|
||||
|
||||
def test_create_letter_branding_deletes_temp_files_when_uploading_a_new_file(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=user_id, unique_id=fake_uuid, filename='temp.svg')
|
||||
@@ -420,15 +429,13 @@ def test_create_letter_branding_deletes_temp_files_when_uploading_a_new_file(
|
||||
mock_s3_upload = mocker.patch('app.s3_client.s3_logo_client.utils_s3upload')
|
||||
mock_delete_temp_files = mocker.patch('app.main.views.letter_branding.delete_letter_temp_file')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_letter_branding', logo=temp_logo),
|
||||
data={'file': (BytesIO(''.encode('utf-8')), 'new.svg')},
|
||||
follow_redirects=True
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_letter_branding',
|
||||
logo=temp_logo,
|
||||
_data={'file': (BytesIO(''.encode('utf-8')), 'new.svg')},
|
||||
_follow_redirects=True
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert mock_s3_upload.called
|
||||
assert mock_delete_temp_files.called
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
@@ -436,50 +443,51 @@ def test_create_letter_branding_deletes_temp_files_when_uploading_a_new_file(
|
||||
|
||||
def test_create_new_letter_branding_shows_preview_of_logo(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=user_id, unique_id=fake_uuid, filename='temp.svg')
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('.create_letter_branding', logo=temp_logo)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.create_letter_branding',
|
||||
logo=temp_logo,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
assert page.select_one('#logo-img > img').attrs['src'].endswith(temp_logo)
|
||||
|
||||
|
||||
def test_create_letter_branding_shows_an_error_when_submitting_details_with_no_logo(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_letter_branding'),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_letter_branding',
|
||||
_data={
|
||||
'name': 'Test brand',
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
assert page.select_one('.error-message').text.strip() == 'You need to upload a file to submit'
|
||||
|
||||
|
||||
def test_create_letter_branding_persists_logo_when_all_data_is_valid(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=user_id, unique_id=fake_uuid, filename='test.svg')
|
||||
@@ -488,17 +496,17 @@ def test_create_letter_branding_persists_logo_when_all_data_is_valid(
|
||||
mock_persist_logo = mocker.patch('app.main.views.letter_branding.persist_logo')
|
||||
mock_delete_temp_files = mocker.patch('app.main.views.letter_branding.delete_letter_temp_files_created_by')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_letter_branding', logo=temp_logo),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_letter_branding',
|
||||
logo=temp_logo,
|
||||
_data={
|
||||
'name': 'Test brand',
|
||||
'operation': 'branding-details'
|
||||
},
|
||||
follow_redirects=True
|
||||
_follow_redirects=True
|
||||
)
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert response.status_code == 200
|
||||
assert page.find('h1').text == 'Letter branding'
|
||||
|
||||
mock_letter_client.create_letter_branding.assert_called_once_with(
|
||||
@@ -512,23 +520,26 @@ def test_create_letter_branding_persists_logo_when_all_data_is_valid(
|
||||
|
||||
|
||||
def test_create_letter_branding_shows_form_errors_on_name_field(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=user_id, unique_id=fake_uuid, filename='test.svg')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_letter_branding', logo=temp_logo),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_letter_branding',
|
||||
logo=temp_logo,
|
||||
_data={
|
||||
'name': '',
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
error_messages = page.find_all('span', class_='govuk-error-message')
|
||||
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
@@ -538,10 +549,11 @@ def test_create_letter_branding_shows_form_errors_on_name_field(
|
||||
|
||||
def test_create_letter_branding_shows_database_errors_on_name_fields(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
user_id = session["user_id"]
|
||||
|
||||
mocker.patch('app.main.views.letter_branding.letter_branding_client.create_letter_branding', side_effect=HTTPError(
|
||||
@@ -561,15 +573,17 @@ def test_create_letter_branding_shows_database_errors_on_name_fields(
|
||||
|
||||
temp_logo = LETTER_TEMP_LOGO_LOCATION.format(user_id=user_id, unique_id=fake_uuid, filename='test.svg')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('.create_letter_branding', logo=temp_logo),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'.create_letter_branding',
|
||||
logo=temp_logo,
|
||||
_data={
|
||||
'name': 'my brand',
|
||||
'operation': 'branding-details'
|
||||
}
|
||||
},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
error_message = page.find('span', class_='govuk-error-message').text.strip()
|
||||
|
||||
assert page.find('h1').text == 'Add letter branding'
|
||||
|
||||
@@ -5,7 +5,6 @@ from functools import partial
|
||||
from unittest.mock import ANY, call
|
||||
|
||||
import pytest
|
||||
from bs4 import BeautifulSoup
|
||||
from flask import url_for
|
||||
from freezegun import freeze_time
|
||||
|
||||
@@ -52,14 +51,14 @@ def test_should_403_if_not_platform_admin(
|
||||
('main.trial_services', 1),
|
||||
])
|
||||
def test_should_render_platform_admin_page(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_detailed_services,
|
||||
endpoint,
|
||||
expected_services_shown
|
||||
):
|
||||
response = platform_admin_client.get(url_for(endpoint))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(endpoint)
|
||||
assert [
|
||||
normalize_spaces(column.text)
|
||||
for column in page.select('tbody tr')[1].select('td')
|
||||
@@ -82,14 +81,14 @@ def test_should_render_platform_admin_page(
|
||||
])
|
||||
def test_live_trial_services_toggle_including_from_test_key(
|
||||
partial_url_for,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_detailed_services,
|
||||
endpoint,
|
||||
inc
|
||||
):
|
||||
response = platform_admin_client.get(partial_url_for(endpoint))
|
||||
|
||||
assert response.status_code == 200
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.get_url(partial_url_for(endpoint))
|
||||
mock_get_detailed_services.assert_called_once_with({
|
||||
'detailed': True,
|
||||
'only_active': False,
|
||||
@@ -102,15 +101,19 @@ def test_live_trial_services_toggle_including_from_test_key(
|
||||
'main.trial_services'
|
||||
])
|
||||
def test_live_trial_services_with_date_filter(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_detailed_services,
|
||||
endpoint
|
||||
):
|
||||
response = platform_admin_client.get(url_for(endpoint, start_date='2016-12-20', end_date='2016-12-28'))
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
endpoint,
|
||||
start_date='2016-12-20',
|
||||
end_date='2016-12-28',
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
resp_data = response.get_data(as_text=True)
|
||||
assert 'Platform admin' in resp_data
|
||||
assert 'Platform admin' in page.text
|
||||
mock_get_detailed_services.assert_called_once_with({
|
||||
'include_from_test_key': False,
|
||||
'end_date': datetime.date(2016, 12, 28),
|
||||
@@ -137,7 +140,8 @@ def test_live_trial_services_with_date_filter(
|
||||
),
|
||||
])
|
||||
def test_should_show_total_on_live_trial_services_pages(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_detailed_services,
|
||||
endpoint,
|
||||
fake_uuid,
|
||||
@@ -173,9 +177,9 @@ def test_should_show_total_on_live_trial_services_pages(
|
||||
|
||||
mock_get_detailed_services.return_value = {'data': services}
|
||||
|
||||
response = platform_admin_client.get(url_for(endpoint))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(endpoint)
|
||||
|
||||
assert (
|
||||
normalize_spaces(page.select('.big-number-with-status')[0].text),
|
||||
normalize_spaces(page.select('.big-number-with-status')[1].text),
|
||||
@@ -290,7 +294,8 @@ def test_should_show_email_and_sms_stats_for_all_service_types(
|
||||
endpoint,
|
||||
restricted,
|
||||
research_mode,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_detailed_services,
|
||||
fake_uuid,
|
||||
):
|
||||
@@ -305,13 +310,12 @@ def test_should_show_email_and_sms_stats_for_all_service_types(
|
||||
)
|
||||
|
||||
mock_get_detailed_services.return_value = {'data': services}
|
||||
response = platform_admin_client.get(url_for(endpoint))
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(endpoint)
|
||||
|
||||
assert response.status_code == 200
|
||||
mock_get_detailed_services.assert_called_once_with({'detailed': True,
|
||||
'include_from_test_key': True,
|
||||
'only_active': ANY})
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
table_body = page.find_all('table')[0].find_all('tbody')[0]
|
||||
service_row_group = table_body.find_all('tbody')[0].find_all('tr')
|
||||
@@ -328,7 +332,8 @@ def test_should_show_email_and_sms_stats_for_all_service_types(
|
||||
], ids=['live', 'trial'])
|
||||
def test_should_show_archived_services_last(
|
||||
endpoint,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_detailed_services,
|
||||
restricted,
|
||||
):
|
||||
@@ -342,13 +347,12 @@ def test_should_show_archived_services_last(
|
||||
services[2]['statistics'] = create_stats()
|
||||
|
||||
mock_get_detailed_services.return_value = {'data': services}
|
||||
response = platform_admin_client.get(url_for(endpoint))
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(endpoint)
|
||||
|
||||
assert response.status_code == 200
|
||||
mock_get_detailed_services.assert_called_once_with({'detailed': True,
|
||||
'include_from_test_key': True,
|
||||
'only_active': ANY})
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
table_body = page.find_all('table')[0].find_all('tbody')[0]
|
||||
services = [service.tr for service in table_body.find_all('tbody')]
|
||||
@@ -366,7 +370,8 @@ def test_should_order_services_by_usage_with_inactive_last(
|
||||
endpoint,
|
||||
restricted,
|
||||
research_mode,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_detailed_services,
|
||||
fake_uuid,
|
||||
):
|
||||
@@ -403,13 +408,12 @@ def test_should_order_services_by_usage_with_inactive_last(
|
||||
)
|
||||
|
||||
mock_get_detailed_services.return_value = {'data': services}
|
||||
response = platform_admin_client.get(url_for(endpoint))
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(endpoint)
|
||||
|
||||
assert response.status_code == 200
|
||||
mock_get_detailed_services.assert_called_once_with({'detailed': True,
|
||||
'include_from_test_key': True,
|
||||
'only_active': ANY})
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
table_body = page.find_all('table')[0].find_all('tbody')[0]
|
||||
services = [service.tr for service in table_body.find_all('tbody')]
|
||||
@@ -446,7 +450,8 @@ def test_sum_service_usage_with_zeros(fake_uuid):
|
||||
|
||||
|
||||
def test_platform_admin_list_complaints(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker
|
||||
):
|
||||
complaint = {
|
||||
@@ -462,15 +467,22 @@ def test_platform_admin_list_complaints(
|
||||
mock = mocker.patch('app.complaint_api_client.get_all_complaints',
|
||||
return_value={'complaints': [complaint], 'links': {}})
|
||||
|
||||
response = platform_admin_client.get(url_for('main.platform_admin_list_complaints'))
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.platform_admin_list_complaints'
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
resp_data = response.get_data(as_text=True)
|
||||
assert 'Email complaints' in resp_data
|
||||
assert 'Email complaints' in page.text
|
||||
assert mock.called
|
||||
|
||||
|
||||
def test_should_show_complaints_with_next_previous(platform_admin_client, mocker, service_one, fake_uuid):
|
||||
def test_should_show_complaints_with_next_previous(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
):
|
||||
|
||||
api_response = {
|
||||
'complaints': [{'complaint_date': None,
|
||||
@@ -486,10 +498,11 @@ def test_should_show_complaints_with_next_previous(platform_admin_client, mocker
|
||||
|
||||
mocker.patch('app.complaint_api_client.get_all_complaints', return_value=api_response)
|
||||
|
||||
response = platform_admin_client.get(url_for('main.platform_admin_list_complaints', page=2))
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.platform_admin_list_complaints',
|
||||
page=2,
|
||||
)
|
||||
|
||||
next_page_link = page.find('a', {'rel': 'next'})
|
||||
prev_page_link = page.find('a', {'rel': 'previous'})
|
||||
@@ -501,13 +514,20 @@ def test_should_show_complaints_with_next_previous(platform_admin_client, mocker
|
||||
assert 'page 1' in prev_page_link.text.strip()
|
||||
|
||||
|
||||
def test_platform_admin_list_complaints_returns_404_with_invalid_page(platform_admin_client, mocker):
|
||||
def test_platform_admin_list_complaints_returns_404_with_invalid_page(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
|
||||
mocker.patch('app.complaint_api_client.get_all_complaints', return_value={'complaints': [], 'links': {}})
|
||||
|
||||
response = platform_admin_client.get(url_for('main.platform_admin_list_complaints', page='invalid'))
|
||||
|
||||
assert response.status_code == 404
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.get(
|
||||
'main.platform_admin_list_complaints',
|
||||
page='invalid',
|
||||
_expected_status=404,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('number, total, threshold, result', [
|
||||
@@ -546,7 +566,11 @@ def test_platform_admin_splash_doesnt_talk_to_api(
|
||||
)
|
||||
|
||||
|
||||
def test_platform_admin_with_start_and_end_dates_provided(mocker, platform_admin_client):
|
||||
def test_platform_admin_with_start_and_end_dates_provided(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
start_date = '2018-01-01'
|
||||
end_date = '2018-06-01'
|
||||
api_args = {'start_date': datetime.date(2018, 1, 1), 'end_date': datetime.date(2018, 6, 1)}
|
||||
@@ -556,8 +580,9 @@ def test_platform_admin_with_start_and_end_dates_provided(mocker, platform_admin
|
||||
'app.main.views.platform_admin.platform_stats_api_client.get_aggregate_platform_stats')
|
||||
complaint_count_mock = mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count')
|
||||
|
||||
platform_admin_client.get(
|
||||
url_for('main.platform_admin', start_date=start_date, end_date=end_date)
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.get(
|
||||
'main.platform_admin', start_date=start_date, end_date=end_date,
|
||||
)
|
||||
|
||||
aggregate_stats_mock.assert_called_with(api_args)
|
||||
@@ -565,7 +590,11 @@ def test_platform_admin_with_start_and_end_dates_provided(mocker, platform_admin
|
||||
|
||||
|
||||
@freeze_time('2018-6-11')
|
||||
def test_platform_admin_with_only_a_start_date_provided(mocker, platform_admin_client):
|
||||
def test_platform_admin_with_only_a_start_date_provided(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
start_date = '2018-01-01'
|
||||
api_args = {'start_date': datetime.date(2018, 1, 1), 'end_date': datetime.datetime.utcnow().date()}
|
||||
|
||||
@@ -574,13 +603,21 @@ def test_platform_admin_with_only_a_start_date_provided(mocker, platform_admin_c
|
||||
'app.main.views.platform_admin.platform_stats_api_client.get_aggregate_platform_stats')
|
||||
complaint_count_mock = mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count')
|
||||
|
||||
platform_admin_client.get(url_for('main.platform_admin', start_date=start_date))
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.get(
|
||||
'main.platform_admin',
|
||||
start_date=start_date,
|
||||
)
|
||||
|
||||
aggregate_stats_mock.assert_called_with(api_args)
|
||||
complaint_count_mock.assert_called_with(api_args)
|
||||
|
||||
|
||||
def test_platform_admin_without_dates_provided(mocker, platform_admin_client):
|
||||
def test_platform_admin_without_dates_provided(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
api_args = {}
|
||||
|
||||
mocker.patch('app.main.views.platform_admin.make_columns')
|
||||
@@ -588,7 +625,8 @@ def test_platform_admin_without_dates_provided(mocker, platform_admin_client):
|
||||
'app.main.views.platform_admin.platform_stats_api_client.get_aggregate_platform_stats')
|
||||
complaint_count_mock = mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count')
|
||||
|
||||
platform_admin_client.get(url_for('main.platform_admin'))
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.get('main.platform_admin')
|
||||
|
||||
aggregate_stats_mock.assert_called_with(api_args)
|
||||
complaint_count_mock.assert_called_with(api_args)
|
||||
@@ -596,7 +634,8 @@ def test_platform_admin_without_dates_provided(mocker, platform_admin_client):
|
||||
|
||||
def test_platform_admin_displays_stats_in_right_boxes_and_with_correct_styling(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
platform_stats = {
|
||||
'email': {'failures':
|
||||
@@ -616,8 +655,8 @@ def test_platform_admin_displays_stats_in_right_boxes_and_with_correct_styling(
|
||||
return_value=platform_stats)
|
||||
mocker.patch('app.main.views.platform_admin.complaint_api_client.get_complaint_count', return_value=15)
|
||||
|
||||
response = platform_admin_client.get(url_for('main.platform_admin'))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('main.platform_admin')
|
||||
|
||||
# Email permanent failure status box - number is correct
|
||||
assert '3 permanent failures' in page.find_all(
|
||||
@@ -637,14 +676,23 @@ def test_platform_admin_displays_stats_in_right_boxes_and_with_correct_styling(
|
||||
'div', class_='big-number-status-failing').text
|
||||
|
||||
|
||||
def test_platform_admin_submit_returned_letters(mocker, platform_admin_client):
|
||||
def test_platform_admin_submit_returned_letters(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
|
||||
redis = mocker.patch('app.main.views.platform_admin.redis_client')
|
||||
mock_client = mocker.patch('app.letter_jobs_client.submit_returned_letters')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.platform_admin_returned_letters'),
|
||||
data={'references': ' NOTIFY000REF1 \n NOTIFY002REF2 '}
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.platform_admin_returned_letters',
|
||||
_data={'references': ' NOTIFY000REF1 \n NOTIFY002REF2 '},
|
||||
_expected_redirect=url_for(
|
||||
'main.platform_admin_returned_letters',
|
||||
_external=True,
|
||||
)
|
||||
)
|
||||
|
||||
mock_client.assert_called_once_with(['REF1', 'REF2'])
|
||||
@@ -652,26 +700,33 @@ def test_platform_admin_submit_returned_letters(mocker, platform_admin_client):
|
||||
call('service-????????-????-????-????-????????????-returned-letters-statistics'),
|
||||
call('service-????????-????-????-????-????????????-returned-letters-summary'),
|
||||
]
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.platform_admin_returned_letters', _external=True)
|
||||
|
||||
|
||||
def test_platform_admin_submit_empty_returned_letters(mocker, platform_admin_client):
|
||||
def test_platform_admin_submit_empty_returned_letters(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
|
||||
mock_client = mocker.patch('app.letter_jobs_client.submit_returned_letters')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.platform_admin_returned_letters'),
|
||||
data={'references': ' \n '}
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'main.platform_admin_returned_letters',
|
||||
_data={'references': ' \n '},
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
assert not mock_client.called
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "Cannot be empty" in response.get_data(as_text=True)
|
||||
assert "Cannot be empty" in page.text
|
||||
|
||||
|
||||
def test_clear_cache_shows_form(client_request, platform_admin_user, mocker):
|
||||
def test_clear_cache_shows_form(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
redis = mocker.patch('app.main.views.platform_admin.redis_client')
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
@@ -737,7 +792,11 @@ def test_clear_cache_submits_and_tells_you_how_many_things_were_deleted(
|
||||
assert flash_banner.text.strip() == expected_confirmation
|
||||
|
||||
|
||||
def test_clear_cache_requires_option(client_request, platform_admin_user, mocker):
|
||||
def test_clear_cache_requires_option(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
redis = mocker.patch('app.main.views.platform_admin.redis_client')
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
@@ -748,13 +807,12 @@ def test_clear_cache_requires_option(client_request, platform_admin_user, mocker
|
||||
|
||||
|
||||
def test_reports_page(
|
||||
platform_admin_client
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('main.platform_admin_reports')
|
||||
|
||||
response = platform_admin_client.get(url_for('main.platform_admin_reports'))
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.find(
|
||||
'a', text="Download live services csv report"
|
||||
).attrs['href'] == '/platform-admin/reports/live-services.csv'
|
||||
@@ -764,7 +822,11 @@ def test_reports_page(
|
||||
).attrs['href'] == url_for('main.notifications_sent_by_service')
|
||||
|
||||
|
||||
def test_get_live_services_report(platform_admin_client, mocker):
|
||||
def test_get_live_services_report(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
|
||||
mocker.patch(
|
||||
'app.service_api_client.get_live_services_data',
|
||||
@@ -783,8 +845,11 @@ def test_get_live_services_report(platform_admin_client, mocker):
|
||||
'free_sms_fragment_limit': 200},
|
||||
]}
|
||||
)
|
||||
response = platform_admin_client.get(url_for('main.live_services_csv'))
|
||||
assert response.status_code == 200
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.get(
|
||||
'main.live_services_csv',
|
||||
_raw_response=True,
|
||||
)
|
||||
report = response.get_data(as_text=True)
|
||||
assert report.strip() == (
|
||||
'Service ID,Organisation,Organisation type,Service name,Consent to research,Main contact,Contact email,'
|
||||
@@ -798,7 +863,10 @@ def test_get_live_services_report(platform_admin_client, mocker):
|
||||
)
|
||||
|
||||
|
||||
def test_get_notifications_sent_by_service_shows_date_form(client_request, platform_admin_user):
|
||||
def test_get_notifications_sent_by_service_shows_date_form(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get('main.notifications_sent_by_service')
|
||||
|
||||
@@ -812,7 +880,11 @@ def test_get_notifications_sent_by_service_shows_date_form(client_request, platf
|
||||
]
|
||||
|
||||
|
||||
def test_get_notifications_sent_by_service_validates_form(mocker, client_request, platform_admin_user):
|
||||
def test_get_notifications_sent_by_service_validates_form(
|
||||
mocker,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
mock_get_stats_from_api = mocker.patch('app.main.views.platform_admin.notification_api_client')
|
||||
|
||||
client_request.login(platform_admin_user)
|
||||
@@ -846,7 +918,11 @@ def test_get_billing_report_when_no_results_for_date(client_request, platform_ad
|
||||
assert normalize_spaces(error.text) == 'No results for dates'
|
||||
|
||||
|
||||
def test_get_billing_report_when_calls_api_and_download_data(platform_admin_client, mocker):
|
||||
def test_get_billing_report_when_calls_api_and_download_data(
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker
|
||||
):
|
||||
mocker.patch(
|
||||
"app.main.views.platform_admin.billing_api_client.get_data_for_billing_report",
|
||||
return_value=[{
|
||||
@@ -866,10 +942,14 @@ def test_get_billing_report_when_calls_api_and_download_data(platform_admin_clie
|
||||
}]
|
||||
)
|
||||
|
||||
response = platform_admin_client.post(url_for('main.get_billing_report'),
|
||||
data={'start_date': '2019-01-01', 'end_date': '2019-03-31'})
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.post(
|
||||
'main.get_billing_report',
|
||||
_data={'start_date': '2019-01-01', 'end_date': '2019-03-31'},
|
||||
_expected_status=200,
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.content_type == 'text/csv; charset=utf-8'
|
||||
assert response.headers['Content-Disposition'] == (
|
||||
'attachment; filename="Billing Report from {} to {}.csv"'.format('2019-01-01', '2019-03-31')
|
||||
@@ -900,7 +980,8 @@ def test_get_billing_report_when_calls_api_and_download_data(platform_admin_clie
|
||||
|
||||
def test_get_notifications_sent_by_service_calls_api_and_downloads_data(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
service_two,
|
||||
):
|
||||
@@ -914,12 +995,14 @@ def test_get_notifications_sent_by_service_calls_api_and_downloads_data(
|
||||
start_date = datetime.date(2019, 1, 1)
|
||||
end_date = datetime.date(2019, 1, 31)
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.notifications_sent_by_service'),
|
||||
data={'start_date': start_date, 'end_date': end_date}
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.post(
|
||||
'main.notifications_sent_by_service',
|
||||
_data={'start_date': start_date, 'end_date': end_date},
|
||||
_expected_status=200,
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.content_type == 'text/csv; charset=utf-8'
|
||||
assert response.headers['Content-Disposition'] == (
|
||||
'attachment; filename="{} to {} notification status per service report.csv"'.format(start_date, end_date)
|
||||
|
||||
@@ -1724,7 +1724,8 @@ def test_send_one_off_redirects_to_end_if_step_out_of_bounds(
|
||||
create_active_caseworking_user(),
|
||||
))
|
||||
def test_send_one_off_redirects_to_start_if_you_skip_steps(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
mock_get_service_letter_template,
|
||||
@@ -1737,21 +1738,21 @@ def test_send_one_off_redirects_to_start_if_you_skip_steps(
|
||||
):
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['placeholders'] = {'address_line_1': 'foo'}
|
||||
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.get(
|
||||
'main.send_one_off_step',
|
||||
service_id=service_one['id'],
|
||||
template_id=fake_uuid,
|
||||
step_index=7, # letter template has 7 placeholders – we’re at the end
|
||||
))
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'main.send_one_off',
|
||||
service_id=service_one['id'],
|
||||
template_id=fake_uuid,
|
||||
_external=True,
|
||||
_expected_redirect=url_for(
|
||||
'main.send_one_off',
|
||||
service_id=service_one['id'],
|
||||
template_id=fake_uuid,
|
||||
_external=True,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -1928,7 +1929,8 @@ def test_send_one_off_sms_message_back_link_with_multiple_placeholders(
|
||||
|
||||
|
||||
def test_send_one_off_letter_redirects_to_right_url(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
fake_uuid,
|
||||
mock_get_service_letter_template,
|
||||
mock_s3_upload,
|
||||
@@ -1937,7 +1939,7 @@ def test_send_one_off_letter_redirects_to_right_url(
|
||||
mocker,
|
||||
):
|
||||
mocker.patch('app.main.views.send.get_page_count_for_letter', return_value=9)
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['recipient'] = ''
|
||||
session['placeholders'] = {
|
||||
'address line 1': 'foo',
|
||||
@@ -1949,20 +1951,19 @@ def test_send_one_off_letter_redirects_to_right_url(
|
||||
'address line 7': 'SW1 1AA',
|
||||
}
|
||||
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.get(
|
||||
'main.send_one_off_step',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
step_index=7, # letter template has 7 placeholders – we’re at the end
|
||||
))
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location.startswith(url_for(
|
||||
'main.check_notification',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
_external=True,
|
||||
))
|
||||
_expected_redirect=url_for(
|
||||
'main.check_notification',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_send_one_off_populates_field_from_session(
|
||||
@@ -2168,7 +2169,8 @@ def test_send_one_off_sms_message_puts_submitted_data_in_session(
|
||||
@pytest.mark.parametrize('filetype', ['pdf', 'png'])
|
||||
def test_send_test_works_as_letter_preview(
|
||||
filetype,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_service_letter_template,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_statistics,
|
||||
@@ -2186,20 +2188,19 @@ def test_send_test_works_as_letter_preview(
|
||||
|
||||
service_id = service_one['id']
|
||||
template_id = fake_uuid
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['placeholders'] = {'address_line_1': 'Jo Lastname'}
|
||||
response = platform_admin_client.get(
|
||||
url_for(
|
||||
'no_cookie.send_test_preview',
|
||||
service_id=service_id,
|
||||
template_id=template_id,
|
||||
filetype=filetype
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.get(
|
||||
'no_cookie.send_test_preview',
|
||||
service_id=service_id,
|
||||
template_id=template_id,
|
||||
filetype=filetype,
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
mock_get_service_letter_template.assert_called_with(service_id, template_id, None)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.get_data(as_text=True) == 'foo'
|
||||
assert mocked_preview.call_args[0][0].id == template_id
|
||||
assert type(mocked_preview.call_args[0][0]) == LetterImageTemplate
|
||||
@@ -2748,12 +2749,13 @@ def test_create_job_should_call_api(
|
||||
|
||||
|
||||
def test_can_start_letters_job(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_create_job,
|
||||
service_one,
|
||||
fake_uuid
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['file_uploads'] = {
|
||||
fake_uuid: {
|
||||
'template_id': fake_uuid,
|
||||
@@ -2762,11 +2764,15 @@ def test_can_start_letters_job(
|
||||
}
|
||||
}
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.start_job', service_id=service_one['id'], upload_id=fake_uuid),
|
||||
data={}
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.post(
|
||||
'main.start_job',
|
||||
service_id=service_one['id'],
|
||||
upload_id=fake_uuid,
|
||||
_data={},
|
||||
_expected_status=302,
|
||||
_raw_response=True,
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert 'just_sent=yes' in response.location
|
||||
|
||||
|
||||
@@ -2811,7 +2817,8 @@ def test_can_start_letters_job(
|
||||
])
|
||||
def test_should_show_preview_letter_message(
|
||||
filetype,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_service_letter_template,
|
||||
mock_get_users_by_service,
|
||||
mock_get_service_statistics,
|
||||
@@ -2847,7 +2854,7 @@ def test_should_show_preview_letter_message(
|
||||
|
||||
service_id = service_one['id']
|
||||
template_id = fake_uuid
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['file_uploads'] = {
|
||||
fake_uuid: {
|
||||
'template_id': fake_uuid,
|
||||
@@ -2856,20 +2863,19 @@ def test_should_show_preview_letter_message(
|
||||
}
|
||||
}
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for(
|
||||
'no_cookie.check_messages_preview',
|
||||
service_id=service_id,
|
||||
template_id=fake_uuid,
|
||||
upload_id=fake_uuid,
|
||||
filetype=filetype,
|
||||
**extra_args
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.get(
|
||||
'no_cookie.check_messages_preview',
|
||||
service_id=service_id,
|
||||
template_id=fake_uuid,
|
||||
upload_id=fake_uuid,
|
||||
filetype=filetype,
|
||||
_raw_response=True,
|
||||
**extra_args
|
||||
)
|
||||
|
||||
mock_get_service_letter_template.assert_called_with(service_id, template_id, None)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.get_data(as_text=True) == 'foo'
|
||||
assert mocked_preview.call_args[0][0].id == template_id
|
||||
assert type(mocked_preview.call_args[0][0]) == LetterPreviewTemplate
|
||||
|
||||
@@ -3807,15 +3807,15 @@ def test_organisation_type_pages_are_platform_admin_only(
|
||||
|
||||
|
||||
def test_should_show_page_to_set_sms_allowance(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mock_get_free_sms_fragment_limit
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.set_free_sms_allowance',
|
||||
service_id=SERVICE_ONE_ID
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
)
|
||||
|
||||
assert normalize_spaces(page.select_one('label').text) == 'Numbers of text message fragments per year'
|
||||
mock_get_free_sms_fragment_limit.assert_called_once_with(SERVICE_ONE_ID)
|
||||
@@ -3828,24 +3828,27 @@ def test_should_show_page_to_set_sms_allowance(
|
||||
pytest.param('foo', 'foo', marks=pytest.mark.xfail),
|
||||
])
|
||||
def test_should_set_sms_allowance(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
given_allowance,
|
||||
expected_api_argument,
|
||||
mock_get_free_sms_fragment_limit,
|
||||
mock_create_or_update_free_sms_fragment_limit,
|
||||
):
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.set_free_sms_allowance',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.set_free_sms_allowance',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={
|
||||
'free_sms_allowance': given_allowance,
|
||||
},
|
||||
_expected_redirect=url_for(
|
||||
'main.service_settings',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
|
||||
mock_create_or_update_free_sms_fragment_limit.assert_called_with(
|
||||
SERVICE_ONE_ID,
|
||||
@@ -3854,15 +3857,14 @@ def test_should_set_sms_allowance(
|
||||
|
||||
|
||||
def test_should_show_page_to_set_message_limit(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.set_message_limit',
|
||||
service_id=SERVICE_ONE_ID
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
)
|
||||
assert normalize_spaces(page.select_one('label').text) == (
|
||||
'Number of messages the service is allowed to send each day'
|
||||
)
|
||||
@@ -3872,15 +3874,14 @@ def test_should_show_page_to_set_message_limit(
|
||||
|
||||
|
||||
def test_should_show_page_to_set_rate_limit(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.set_rate_limit',
|
||||
service_id=SERVICE_ONE_ID
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
)
|
||||
assert normalize_spaces(page.select_one('label').text) == (
|
||||
'Number of messages the service can send in a rolling 60 second window'
|
||||
)
|
||||
@@ -3899,26 +3900,22 @@ def test_should_show_page_to_set_rate_limit(
|
||||
pytest.param('foo', 'foo', marks=pytest.mark.xfail),
|
||||
])
|
||||
def test_should_set_message_limit(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
new_limit,
|
||||
expected_api_argument,
|
||||
mock_update_service,
|
||||
endpoint,
|
||||
field_name,
|
||||
):
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
endpoint,
|
||||
service_id=SERVICE_ONE_ID,
|
||||
),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
endpoint,
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={
|
||||
field_name: new_limit,
|
||||
},
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
|
||||
mock_update_service.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
**{field_name: expected_api_argument},
|
||||
@@ -4226,7 +4223,8 @@ def test_archive_service_prompts_user(
|
||||
|
||||
|
||||
def test_cant_archive_inactive_service(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
single_reply_to_email_address,
|
||||
single_letter_contact_block,
|
||||
@@ -4235,10 +4233,12 @@ def test_cant_archive_inactive_service(
|
||||
):
|
||||
service_one['active'] = False
|
||||
|
||||
response = platform_admin_client.get(url_for('main.service_settings', service_id=service_one['id']))
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.service_settings',
|
||||
service_id=service_one['id'],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert 'Delete service' not in {a.text for a in page.find_all('a', class_='button')}
|
||||
|
||||
|
||||
@@ -4294,7 +4294,8 @@ def test_suspend_service_prompts_user(
|
||||
|
||||
|
||||
def test_cant_suspend_inactive_service(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
single_reply_to_email_address,
|
||||
single_letter_contact_block,
|
||||
@@ -4303,10 +4304,12 @@ def test_cant_suspend_inactive_service(
|
||||
):
|
||||
service_one['active'] = False
|
||||
|
||||
response = platform_admin_client.get(url_for('main.service_settings', service_id=service_one['id']))
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.service_settings',
|
||||
service_id=service_one['id'],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert 'Suspend service' not in {a.text for a in page.find_all('a', class_='button')}
|
||||
|
||||
|
||||
@@ -4365,17 +4368,19 @@ def test_resume_service_prompts_user(
|
||||
|
||||
|
||||
def test_cant_resume_active_service(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
single_reply_to_email_address,
|
||||
single_letter_contact_block,
|
||||
single_sms_sender,
|
||||
mock_get_service_settings_page_common
|
||||
):
|
||||
response = platform_admin_client.get(url_for('main.service_settings', service_id=service_one['id']))
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.service_settings',
|
||||
service_id=service_one['id'],
|
||||
)
|
||||
assert 'Resume service' not in {a.text for a in page.find_all('a', class_='button')}
|
||||
|
||||
|
||||
@@ -4692,18 +4697,18 @@ def test_updates_sms_prefixing(
|
||||
|
||||
|
||||
def test_select_organisation(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_get_organisation,
|
||||
mock_get_organisations
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for('.link_service_to_organisation', service_id=service_one['id']),
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.link_service_to_organisation',
|
||||
service_id=service_one['id'],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert len(page.select('.govuk-radios__item')) == 3
|
||||
for i in range(0, 3):
|
||||
assert normalize_spaces(
|
||||
@@ -4712,37 +4717,38 @@ def test_select_organisation(
|
||||
|
||||
|
||||
def test_select_organisation_shows_message_if_no_orgs(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_get_organisation,
|
||||
mocker
|
||||
):
|
||||
mocker.patch('app.organisations_client.get_organisations', return_value=[])
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('.link_service_to_organisation', service_id=service_one['id']),
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.link_service_to_organisation',
|
||||
service_id=service_one['id'],
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
assert normalize_spaces(page.select_one('main p').text) == "No organisations"
|
||||
assert not page.select_one('main button')
|
||||
|
||||
|
||||
def test_update_service_organisation(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_get_organisation,
|
||||
mock_get_organisations,
|
||||
mock_update_service_organisation,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for('.link_service_to_organisation', service_id=service_one['id']),
|
||||
data={'organisations': '7aa5d4e9-4385-4488-a489-07812ba13384'},
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.link_service_to_organisation',
|
||||
service_id=service_one['id'],
|
||||
_data={'organisations': '7aa5d4e9-4385-4488-a489-07812ba13384'},
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
mock_update_service_organisation.assert_called_once_with(
|
||||
service_one['id'],
|
||||
'7aa5d4e9-4385-4488-a489-07812ba13384'
|
||||
@@ -4750,7 +4756,8 @@ def test_update_service_organisation(
|
||||
|
||||
|
||||
def test_update_service_organisation_does_not_update_if_same_value(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_get_organisation,
|
||||
mock_get_organisations,
|
||||
@@ -4758,12 +4765,12 @@ def test_update_service_organisation_does_not_update_if_same_value(
|
||||
):
|
||||
org_id = "7aa5d4e9-4385-4488-a489-07812ba13383"
|
||||
service_one['organisation'] = org_id
|
||||
response = platform_admin_client.post(
|
||||
url_for('.link_service_to_organisation', service_id=service_one['id']),
|
||||
data={'organisations': org_id},
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'.link_service_to_organisation',
|
||||
service_id=service_one['id'],
|
||||
_data={'organisations': org_id},
|
||||
)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert mock_update_service_organisation.called is False
|
||||
|
||||
|
||||
@@ -5339,7 +5346,8 @@ def test_service_settings_links_to_branding_request_page_for_letters(
|
||||
|
||||
|
||||
def test_show_service_data_retention(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_get_service_data_retention,
|
||||
|
||||
@@ -5347,172 +5355,198 @@ def test_show_service_data_retention(
|
||||
|
||||
mock_get_service_data_retention.return_value[0]['days_of_retention'] = 5
|
||||
|
||||
response = platform_admin_client.get(url_for('main.data_retention', service_id=service_one['id']))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.data_retention',
|
||||
service_id=service_one['id'],
|
||||
)
|
||||
|
||||
rows = page.select('tbody tr')
|
||||
assert len(rows) == 1
|
||||
assert normalize_spaces(rows[0].text) == 'Email 5 days Change'
|
||||
|
||||
|
||||
def test_view_add_service_data_retention(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
|
||||
):
|
||||
response = platform_admin_client.get(url_for('main.add_data_retention', service_id=service_one['id']))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.add_data_retention',
|
||||
service_id=service_one['id'],
|
||||
)
|
||||
assert normalize_spaces(page.select_one('input')['value']) == "email"
|
||||
assert page.find('input', attrs={'name': 'days_of_retention'})
|
||||
|
||||
|
||||
def test_add_service_data_retention(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_create_service_data_retention
|
||||
):
|
||||
response = platform_admin_client.post(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.add_data_retention',
|
||||
service_id=service_one['id']),
|
||||
data={'notification_type': "email", 'days_of_retention': 5}
|
||||
service_id=service_one['id'],
|
||||
_data={'notification_type': "email", 'days_of_retention': 5},
|
||||
_expected_redirect=url_for(
|
||||
'main.data_retention',
|
||||
service_id=service_one['id'],
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.data_retention', service_id=service_one['id'], _external=True)
|
||||
assert settings_url == response.location
|
||||
assert mock_create_service_data_retention.called
|
||||
|
||||
|
||||
def test_update_service_data_retention(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
mock_get_service_data_retention,
|
||||
mock_update_service_data_retention,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_data_retention',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.edit_data_retention',
|
||||
service_id=service_one['id'],
|
||||
data_retention_id=str(fake_uuid),
|
||||
_data={'days_of_retention': 5},
|
||||
_expected_redirect=url_for(
|
||||
'main.data_retention',
|
||||
service_id=service_one['id'],
|
||||
data_retention_id=str(fake_uuid)),
|
||||
data={'days_of_retention': 5}
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.data_retention', service_id=service_one['id'], _external=True)
|
||||
assert settings_url == response.location
|
||||
assert mock_update_service_data_retention.called
|
||||
|
||||
|
||||
def test_update_service_data_retention_return_validation_error_for_negative_days_of_retention(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
mock_get_service_data_retention,
|
||||
mock_update_service_data_retention,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_data_retention',
|
||||
service_id=service_one['id'],
|
||||
data_retention_id=fake_uuid
|
||||
),
|
||||
data={'days_of_retention': -5}
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'main.edit_data_retention',
|
||||
service_id=service_one['id'],
|
||||
data_retention_id=fake_uuid,
|
||||
_data={'days_of_retention': -5},
|
||||
_expected_status=200,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert 'Must be between 3 and 90' in page.find('span', class_='govuk-error-message').text
|
||||
assert mock_get_service_data_retention.called
|
||||
assert not mock_update_service_data_retention.called
|
||||
|
||||
|
||||
def test_update_service_data_retention_populates_form(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
fake_uuid,
|
||||
mock_get_service_data_retention,
|
||||
):
|
||||
|
||||
mock_get_service_data_retention.return_value[0]['days_of_retention'] = 5
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.edit_data_retention',
|
||||
service_id=service_one['id'],
|
||||
data_retention_id=fake_uuid
|
||||
))
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
data_retention_id=fake_uuid,
|
||||
)
|
||||
assert page.find('input', attrs={'name': 'days_of_retention'})['value'] == '5'
|
||||
|
||||
|
||||
def test_service_settings_links_to_edit_service_notes_page_for_platform_admins(
|
||||
mocker,
|
||||
service_one,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
no_reply_to_email_addresses,
|
||||
no_letter_contact_blocks,
|
||||
single_sms_sender,
|
||||
mock_get_service_settings_page_common,
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
'.service_settings', service_id=SERVICE_ONE_ID
|
||||
))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.service_settings',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert len(page.find_all('a', attrs={'href': '/services/{}/notes'.format(SERVICE_ONE_ID)})) == 1
|
||||
|
||||
|
||||
def test_view_edit_service_notes(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
|
||||
):
|
||||
response = platform_admin_client.get(url_for('main.edit_service_notes', service_id=SERVICE_ONE_ID))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.edit_service_notes',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert page.select_one('h1').text == "Edit service notes"
|
||||
assert page.find('label', class_="form-label").text.strip() == "Notes"
|
||||
assert page.find('textarea').attrs["name"] == "notes"
|
||||
|
||||
|
||||
def test_update_service_notes(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_update_service
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_service_notes',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.edit_service_notes',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'notes': "Very fluffy"},
|
||||
_expected_redirect=url_for(
|
||||
'main.service_settings',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
),
|
||||
data={'notes': "Very fluffy"}
|
||||
_external=True,
|
||||
)
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
assert settings_url == response.location
|
||||
mock_update_service.assert_called_with(SERVICE_ONE_ID, notes="Very fluffy")
|
||||
|
||||
|
||||
def test_service_settings_links_to_edit_service_billing_details_page_for_platform_admins(
|
||||
mocker,
|
||||
service_one,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
no_reply_to_email_addresses,
|
||||
no_letter_contact_blocks,
|
||||
single_sms_sender,
|
||||
mock_get_service_settings_page_common,
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
'.service_settings', service_id=SERVICE_ONE_ID
|
||||
))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.service_settings',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert len(page.find_all('a', attrs={'href': '/services/{}/edit-billing-details'.format(SERVICE_ONE_ID)})) == 1
|
||||
|
||||
|
||||
def test_view_edit_service_billing_details(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
|
||||
):
|
||||
response = platform_admin_client.get(url_for('main.edit_service_billing_details', service_id=SERVICE_ONE_ID))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.edit_service_billing_details',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
|
||||
assert page.select_one('h1').text == "Change billing details"
|
||||
labels = page.find_all('label', class_="form-label")
|
||||
labels_list = [
|
||||
@@ -5539,27 +5573,28 @@ def test_view_edit_service_billing_details(
|
||||
|
||||
|
||||
def test_update_service_billing_details(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
service_one,
|
||||
mock_update_service
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_service_billing_details',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
),
|
||||
data={
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.edit_service_billing_details',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={
|
||||
'billing_contact_email_addresses': 'accounts@fluff.gov.uk',
|
||||
'billing_contact_names': 'Flannellette von Fluff',
|
||||
'billing_reference': '',
|
||||
'purchase_order_number': 'PO1234',
|
||||
'notes': 'very fluffy, give extra allowance'
|
||||
}
|
||||
},
|
||||
_expected_redirect=url_for(
|
||||
'main.service_settings',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
assert response.location == settings_url
|
||||
mock_update_service.assert_called_with(
|
||||
SERVICE_ONE_ID,
|
||||
billing_contact_email_addresses='accounts@fluff.gov.uk',
|
||||
@@ -5571,17 +5606,15 @@ def test_update_service_billing_details(
|
||||
|
||||
|
||||
def test_service_set_broadcast_channel(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.select_one('h1').text.strip() == 'Emergency alerts settings'
|
||||
|
||||
expected_labels = [
|
||||
@@ -5602,16 +5635,14 @@ def test_service_set_broadcast_channel(
|
||||
|
||||
|
||||
def test_service_set_broadcast_channel_has_no_radio_selected_for_non_broadcast_service(
|
||||
platform_admin_client
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
response = platform_admin_client.get(
|
||||
url_for(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert len(page.select('input[checked]')) == 0
|
||||
|
||||
|
||||
@@ -5635,7 +5666,8 @@ def test_service_set_broadcast_channel_has_no_radio_selected_for_non_broadcast_s
|
||||
]
|
||||
)
|
||||
def test_service_set_broadcast_channel_has_radio_selected_for_broadcast_service(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
service_mode,
|
||||
broadcast_channel,
|
||||
@@ -5652,14 +5684,12 @@ def test_service_set_broadcast_channel_has_radio_selected_for_broadcast_service(
|
||||
)
|
||||
mocker.patch('app.service_api_client.get_service', return_value={'data': service_one})
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
client_request.login(platform_admin_user, service_one)
|
||||
page = client_request.get(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
|
||||
selected_radios = page.select('input[checked]')
|
||||
assert len(selected_radios) == 1
|
||||
|
||||
@@ -5938,7 +5968,8 @@ def test_service_confirm_broadcast_account_type_confirmation_page(
|
||||
]
|
||||
)
|
||||
def test_service_confirm_broadcast_account_type_posts_data_to_api_and_redirects(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
value,
|
||||
service_mode,
|
||||
@@ -5950,15 +5981,17 @@ def test_service_confirm_broadcast_account_type_posts_data_to_api_and_redirects(
|
||||
set_service_broadcast_settings_mock = mocker.patch('app.service_api_client.set_service_broadcast_settings')
|
||||
mock_event_handler = mocker.patch('app.main.views.service_settings.create_broadcast_account_type_change_event')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.service_confirm_broadcast_account_type',
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.service_confirm_broadcast_account_type',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
account_type=value,
|
||||
_expected_redirect=url_for(
|
||||
'main.service_settings',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
account_type=value,
|
||||
)
|
||||
_external=True,
|
||||
),
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
set_service_broadcast_settings_mock.assert_called_once_with(
|
||||
SERVICE_ONE_ID,
|
||||
service_mode=service_mode,
|
||||
@@ -5981,34 +6014,33 @@ def test_service_confirm_broadcast_account_type_posts_data_to_api_and_redirects(
|
||||
'live-government-foo'
|
||||
))
|
||||
def test_service_confirm_broadcast_account_type_errors_for_unknown_type(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
account_type,
|
||||
):
|
||||
set_service_broadcast_settings_mock = mocker.patch('app.service_api_client.set_service_broadcast_settings')
|
||||
mock_event_handler = mocker.patch('app.main.views.service_settings.create_broadcast_account_type_change_event')
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.service_confirm_broadcast_account_type',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
account_type=account_type,
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.service_confirm_broadcast_account_type',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
account_type=account_type,
|
||||
_expected_status=404,
|
||||
)
|
||||
assert response.status_code == 404
|
||||
assert not set_service_broadcast_settings_mock.called
|
||||
assert not mock_event_handler.called
|
||||
|
||||
|
||||
def test_service_set_broadcast_channel_makes_you_choose(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.post(
|
||||
'main.service_set_broadcast_channel',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_expected_status=200,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert 'Error: Select mode or channel' in page.find("span", {"class": "govuk-error-message"}).text
|
||||
|
||||
@@ -1083,7 +1083,7 @@ def test_should_show_message_with_prefix_hint_if_enabled_for_service(
|
||||
|
||||
|
||||
def test_should_show_page_template_with_priority_select_if_platform_admin(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
mock_get_service_template,
|
||||
@@ -1092,16 +1092,16 @@ def test_should_show_page_template_with_priority_select_if_platform_admin(
|
||||
):
|
||||
mocker.patch('app.user_api_client.get_users_for_service', return_value=[platform_admin_user])
|
||||
template_id = fake_uuid
|
||||
response = platform_admin_client.get(url_for(
|
||||
client_request.login(platform_admin_user)
|
||||
page = client_request.get(
|
||||
'.edit_service_template',
|
||||
service_id=service_one['id'],
|
||||
template_id=template_id,
|
||||
))
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "Two week reminder" in response.get_data(as_text=True)
|
||||
assert "Template <em>content</em> with & entity" in response.get_data(as_text=True)
|
||||
assert "Use priority queue?" in response.get_data(as_text=True)
|
||||
assert page.select_one('input[name=name]')['value'] == "Two week reminder"
|
||||
assert "Template <em>content</em> with & entity" in str(page.select_one('textarea'))
|
||||
assert "Use priority queue?" in page.text
|
||||
mock_get_service_template.assert_called_with(service_one['id'], template_id, None)
|
||||
|
||||
|
||||
@@ -1167,7 +1167,8 @@ def test_dont_show_preview_letter_templates_for_bad_filetype(
|
||||
])
|
||||
def test_letter_branding_preview_image(
|
||||
mocker,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
original_filename,
|
||||
new_filename,
|
||||
):
|
||||
@@ -1175,8 +1176,11 @@ def test_letter_branding_preview_image(
|
||||
'app.main.views.templates.TemplatePreview.from_example_template',
|
||||
return_value='foo'
|
||||
)
|
||||
resp = platform_admin_client.get(
|
||||
url_for('no_cookie.letter_branding_preview_image', filename=original_filename)
|
||||
client_request.login(platform_admin_user)
|
||||
resp = client_request.get(
|
||||
'no_cookie.letter_branding_preview_image',
|
||||
filename=original_filename,
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
mocked_preview.assert_called_with(
|
||||
|
||||
@@ -46,14 +46,16 @@ def test_begin_register_forbidden_unless_can_use_webauthn(
|
||||
def test_begin_register_returns_encoded_options(
|
||||
mocker,
|
||||
platform_admin_user,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
webauthn_dev_server,
|
||||
):
|
||||
mocker.patch('app.models.webauthn_credential.WebAuthnCredentials.client_method', return_value=[])
|
||||
|
||||
response = platform_admin_client.get(url_for('main.webauthn_begin_register'))
|
||||
|
||||
assert response.status_code == 200
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.get(
|
||||
'main.webauthn_begin_register',
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
webauthn_options = cbor.decode(response.data)['publicKey']
|
||||
assert webauthn_options['attestation'] == 'direct'
|
||||
@@ -73,7 +75,8 @@ def test_begin_register_returns_encoded_options(
|
||||
|
||||
|
||||
def test_begin_register_includes_existing_credentials(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
webauthn_credential,
|
||||
mocker,
|
||||
):
|
||||
@@ -82,8 +85,10 @@ def test_begin_register_includes_existing_credentials(
|
||||
return_value=[webauthn_credential, webauthn_credential]
|
||||
)
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('main.webauthn_begin_register')
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.get(
|
||||
'main.webauthn_begin_register',
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
webauthn_options = cbor.decode(response.data)['publicKey']
|
||||
@@ -91,30 +96,33 @@ def test_begin_register_includes_existing_credentials(
|
||||
|
||||
|
||||
def test_begin_register_stores_state_in_session(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.models.webauthn_credential.WebAuthnCredentials.client_method',
|
||||
return_value=[])
|
||||
|
||||
response = platform_admin_client.get(
|
||||
url_for('main.webauthn_begin_register')
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.get(
|
||||
'main.webauthn_begin_register',
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
assert session['webauthn_registration_state'] is not None
|
||||
|
||||
|
||||
def test_complete_register_creates_credential(
|
||||
platform_admin_user,
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
mock_update_user_attribute,
|
||||
mocker,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['webauthn_registration_state'] = 'state'
|
||||
|
||||
user_api_mock = mocker.patch(
|
||||
@@ -126,12 +134,14 @@ def test_complete_register_creates_credential(
|
||||
return_value='cred'
|
||||
)
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.webauthn_complete_register'),
|
||||
data=cbor.encode('public_key_credential'),
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.webauthn_begin_register',
|
||||
_data=cbor.encode('public_key_credential'),
|
||||
_expected_status=200,
|
||||
_raw_response=True,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
credential_mock.assert_called_once_with('state', 'public_key_credential')
|
||||
user_api_mock.assert_called_once_with(platform_admin_user['id'], 'cred')
|
||||
mock_update_user_attribute.assert_called_once_with(
|
||||
@@ -141,21 +151,24 @@ def test_complete_register_creates_credential(
|
||||
|
||||
|
||||
def test_complete_register_clears_session(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['webauthn_registration_state'] = 'state'
|
||||
|
||||
mocker.patch('app.user_api_client.create_webauthn_credential_for_user')
|
||||
mocker.patch('app.models.webauthn_credential.WebAuthnCredential.from_registration')
|
||||
|
||||
platform_admin_client.post(
|
||||
url_for('main.webauthn_complete_register'),
|
||||
data=cbor.encode('public_key_credential'),
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.webauthn_complete_register',
|
||||
_data=cbor.encode('public_key_credential'),
|
||||
_expected_status=200,
|
||||
)
|
||||
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
assert 'webauthn_registration_state' not in session
|
||||
assert session['_flashes'] == [('default_with_tick', (
|
||||
'Registration complete. Next time you sign in to Notify '
|
||||
@@ -164,10 +177,11 @@ def test_complete_register_clears_session(
|
||||
|
||||
|
||||
def test_complete_register_handles_library_errors(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
with platform_admin_client.session_transaction() as session:
|
||||
with client_request.session_transaction() as session:
|
||||
session['webauthn_registration_state'] = 'state'
|
||||
|
||||
mocker.patch(
|
||||
@@ -175,24 +189,28 @@ def test_complete_register_handles_library_errors(
|
||||
side_effect=RegistrationError('error')
|
||||
)
|
||||
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.webauthn_complete_register'),
|
||||
data=cbor.encode('public_key_credential'),
|
||||
client_request.login(platform_admin_user)
|
||||
client_request.post(
|
||||
'main.webauthn_complete_register',
|
||||
_data=cbor.encode('public_key_credential'),
|
||||
_raw_response=True,
|
||||
_expected_status=400,
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_complete_register_handles_missing_state(
|
||||
platform_admin_client,
|
||||
client_request,
|
||||
platform_admin_user,
|
||||
mocker,
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.webauthn_complete_register'),
|
||||
data=cbor.encode('public_key_credential'),
|
||||
client_request.login(platform_admin_user)
|
||||
response = client_request.post(
|
||||
'main.webauthn_complete_register',
|
||||
_data=cbor.encode('public_key_credential'),
|
||||
_raw_response=True,
|
||||
_expected_status=400,
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
assert cbor.decode(response.data) == 'No registration in progress'
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user