Sanitise uploaded letters and store in S3

This sanitises uploaded letters and stores the sanitised result in S3
with if it passes validation or the original PDF in S3 if validation
fails. A metadata value of 'status' is set to either 'valid' or
'invalid'.
This commit is contained in:
Katie Smith
2019-09-06 17:10:48 +01:00
parent 5fa9e071c7
commit 8a322b844b
8 changed files with 161 additions and 11 deletions

View File

@@ -4,7 +4,11 @@ from unittest.mock import Mock
import pytest
from notifications_utils.template import LetterPreviewTemplate
from app.template_previews import TemplatePreview, get_page_count_for_letter
from app.template_previews import (
TemplatePreview,
get_page_count_for_letter,
sanitise_letter,
)
@pytest.mark.parametrize('partial_call, expected_page_argument', [
@@ -119,3 +123,15 @@ def test_from_example_template_makes_request(mocker):
'filename': filename,
'letter_contact_block': None}
)
def test_sanitise_letter_calls_template_preview_sanitise_endoint_with_file(mocker):
request_mock = mocker.patch('app.template_previews.requests.post')
sanitise_letter('pdf_data')
request_mock.assert_called_once_with(
'http://localhost:9999/precompiled/sanitise',
headers={'Authorization': 'Token my-secret-key'},
data='pdf_data'
)