mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 00:20:43 -04:00
Remove the letter validation preview endpoints
We can use the ‘Uploads’ feature to check if letters are printable now. This code works in a completely different way, so if we kept it we’d have to maintain two different code paths, and make sure that they didn’t diverge. Also deletes the related HTML templates.
This commit is contained in:
@@ -709,132 +709,6 @@ def test_platform_admin_submit_empty_returned_letters(mocker, platform_admin_cli
|
||||
assert "Cannot be empty" in response.get_data(as_text=True)
|
||||
|
||||
|
||||
def test_service_letter_validation_preview_renders_correctly(
|
||||
client_request,
|
||||
mock_has_no_jobs
|
||||
|
||||
):
|
||||
page = client_request.get('main.service_letter_validation_preview', service_id=SERVICE_ONE_ID)
|
||||
|
||||
assert page.find('h1').text.strip() == "Letter validation preview"
|
||||
assert page.find_all('input', class_='file-upload-field')
|
||||
|
||||
|
||||
def test_service_letter_validation_preview_returns_400_if_file_is_too_big(
|
||||
client_request,
|
||||
mock_has_no_jobs,
|
||||
mocker
|
||||
|
||||
):
|
||||
with open('tests/test_pdf_files/big.pdf', 'rb') as file:
|
||||
page = client_request.post('main.service_letter_validation_preview', service_id=SERVICE_ONE_ID,
|
||||
_data=dict(
|
||||
pdf_file=file,
|
||||
),
|
||||
content_type='multipart/form-data',
|
||||
_follow_redirects=True)
|
||||
|
||||
assert page.find('h1').text.strip() == "Letter validation preview"
|
||||
assert page.find_all('input', class_='file-upload-field')
|
||||
page.find('span', class_='error-message').text.strip() == "File must be less than 2MB"
|
||||
|
||||
|
||||
def test_letter_validation_preview_renders_correctly(mocker, platform_admin_client):
|
||||
response = platform_admin_client.get(url_for('main.platform_admin_letter_validation_preview'))
|
||||
assert response.status_code == 200
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.find('h1').text.strip() == "Letter Validation Preview"
|
||||
assert page.find_all('input', class_='file-upload-field')
|
||||
|
||||
|
||||
@pytest.mark.parametrize("passed_validation,message,expected_class", [
|
||||
(True, 'Your PDF passed the layout check', 'banner-with-tick'),
|
||||
(False, 'content-outside-printable-area', "banner-dangerous")
|
||||
])
|
||||
def test_letter_validation_preview_calls_template_preview_when_data_correct_and_displays_correct_message(
|
||||
mocker, platform_admin_client, passed_validation, message, expected_class
|
||||
):
|
||||
endpoint = '{}/precompiled/validate?include_preview=true'.format(current_app.config['TEMPLATE_PREVIEW_API_HOST'])
|
||||
mocker.patch('app.main.views.platform_admin.antivirus_client.scan', return_value=True)
|
||||
|
||||
with requests_mock.mock() as rmock:
|
||||
rmock.request(
|
||||
"POST",
|
||||
endpoint,
|
||||
json={"pages": [], "message": message, "result": passed_validation},
|
||||
status_code=200
|
||||
)
|
||||
with open('tests/test_pdf_files/multi_page_pdf.pdf', 'rb') as file:
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.platform_admin_letter_validation_preview'),
|
||||
data={"file": file},
|
||||
content_type='multipart/form-data'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert rmock.called
|
||||
assert rmock.request_history[0].url == endpoint
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
if passed_validation:
|
||||
assert page.find('div', class_=expected_class).text.strip() == message
|
||||
else:
|
||||
assert page.find('div', class_=expected_class).find('h1', {"data-error-type": message})
|
||||
|
||||
|
||||
def test_letter_validation_preview_doesnt_call_template_preview_when_no_file(mocker, platform_admin_client):
|
||||
antivirus_scan = mocker.patch('app.main.views.platform_admin.antivirus_client.scan')
|
||||
validate_letter = mocker.patch('app.main.views.platform_admin.validate_letter')
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.platform_admin_letter_validation_preview'),
|
||||
data={"file": ""},
|
||||
content_type='multipart/form-data'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
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() == "You need to choose a file to upload"
|
||||
|
||||
|
||||
def test_letter_validation_preview_doesnt_call_template_preview_when_file_not_pdf(mocker, platform_admin_client):
|
||||
antivirus_scan = mocker.patch('app.main.views.platform_admin.antivirus_client.scan')
|
||||
validate_letter = mocker.patch('app.main.views.platform_admin.validate_letter')
|
||||
with open('tests/non_spreadsheet_files/actually_a_png.csv', 'rb') as file:
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.platform_admin_letter_validation_preview'),
|
||||
data={"file": file},
|
||||
content_type='multipart/form-data'
|
||||
)
|
||||
assert response.status_code == 200
|
||||
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() == "Save your letter as a PDF and try again."
|
||||
|
||||
|
||||
def test_letter_validation_preview_doesnt_call_template_preview_when_file_doesnt_pass_virus_scan(
|
||||
mocker,
|
||||
platform_admin_client
|
||||
):
|
||||
antivirus_scan = mocker.patch('app.main.views.platform_admin.antivirus_client.scan', return_value=False)
|
||||
validate_letter = mocker.patch('app.main.views.platform_admin.validate_letter')
|
||||
|
||||
with open('tests/test_pdf_files/multi_page_pdf.pdf', 'rb') as file:
|
||||
response = platform_admin_client.post(
|
||||
url_for('main.platform_admin_letter_validation_preview'),
|
||||
data={"file": file},
|
||||
content_type='multipart/form-data'
|
||||
)
|
||||
assert response.status_code == 400
|
||||
assert antivirus_scan.called is True
|
||||
validate_letter.assert_not_called()
|
||||
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.find('div', class_='banner-dangerous').text.strip() == "Document did not pass the virus scan"
|
||||
|
||||
|
||||
def test_clear_cache_shows_form(client_request, platform_admin_user, mocker):
|
||||
redis = mocker.patch('app.main.views.platform_admin.redis_client')
|
||||
client_request.login(platform_admin_user)
|
||||
|
||||
Reference in New Issue
Block a user