mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-13 09:50:08 -04:00
Update for new template preview sanitise response
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import base64
|
||||
import uuid
|
||||
from io import BytesIO
|
||||
|
||||
@@ -51,6 +52,7 @@ def upload_letter(service_id):
|
||||
return invalid_upload_error('Your file must be smaller than 2MB')
|
||||
|
||||
try:
|
||||
# TODO: get page count from the sanitise response once template preview handles malformed files nicely
|
||||
page_count = pdf_page_count(BytesIO(pdf_file_bytes))
|
||||
except PdfReadError:
|
||||
current_app.logger.info('Invalid PDF uploaded for service_id: {}'.format(service_id))
|
||||
@@ -70,7 +72,8 @@ def upload_letter(service_id):
|
||||
raise ex
|
||||
else:
|
||||
status = 'valid'
|
||||
upload_letter_to_s3(response.content, file_location, status)
|
||||
file_contents = base64.b64decode(response.json()['file'].encode())
|
||||
upload_letter_to_s3(file_contents, file_location, status)
|
||||
|
||||
return redirect(
|
||||
url_for(
|
||||
|
||||
@@ -28,7 +28,10 @@ def test_get_upload_letter(client_request):
|
||||
def test_post_upload_letter_redirects_for_valid_file(mocker, client_request):
|
||||
mocker.patch('uuid.uuid4', return_value='fake-uuid')
|
||||
antivirus_mock = mocker.patch('app.main.views.uploads.antivirus_client.scan', return_value=True)
|
||||
mocker.patch('app.main.views.uploads.sanitise_letter', return_value=Mock(content='The sanitised content'))
|
||||
mocker.patch(
|
||||
'app.main.views.uploads.sanitise_letter',
|
||||
return_value=Mock(content='The sanitised content', json=lambda: {'file': 'VGhlIHNhbml0aXNlZCBjb250ZW50'})
|
||||
)
|
||||
mock_s3 = mocker.patch('app.main.views.uploads.upload_letter_to_s3')
|
||||
mocker.patch('app.main.views.uploads.service_api_client.get_precompiled_template')
|
||||
|
||||
@@ -42,7 +45,7 @@ def test_post_upload_letter_redirects_for_valid_file(mocker, client_request):
|
||||
assert antivirus_mock.called
|
||||
|
||||
mock_s3.assert_called_once_with(
|
||||
'The sanitised content',
|
||||
b'The sanitised content',
|
||||
'service-{}/fake-uuid.pdf'.format(SERVICE_ONE_ID),
|
||||
'valid',
|
||||
)
|
||||
@@ -64,7 +67,10 @@ def test_post_upload_letter_shows_letter_preview_for_valid_file(mocker, client_r
|
||||
|
||||
mocker.patch('uuid.uuid4', return_value='fake-uuid')
|
||||
mocker.patch('app.main.views.uploads.antivirus_client.scan', return_value=True)
|
||||
mocker.patch('app.main.views.uploads.sanitise_letter', return_value=Mock(content='The sanitised content'))
|
||||
mocker.patch(
|
||||
'app.main.views.uploads.sanitise_letter',
|
||||
return_value=Mock(content='The sanitised content', json=lambda: {'file': 'VGhlIHNhbml0aXNlZCBjb250ZW50'})
|
||||
)
|
||||
mocker.patch('app.main.views.uploads.upload_letter_to_s3')
|
||||
mocker.patch('app.main.views.uploads.pdf_page_count', return_value=3)
|
||||
mocker.patch('app.main.views.uploads.service_api_client.get_precompiled_template', return_value=letter_template)
|
||||
|
||||
Reference in New Issue
Block a user