mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Add endpoints to serve the agreement
Rather than making users contact us to get the agreement, we should just let them download it, when we know which version to send them. This commit adds two endpoints: - one to serve a page which links to the agreement - one to serve the agreement itself These pages are not linked to anywhere because the underlying files don’t exist yet. So I haven’t bothered putting real content on the page yet either. I imagine the deploy sequence will be: 1. Upload the files to the buckets in each environment 2. Deploy this code through each enviroment, checking the links work 3. Make another PR to start linking to the endpoints added by this commit
This commit is contained in:
103
tests/app/main/views/test_agreement.py
Normal file
103
tests/app/main/views/test_agreement.py
Normal file
@@ -0,0 +1,103 @@
|
||||
from io import BytesIO
|
||||
|
||||
import pytest
|
||||
from flask import url_for
|
||||
from tests.conftest import active_user_with_permissions
|
||||
|
||||
|
||||
class _MockS3Object():
|
||||
|
||||
def __init__(self, data=None):
|
||||
self.data = data or b''
|
||||
|
||||
def get(self):
|
||||
return {'Body': BytesIO(self.data)}
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address, expected_status', [
|
||||
('test@cabinet-office.gov.uk', 200),
|
||||
('test@aylesburytowncouncil.gov.uk', 200),
|
||||
('test@unknown.gov.uk', 404),
|
||||
])
|
||||
def test_show_agreement_page(
|
||||
client_request,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
email_address,
|
||||
expected_status,
|
||||
):
|
||||
user = active_user_with_permissions(fake_uuid)
|
||||
user.email_address = email_address
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
client_request.get(
|
||||
'main.agreement',
|
||||
_expected_status=expected_status,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('email_address, expected_file_fetched, expected_file_served', [
|
||||
(
|
||||
'test@cabinet-office.gov.uk',
|
||||
'crown.pdf',
|
||||
'GOV.UK Notify data sharing and financial agreement.pdf',
|
||||
),
|
||||
(
|
||||
'test@aylesburytowncouncil.gov.uk',
|
||||
'non-crown.pdf',
|
||||
'GOV.UK Notify data sharing and financial agreement (non-crown).pdf',
|
||||
),
|
||||
])
|
||||
def test_downloading_agreement(
|
||||
logged_in_client,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
email_address,
|
||||
expected_file_fetched,
|
||||
expected_file_served,
|
||||
):
|
||||
mock_get_s3_object = mocker.patch(
|
||||
'app.main.s3_client.get_s3_object',
|
||||
return_value=_MockS3Object(b'foo')
|
||||
)
|
||||
user = active_user_with_permissions(fake_uuid)
|
||||
user.email_address = email_address
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
response = logged_in_client.get(url_for('main.download_agreement'))
|
||||
assert response.status_code == 200
|
||||
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)
|
||||
|
||||
|
||||
def test_agreement_cant_be_downloaded_unknown_crown_status(
|
||||
logged_in_client,
|
||||
mocker,
|
||||
fake_uuid,
|
||||
):
|
||||
mock_get_s3_object = mocker.patch(
|
||||
'app.main.s3_client.get_s3_object',
|
||||
return_value=_MockS3Object()
|
||||
)
|
||||
user = active_user_with_permissions(fake_uuid)
|
||||
user.email_address = 'test@unknown.gov.uk'
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
response = logged_in_client.get(url_for('main.download_agreement'))
|
||||
assert response.status_code == 404
|
||||
assert mock_get_s3_object.call_args_list == []
|
||||
|
||||
|
||||
def test_agreement_requires_login(
|
||||
client,
|
||||
mocker,
|
||||
):
|
||||
mock_get_s3_object = mocker.patch(
|
||||
'app.main.s3_client.get_s3_object',
|
||||
return_value=_MockS3Object()
|
||||
)
|
||||
response = client.get(url_for('main.download_agreement'))
|
||||
assert response.status_code == 302
|
||||
assert response.location == 'http://localhost/sign-in?next=%2Fagreement.pdf'
|
||||
assert mock_get_s3_object.call_args_list == []
|
||||
Reference in New Issue
Block a user