mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 23:58:25 -04:00
Add check that PDF file can be opened and is not malformed
This checks that the PDF file is not malformed in some way (e.g. by missing the EOF marker). We check this by trying to get the page count of the letter which will be needed to display the preview of the letter.
This commit is contained in:
@@ -90,6 +90,20 @@ def test_post_choose_upload_file_when_file_is_too_big(mocker, client_request):
|
||||
assert normalize_spaces(page.select('.banner-dangerous')[0].text) == 'Your file must be smaller than 2MB'
|
||||
|
||||
|
||||
def test_post_choose_upload_file_when_file_is_malformed(mocker, client_request):
|
||||
mocker.patch('app.main.views.uploads.antivirus_client.scan', return_value=True)
|
||||
|
||||
with open('tests/test_pdf_files/no_eof_marker.pdf', 'rb') as file:
|
||||
page = client_request.post(
|
||||
'main.upload_letter',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'file': file},
|
||||
_expected_status=400
|
||||
)
|
||||
assert page.find('h1').text == 'Upload a letter'
|
||||
assert normalize_spaces(page.select('.banner-dangerous')[0].text) == 'Your file must be a valid PDF'
|
||||
|
||||
|
||||
def test_uploaded_letter_preview(client_request):
|
||||
page = client_request.get(
|
||||
'main.uploaded_letter_preview',
|
||||
|
||||
BIN
tests/test_pdf_files/no_eof_marker.pdf
Normal file
BIN
tests/test_pdf_files/no_eof_marker.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user