2018-05-08 14:21:52 +01:00
|
|
|
|
from functools import partial
|
2018-03-16 17:27:47 +00:00
|
|
|
|
from io import BytesIO
|
2020-04-02 12:56:47 +01:00
|
|
|
|
from unittest.mock import call
|
2018-03-16 17:27:47 +00:00
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
from flask import url_for
|
2019-06-18 14:24:29 +01:00
|
|
|
|
from freezegun import freeze_time
|
2018-04-25 14:12:58 +01:00
|
|
|
|
|
2019-06-18 14:24:29 +01:00
|
|
|
|
from tests import organisation_json
|
2020-03-20 08:42:33 +00:00
|
|
|
|
from tests.conftest import ORGANISATION_ID, SERVICE_ONE_ID, normalize_spaces
|
2018-03-16 17:27:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MockS3Object():
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, data=None):
|
|
|
|
|
|
self.data = data or b''
|
|
|
|
|
|
|
|
|
|
|
|
def get(self):
|
|
|
|
|
|
return {'Body': BytesIO(self.data)}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-04-04 11:17:35 +01:00
|
|
|
|
@pytest.mark.parametrize('agreement_signed, crown, expected_links', [
|
2018-05-08 14:21:52 +01:00
|
|
|
|
(
|
2019-04-04 11:17:35 +01:00
|
|
|
|
True, True,
|
2018-05-08 14:21:52 +01:00
|
|
|
|
[
|
2019-07-12 09:03:35 +01:00
|
|
|
|
(
|
|
|
|
|
|
['govuk-back-link'],
|
|
|
|
|
|
partial(url_for, 'main.request_to_go_live', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-02-12 16:26:08 +00:00
|
|
|
|
['govuk-link', 'govuk-link--no-visited-state'],
|
2019-07-12 09:03:35 +01:00
|
|
|
|
partial(url_for, 'main.service_download_agreement', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
2018-05-08 14:21:52 +01:00
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-04-04 11:17:35 +01:00
|
|
|
|
False, False,
|
2018-05-08 14:21:52 +01:00
|
|
|
|
[
|
2019-07-12 09:03:35 +01:00
|
|
|
|
(
|
|
|
|
|
|
['govuk-back-link'],
|
|
|
|
|
|
partial(url_for, 'main.request_to_go_live', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-02-12 16:26:08 +00:00
|
|
|
|
['govuk-link', 'govuk-link--no-visited-state'],
|
2019-07-12 09:03:35 +01:00
|
|
|
|
partial(url_for, 'main.service_download_agreement', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-01-30 14:01:13 +00:00
|
|
|
|
['govuk-button'],
|
2019-07-12 09:03:35 +01:00
|
|
|
|
partial(url_for, 'main.service_accept_agreement', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
2019-06-18 14:24:29 +01:00
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
False, True,
|
|
|
|
|
|
[
|
2019-07-12 09:03:35 +01:00
|
|
|
|
(
|
|
|
|
|
|
['govuk-back-link'],
|
|
|
|
|
|
partial(url_for, 'main.request_to_go_live', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-02-12 16:26:08 +00:00
|
|
|
|
['govuk-link', 'govuk-link--no-visited-state'],
|
2019-07-12 09:03:35 +01:00
|
|
|
|
partial(url_for, 'main.service_download_agreement', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-01-30 14:01:13 +00:00
|
|
|
|
['govuk-button'],
|
2019-07-12 09:03:35 +01:00
|
|
|
|
partial(url_for, 'main.service_accept_agreement', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
2018-05-08 14:21:52 +01:00
|
|
|
|
]
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2019-04-04 11:17:35 +01:00
|
|
|
|
None, None,
|
2018-05-08 14:21:52 +01:00
|
|
|
|
[
|
2019-07-12 09:03:35 +01:00
|
|
|
|
(
|
|
|
|
|
|
['govuk-back-link'],
|
|
|
|
|
|
partial(url_for, 'main.request_to_go_live', service_id=SERVICE_ONE_ID),
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
2020-02-12 16:26:08 +00:00
|
|
|
|
['govuk-link', 'govuk-link--no-visited-state'],
|
2019-07-12 09:03:35 +01:00
|
|
|
|
partial(url_for, 'main.support'),
|
|
|
|
|
|
),
|
2018-05-08 14:21:52 +01:00
|
|
|
|
]
|
|
|
|
|
|
),
|
2018-03-16 17:27:47 +00:00
|
|
|
|
])
|
|
|
|
|
|
def test_show_agreement_page(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2019-05-01 08:29:32 +01:00
|
|
|
|
mock_has_jobs,
|
2019-04-04 11:17:35 +01:00
|
|
|
|
agreement_signed,
|
|
|
|
|
|
crown,
|
2018-05-08 14:21:52 +01:00
|
|
|
|
expected_links,
|
2018-03-16 17:27:47 +00:00
|
|
|
|
):
|
2019-12-20 15:02:47 +00:00
|
|
|
|
org = organisation_json(
|
2019-04-04 11:17:35 +01:00
|
|
|
|
crown=crown,
|
2019-12-20 15:02:47 +00:00
|
|
|
|
agreement_signed=agreement_signed
|
2019-04-04 11:17:35 +01:00
|
|
|
|
)
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mocker.patch('app.organisations_client.get_organisation', return_value=org)
|
2019-12-20 15:02:47 +00:00
|
|
|
|
|
2019-07-12 09:03:35 +01:00
|
|
|
|
page = client_request.get('main.service_agreement', service_id=SERVICE_ONE_ID)
|
2020-02-20 16:55:56 +00:00
|
|
|
|
links = page.select('main .govuk-grid-column-five-sixths a')
|
2018-05-08 14:21:52 +01:00
|
|
|
|
assert len(links) == len(expected_links)
|
|
|
|
|
|
for index, link in enumerate(links):
|
2019-07-12 09:03:35 +01:00
|
|
|
|
classes, url = expected_links[index]
|
|
|
|
|
|
assert link.get('class', []) == classes
|
|
|
|
|
|
assert link['href'] == url()
|
2018-03-16 17:27:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
2019-09-05 16:18:02 +01:00
|
|
|
|
@pytest.mark.parametrize('org_type, expected_endpoint', (
|
|
|
|
|
|
('nhs_gp', 'main.add_organisation_from_gp_service'),
|
|
|
|
|
|
('nhs_local', 'main.add_organisation_from_nhs_local_service'),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_unknown_gps_and_trusts_are_redirected(
|
2019-09-04 16:27:25 +01:00
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
mock_has_jobs,
|
|
|
|
|
|
service_one,
|
2019-09-05 16:18:02 +01:00
|
|
|
|
org_type,
|
|
|
|
|
|
expected_endpoint,
|
2019-09-04 16:27:25 +01:00
|
|
|
|
):
|
|
|
|
|
|
service_one['organisation_id'] = None
|
2019-09-05 16:18:02 +01:00
|
|
|
|
service_one['organisation_type'] = org_type
|
2019-09-04 16:27:25 +01:00
|
|
|
|
client_request.get(
|
|
|
|
|
|
'main.service_agreement',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
2019-09-05 16:18:02 +01:00
|
|
|
|
expected_endpoint,
|
2019-09-04 16:27:25 +01:00
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-02 17:04:26 +01:00
|
|
|
|
@pytest.mark.parametrize('crown, expected_status, expected_file_fetched, expected_file_served', (
|
|
|
|
|
|
(
|
|
|
|
|
|
True, 200, 'crown.pdf',
|
|
|
|
|
|
'GOV.UK Notify data sharing and financial agreement.pdf',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
False, 200, 'non-crown.pdf',
|
|
|
|
|
|
'GOV.UK Notify data sharing and financial agreement (non-crown).pdf',
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
None, 404, None,
|
|
|
|
|
|
None,
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_download_service_agreement(
|
|
|
|
|
|
logged_in_client,
|
|
|
|
|
|
mocker,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2019-07-02 17:04:26 +01:00
|
|
|
|
crown,
|
|
|
|
|
|
expected_status,
|
|
|
|
|
|
expected_file_fetched,
|
|
|
|
|
|
expected_file_served,
|
|
|
|
|
|
):
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.models.organisation.organisations_client.get_organisation',
|
2019-07-02 17:04:26 +01:00
|
|
|
|
return_value=organisation_json(
|
|
|
|
|
|
crown=crown
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_get_s3_object = mocker.patch(
|
|
|
|
|
|
'app.s3_client.s3_mou_client.get_s3_object',
|
|
|
|
|
|
return_value=_MockS3Object(b'foo')
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
response = logged_in_client.get(url_for(
|
|
|
|
|
|
'main.service_download_agreement',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
))
|
|
|
|
|
|
assert response.status_code == expected_status
|
|
|
|
|
|
|
|
|
|
|
|
if expected_file_served:
|
|
|
|
|
|
assert response.get_data() == b'foo'
|
|
|
|
|
|
assert response.headers['Content-Type'] == 'application/pdf'
|
|
|
|
|
|
assert response.headers['Content-Disposition'] == (
|
|
|
|
|
|
'attachment; filename="{}"'.format(expected_file_served)
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_get_s3_object.assert_called_once_with('test-mou', expected_file_fetched)
|
|
|
|
|
|
else:
|
|
|
|
|
|
assert not expected_file_fetched
|
|
|
|
|
|
assert mock_get_s3_object.called is False
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-18 14:24:29 +01:00
|
|
|
|
def test_show_accept_agreement_page(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mock_get_organisation,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.get('main.service_accept_agreement', service_id=SERVICE_ONE_ID)
|
|
|
|
|
|
|
|
|
|
|
|
assert [
|
|
|
|
|
|
(input['type'], input['name'], input.get('id')) for input in page.select('input')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
('radio', 'who', 'who-0'),
|
|
|
|
|
|
('radio', 'who', 'who-1'),
|
|
|
|
|
|
('text', 'on_behalf_of_name', 'on_behalf_of_name'),
|
|
|
|
|
|
('email', 'on_behalf_of_email', 'on_behalf_of_email'),
|
2019-07-19 16:20:27 +01:00
|
|
|
|
('text', 'version', 'version'),
|
2019-06-18 14:24:29 +01:00
|
|
|
|
('hidden', 'csrf_token', None),
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('label[for=version]').text) == (
|
2019-07-19 16:20:27 +01:00
|
|
|
|
'Which version of the agreement do you want to accept? '
|
2019-06-18 14:24:29 +01:00
|
|
|
|
'The version number is on the front page, for example ‘3.6’'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select_one('input[name=version]')['value'] == ''
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('#who legend').text) == (
|
2019-07-19 16:20:27 +01:00
|
|
|
|
'Who are you accepting the agreement for?'
|
2019-06-18 14:24:29 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('label[for=who-0]').text) == (
|
2019-07-19 16:20:27 +01:00
|
|
|
|
'Yourself'
|
2019-06-18 14:24:29 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert page.select('input[name=who]')[0]['value'] == 'me'
|
2019-06-18 15:26:04 +01:00
|
|
|
|
assert 'checked' not in page.select('input[name=who]')[0]
|
2019-06-18 16:02:37 +01:00
|
|
|
|
assert 'data-target' not in page.select('.multiple-choice')[0]
|
2019-06-18 14:24:29 +01:00
|
|
|
|
assert normalize_spaces(page.select_one('label[for=who-1]').text) == (
|
2019-07-19 16:20:27 +01:00
|
|
|
|
'Someone else'
|
2019-06-18 14:24:29 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert page.select('input[name=who]')[1]['value'] == 'someone-else'
|
2019-06-18 15:26:04 +01:00
|
|
|
|
assert 'checked' not in page.select('input[name=who]')[1]
|
2019-06-18 16:02:37 +01:00
|
|
|
|
assert page.select('.multiple-choice')[1]['data-target'] == 'on-behalf-of'
|
|
|
|
|
|
assert [
|
|
|
|
|
|
field['name']
|
2019-09-05 12:10:24 +01:00
|
|
|
|
for field in page.select('#on-behalf-of.conditional-radios-panel input')
|
2019-06-18 16:02:37 +01:00
|
|
|
|
] == [
|
|
|
|
|
|
'on_behalf_of_name', 'on_behalf_of_email'
|
|
|
|
|
|
]
|
2019-06-18 14:24:29 +01:00
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('label[for=on_behalf_of_name]').text) == (
|
2019-07-19 16:20:27 +01:00
|
|
|
|
'What’s their name?'
|
2019-06-18 14:24:29 +01:00
|
|
|
|
)
|
|
|
|
|
|
assert page.select_one('input[name=on_behalf_of_name]')['value'] == ''
|
|
|
|
|
|
|
|
|
|
|
|
assert normalize_spaces(page.select_one('label[for=on_behalf_of_email]').text) == (
|
|
|
|
|
|
'What’s their email address?'
|
|
|
|
|
|
)
|
|
|
|
|
|
assert page.select_one('input[name=on_behalf_of_email]')['value'] == ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_accept_agreement_page_populates(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
):
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.models.organisation.organisations_client.get_organisation',
|
2019-06-18 14:24:29 +01:00
|
|
|
|
return_value=organisation_json(
|
|
|
|
|
|
agreement_signed_version='1.2',
|
|
|
|
|
|
agreement_signed_on_behalf_of_name='Firstname Lastname',
|
|
|
|
|
|
agreement_signed_on_behalf_of_email_address='test@example.com',
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
page = client_request.get('main.service_accept_agreement', service_id=SERVICE_ONE_ID)
|
|
|
|
|
|
|
|
|
|
|
|
assert [
|
|
|
|
|
|
(field['name'], field['value']) for field in page.select('input[type=text], input[type=email]')
|
|
|
|
|
|
] == [
|
|
|
|
|
|
('on_behalf_of_name', 'Firstname Lastname'),
|
|
|
|
|
|
('on_behalf_of_email', 'test@example.com'),
|
2019-07-19 16:20:27 +01:00
|
|
|
|
('version', '1.2'),
|
2019-06-18 14:24:29 +01:00
|
|
|
|
]
|
2019-06-18 15:26:04 +01:00
|
|
|
|
assert 'checked' not in page.select('input[name=who]')[0]
|
|
|
|
|
|
assert page.select('input[name=who]')[1]['checked'] == ''
|
2019-06-18 14:24:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-06-18 15:26:04 +01:00
|
|
|
|
@pytest.mark.parametrize('data, expected_errors', (
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': '',
|
|
|
|
|
|
'on_behalf_of_name': '',
|
|
|
|
|
|
'on_behalf_of_email': '',
|
|
|
|
|
|
},
|
|
|
|
|
|
[
|
2020-04-22 17:49:03 +01:00
|
|
|
|
'Select an option',
|
2019-07-19 16:20:27 +01:00
|
|
|
|
'Must be a number',
|
2019-06-18 15:26:04 +01:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': 'one point two',
|
|
|
|
|
|
'who': 'me',
|
|
|
|
|
|
'on_behalf_of_name': '',
|
|
|
|
|
|
'on_behalf_of_email': '',
|
|
|
|
|
|
},
|
|
|
|
|
|
[
|
|
|
|
|
|
'Must be a number',
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': '1.2',
|
|
|
|
|
|
'who': 'someone-else',
|
|
|
|
|
|
'on_behalf_of_name': '',
|
|
|
|
|
|
'on_behalf_of_email': '',
|
|
|
|
|
|
},
|
|
|
|
|
|
[
|
2019-09-12 16:54:13 +01:00
|
|
|
|
'Cannot be empty',
|
|
|
|
|
|
'Cannot be empty',
|
2019-06-18 15:26:04 +01:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': '1.2',
|
|
|
|
|
|
'who': 'someone-else',
|
|
|
|
|
|
'on_behalf_of_name': 'Firstname Lastname',
|
|
|
|
|
|
'on_behalf_of_email': '',
|
|
|
|
|
|
},
|
|
|
|
|
|
[
|
2019-09-12 16:54:13 +01:00
|
|
|
|
'Cannot be empty',
|
2019-06-18 15:26:04 +01:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': '1.2',
|
|
|
|
|
|
'who': 'someone-else',
|
|
|
|
|
|
'on_behalf_of_name': '',
|
|
|
|
|
|
'on_behalf_of_email': 'test@example.com',
|
|
|
|
|
|
},
|
|
|
|
|
|
[
|
2019-09-12 16:54:13 +01:00
|
|
|
|
'Cannot be empty',
|
2019-06-18 15:26:04 +01:00
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
))
|
2019-06-18 14:24:29 +01:00
|
|
|
|
def test_accept_agreement_page_validates(
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mocker,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
client_request,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
data,
|
|
|
|
|
|
expected_errors,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
):
|
|
|
|
|
|
page = client_request.post(
|
|
|
|
|
|
'main.service_accept_agreement',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
_data=data,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
_expected_status=200,
|
|
|
|
|
|
)
|
|
|
|
|
|
assert [
|
|
|
|
|
|
error.text.strip() for error in page.select('.error-message')
|
2019-06-18 15:26:04 +01:00
|
|
|
|
] == expected_errors
|
2019-06-18 14:24:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
2019-06-18 15:26:04 +01:00
|
|
|
|
@pytest.mark.parametrize('data, expected_persisted', (
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': '1.2',
|
|
|
|
|
|
'who': 'someone-else',
|
|
|
|
|
|
'on_behalf_of_name': 'Firstname Lastname',
|
|
|
|
|
|
'on_behalf_of_email': 'test@example.com',
|
|
|
|
|
|
},
|
|
|
|
|
|
call(
|
2020-03-20 08:42:33 +00:00
|
|
|
|
ORGANISATION_ID,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
agreement_signed_version=1.2,
|
|
|
|
|
|
agreement_signed_on_behalf_of_name='Firstname Lastname',
|
|
|
|
|
|
agreement_signed_on_behalf_of_email_address='test@example.com',
|
2019-10-03 11:57:24 +01:00
|
|
|
|
cached_service_ids=None,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': '1.2',
|
|
|
|
|
|
'who': 'me',
|
|
|
|
|
|
'on_behalf_of_name': 'Firstname Lastname',
|
|
|
|
|
|
'on_behalf_of_email': 'test@example.com',
|
|
|
|
|
|
},
|
|
|
|
|
|
call(
|
2020-03-20 08:42:33 +00:00
|
|
|
|
ORGANISATION_ID,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
agreement_signed_version=1.2,
|
|
|
|
|
|
agreement_signed_on_behalf_of_name='',
|
|
|
|
|
|
agreement_signed_on_behalf_of_email_address='',
|
2019-10-03 11:57:24 +01:00
|
|
|
|
cached_service_ids=None,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
(
|
|
|
|
|
|
{
|
|
|
|
|
|
'version': '1.2',
|
|
|
|
|
|
'who': 'me',
|
|
|
|
|
|
'on_behalf_of_name': '',
|
|
|
|
|
|
'on_behalf_of_email': '',
|
|
|
|
|
|
},
|
|
|
|
|
|
call(
|
2020-03-20 08:42:33 +00:00
|
|
|
|
ORGANISATION_ID,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
agreement_signed_version=1.2,
|
|
|
|
|
|
agreement_signed_on_behalf_of_name='',
|
|
|
|
|
|
agreement_signed_on_behalf_of_email_address='',
|
2019-10-03 11:57:24 +01:00
|
|
|
|
cached_service_ids=None,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
)
|
|
|
|
|
|
),
|
|
|
|
|
|
))
|
2019-06-18 14:24:29 +01:00
|
|
|
|
def test_accept_agreement_page_persists(
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mocker,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
client_request,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
mock_update_organisation,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
data,
|
|
|
|
|
|
expected_persisted,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
):
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.service_accept_agreement',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
2019-06-18 15:26:04 +01:00
|
|
|
|
_data=data,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
_expected_status=302,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.service_confirm_agreement',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
2019-06-18 15:26:04 +01:00
|
|
|
|
assert mock_update_organisation.call_args_list == [expected_persisted]
|
2019-06-18 14:24:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('name, email, expected_paragraph', (
|
|
|
|
|
|
(None, None, (
|
|
|
|
|
|
'I confirm that I have the legal authority to accept the '
|
|
|
|
|
|
'GOV.UK Notify data sharing and financial agreement (version '
|
|
|
|
|
|
'1.2) and that Test Organisation will be bound by it.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
('Firstname Lastname', 'test@example.com', (
|
|
|
|
|
|
'I confirm that I have the legal authority to accept the '
|
|
|
|
|
|
'GOV.UK Notify data sharing and financial agreement (version '
|
|
|
|
|
|
'1.2) on behalf of Firstname Lastname (test@example.com) and '
|
|
|
|
|
|
'that Test Organisation will be bound by it.'
|
|
|
|
|
|
)),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_show_confirm_agreement_page(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
name,
|
|
|
|
|
|
email,
|
|
|
|
|
|
expected_paragraph,
|
|
|
|
|
|
):
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.models.organisation.organisations_client.get_organisation',
|
2019-06-18 14:24:29 +01:00
|
|
|
|
return_value=organisation_json(
|
|
|
|
|
|
agreement_signed_version='1.2',
|
|
|
|
|
|
agreement_signed_on_behalf_of_name=name,
|
|
|
|
|
|
agreement_signed_on_behalf_of_email_address=email,
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
page = client_request.get('main.service_confirm_agreement', service_id=SERVICE_ONE_ID)
|
|
|
|
|
|
assert normalize_spaces(page.select_one('main p').text) == expected_paragraph
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('http_method', ('get', 'post'))
|
|
|
|
|
|
def test_confirm_agreement_page_403s_if_previous_step_not_taken(
|
|
|
|
|
|
client_request,
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mock_get_organisation,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
http_method,
|
|
|
|
|
|
):
|
|
|
|
|
|
getattr(client_request, http_method)(
|
|
|
|
|
|
'main.service_confirm_agreement',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_expected_status=403,
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@freeze_time("2012-01-01 01:01")
|
|
|
|
|
|
def test_confirm_agreement_page_persists(
|
|
|
|
|
|
client_request,
|
|
|
|
|
|
mocker,
|
2020-04-02 12:56:47 +01:00
|
|
|
|
mock_get_service_organisation,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
mock_update_organisation,
|
|
|
|
|
|
fake_uuid,
|
|
|
|
|
|
):
|
2020-03-20 08:42:33 +00:00
|
|
|
|
mocker.patch(
|
|
|
|
|
|
'app.models.organisation.organisations_client.get_organisation',
|
2019-06-18 14:24:29 +01:00
|
|
|
|
return_value=organisation_json(agreement_signed_version='1.2')
|
|
|
|
|
|
)
|
|
|
|
|
|
client_request.post(
|
|
|
|
|
|
'main.service_confirm_agreement',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_expected_redirect=url_for(
|
|
|
|
|
|
'main.request_to_go_live',
|
|
|
|
|
|
service_id=SERVICE_ONE_ID,
|
|
|
|
|
|
_external=True,
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
mock_update_organisation.assert_called_once_with(
|
|
|
|
|
|
'1234',
|
|
|
|
|
|
agreement_signed=True,
|
|
|
|
|
|
agreement_signed_at='2012-01-01 01:01:00',
|
|
|
|
|
|
agreement_signed_by_id=fake_uuid,
|
2019-10-03 11:57:24 +01:00
|
|
|
|
cached_service_ids=None,
|
2019-06-18 14:24:29 +01:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-08 14:06:26 +01:00
|
|
|
|
@pytest.mark.parametrize('endpoint', (
|
|
|
|
|
|
'main.public_agreement',
|
|
|
|
|
|
'main.public_download_agreement',
|
|
|
|
|
|
))
|
|
|
|
|
|
@pytest.mark.parametrize('variant, expected_status', (
|
|
|
|
|
|
('crown', 200),
|
|
|
|
|
|
('non-crown', 200),
|
|
|
|
|
|
('foo', 404),
|
|
|
|
|
|
))
|
|
|
|
|
|
def test_show_public_agreement_page(
|
|
|
|
|
|
client,
|
|
|
|
|
|
mocker,
|
|
|
|
|
|
endpoint,
|
|
|
|
|
|
variant,
|
|
|
|
|
|
expected_status,
|
|
|
|
|
|
):
|
|
|
|
|
|
mocker.patch(
|
2019-01-30 09:42:15 +00:00
|
|
|
|
'app.s3_client.s3_mou_client.get_s3_object',
|
2018-05-08 14:06:26 +01:00
|
|
|
|
return_value=_MockS3Object()
|
|
|
|
|
|
)
|
|
|
|
|
|
response = client.get(url_for(
|
|
|
|
|
|
endpoint,
|
|
|
|
|
|
variant=variant,
|
|
|
|
|
|
))
|
|
|
|
|
|
assert response.status_code == expected_status
|