Upload pre-compiled letter PDF to S3

Pre-compiled letter endpoint uploads PDF contents to S3 directly
instead of creating a letter task to generate PDF using template
preview.

This moves some of the utility functions used by existing letter
celery tasks to app.letters.utils, so that they can be reused by
the API endpoint.
This commit is contained in:
Alexey Bezhan
2018-02-23 10:39:32 +00:00
parent 5327298371
commit 8971a5adce
5 changed files with 80 additions and 59 deletions

View File

@@ -697,11 +697,11 @@ def test_post_email_notification_with_invalid_reply_to_id_returns_400(client, sa
assert 'BadRequestError' in resp_json['errors'][0]['error']
def test_post_precompiled_letter_notification_returns_201(client, sample_service, mocker):
mocker.patch('app.celery.letters_pdf_tasks.create_letters_pdf.apply_async')
def test_post_precompiled_letter_notification_returns_201(client, sample_service, notify_user, mocker):
s3mock = mocker.patch('app.v2.notifications.post_notifications.upload_letter_pdf')
data = {
"reference": "letter-reference",
"content": "abcdefgh"
"content": "bGV0dGVyLWNvbnRlbnQ="
}
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.post(
@@ -711,6 +711,8 @@ def test_post_precompiled_letter_notification_returns_201(client, sample_service
assert response.status_code == 201, response.get_data(as_text=True)
s3mock.assert_called_once_with(ANY, b'letter-content')
resp_json = json.loads(response.get_data(as_text=True))
assert resp_json == {
'content': {'body': None, 'subject': 'Pre-compiled PDF'},