mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
Add letter upload form which redirects to blank preview page
Added a form to upload a single letter. Currently this only uses the form to validate that a file is submitted and that the file is a PDF. If either of these validations fail, the form will display an error. Otherwise, we redirect to a new preview page which just has the filename as the heading for now.
This commit is contained in:
@@ -805,7 +805,7 @@ def test_letter_validation_preview_doesnt_call_template_preview_when_file_not_pd
|
||||
antivirus_scan.assert_not_called()
|
||||
validate_letter.assert_not_called()
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.find('span', class_='error-message').text.strip() == "PDF documents only!"
|
||||
assert page.find('span', class_='error-message').text.strip() == "Letters must be saved as a PDF"
|
||||
|
||||
|
||||
def test_letter_validation_preview_doesnt_call_template_preview_when_file_doesnt_pass_virus_scan(
|
||||
|
||||
@@ -1,5 +1,70 @@
|
||||
from flask import url_for
|
||||
|
||||
from tests.conftest import SERVICE_ONE_ID
|
||||
|
||||
|
||||
def test_get_upload_hub_page(client_request):
|
||||
client_request.get('main.uploads', service_id=SERVICE_ONE_ID)
|
||||
page = client_request.get('main.uploads', service_id=SERVICE_ONE_ID)
|
||||
|
||||
assert page.find('h1').text == 'Uploads'
|
||||
assert page.find('a', text='Upload a letter').attrs['href'] == url_for(
|
||||
'main.upload_letter', service_id=SERVICE_ONE_ID
|
||||
)
|
||||
|
||||
|
||||
def test_get_upload_letter(client_request):
|
||||
page = client_request.get('main.upload_letter', service_id=SERVICE_ONE_ID)
|
||||
|
||||
assert page.find('h1').text == 'Upload a letter'
|
||||
assert page.find('input', class_='file-upload-field')
|
||||
assert page.select('button[type=submit]')
|
||||
|
||||
|
||||
def test_post_upload_letter_redirects_for_valid_file(mocker, client_request):
|
||||
mocker.patch('uuid.uuid4', return_value='fake-uuid')
|
||||
|
||||
with open('tests/test_pdf_files/one_page_pdf.pdf', 'rb') as file:
|
||||
client_request.post(
|
||||
'main.upload_letter',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'file': file},
|
||||
_expected_redirect=url_for(
|
||||
'main.uploaded_letter_preview',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
file_id='fake-uuid',
|
||||
original_filename='tests/test_pdf_files/one_page_pdf.pdf',
|
||||
_external=True
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_post_upload_letter_shows_error_when_file_is_not_a_pdf(client_request):
|
||||
with open('tests/non_spreadsheet_files/actually_a_png.csv', 'rb') as file:
|
||||
page = client_request.post(
|
||||
'main.upload_letter',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'file': file},
|
||||
_expected_status=200
|
||||
)
|
||||
assert page.find('span', class_='error-message').text.strip() == "Letters must be saved as a PDF"
|
||||
|
||||
|
||||
def test_post_upload_letter_shows_error_when_no_file_uploaded(client_request):
|
||||
page = client_request.post(
|
||||
'main.upload_letter',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
_data={'file': ''},
|
||||
_expected_status=200
|
||||
)
|
||||
assert page.find('span', class_='error-message').text.strip() == "You need to upload a file to submit"
|
||||
|
||||
|
||||
def test_uploaded_letter_preview(client_request):
|
||||
page = client_request.get(
|
||||
'main.uploaded_letter_preview',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
file_id='fake-uuid',
|
||||
original_filename='my_letter.pdf',
|
||||
)
|
||||
|
||||
assert page.find('h1').text == 'my_letter.pdf'
|
||||
|
||||
Reference in New Issue
Block a user