Do not allow to send uploaded pdf letters longer than 10 pages

This commit is contained in:
Pea Tyczynska
2019-09-27 17:54:44 +01:00
parent 579ae72abb
commit 0adf80f294
2 changed files with 35 additions and 0 deletions

View File

@@ -79,6 +79,8 @@ def upload_letter(service_id):
raise ex
else:
status = 'valid'
if page_count > 10:
status = 'invalid'
file_contents = base64.b64decode(response.json()['file'].encode())
upload_letter_to_s3(
file_contents,

View File

@@ -204,6 +204,39 @@ def test_post_upload_letter_with_invalid_file(mocker, client_request):
assert not page.find('button', {'type': 'submit'})
def test_post_upload_letter_with_letter_that_is_too_long(mocker, client_request):
letter_template = {'template_type': 'letter',
'reply_to_text': '',
'postage': 'second',
'subject': 'hi',
'content': 'my letter'}
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', json=lambda: {'file': 'VGhlIHNhbml0aXNlZCBjb250ZW50'})
)
mocker.patch('app.main.views.uploads.upload_letter_to_s3')
mock_page_count = mocker.patch('app.main.views.uploads.pdf_page_count', return_value=11)
mocker.patch('app.main.views.uploads.service_api_client.get_precompiled_template', return_value=letter_template)
with open('tests/test_pdf_files/one_page_pdf.pdf', 'rb') as file:
page = client_request.post(
'main.upload_letter',
service_id=SERVICE_ONE_ID,
_data={'file': file},
_follow_redirects=True,
)
assert mock_page_count.called
assert page.find('h1').text == 'tests/test_pdf_files/one_page_pdf.pdf'
assert page.find("div", {"class": "banner-dangerous bottom-gutter"})
assert "This letter is too long" in page.text
assert not page.find('button', {'type': 'submit'})
def test_post_upload_letter_shows_letter_preview_for_invalid_file(mocker, client_request):
letter_template = {'template_type': 'letter',
'reply_to_text': '',