Update letter utils to handle precompiled letters sent by test API keys

- precompiled letters sent using a test key should be put into a test-letters bucket
- also refactored code from test_letter_pdf_tasks
This commit is contained in:
Ken Tsang
2018-03-14 18:15:00 +00:00
parent 2ba5202e08
commit c4e1d56492
3 changed files with 53 additions and 31 deletions

View File

@@ -1,6 +1,8 @@
import pytest
from app.letters.utils import get_bucket_prefix_for_notification
from freezegun import freeze_time
from app.letters.utils import get_bucket_prefix_for_notification, get_letter_pdf_filename
def test_get_bucket_prefix_for_notification_valid_notification(sample_notification):
@@ -16,3 +18,30 @@ def test_get_bucket_prefix_for_notification_valid_notification(sample_notificati
def test_get_bucket_prefix_for_notification_invalid_notification():
with pytest.raises(AttributeError):
get_bucket_prefix_for_notification(None)
@pytest.mark.parametrize('crown_flag,expected_crown_text', [
(True, 'C'),
(False, 'N'),
])
@freeze_time("2017-12-04 17:29:00")
def test_get_letter_pdf_filename_returns_correct_filename(
notify_api, mocker, crown_flag, expected_crown_text):
filename = get_letter_pdf_filename(reference='foo', crown=crown_flag)
assert filename == '2017-12-04/NOTIFY.FOO.D.2.C.{}.20171204172900.PDF'.format(expected_crown_text)
@freeze_time("2017-12-04 17:29:00")
def test_get_letter_pdf_filename_returns_correct_filename_for_test_letters(
notify_api, mocker):
filename = get_letter_pdf_filename(reference='foo', crown='C', is_test_letter=True)
assert filename == 'NOTIFY.FOO.D.2.C.C.20171204172900.PDF'
@freeze_time("2017-12-04 17:31:00")
def test_get_letter_pdf_filename_returns_tomorrows_filename(notify_api, mocker):
filename = get_letter_pdf_filename(reference='foo', crown=True)
assert filename == '2017-12-05/NOTIFY.FOO.D.2.C.C.20171204173100.PDF'