mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
Show all pages of a letter everywhere
Right now showing all the pages in full is the only way we have of showing a letter that makes sense to our users. Maybe in the future we show some kind of truncated version, but the end of the first page is not a good place to truncate the letter. This commit just extracts the code for showing multiple pages from the template view, refactors it for reuse, and includes it in the send views.
This commit is contained in:
@@ -4,7 +4,7 @@ from functools import partial
|
||||
from unittest.mock import Mock
|
||||
from notifications_utils.template import LetterPreviewTemplate
|
||||
|
||||
from app.template_previews import TemplatePreview
|
||||
from app.template_previews import TemplatePreview, get_page_count_for_letter
|
||||
|
||||
|
||||
@pytest.mark.parametrize('partial_call, expected_page_argument', [
|
||||
@@ -65,3 +65,32 @@ def test_from_database_object_makes_request(
|
||||
headers = {'Authorization': 'Token my-secret-key'}
|
||||
|
||||
request_mock.assert_called_once_with(expected_url, json=data, headers=headers)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('template_type', [
|
||||
'email', 'sms'
|
||||
])
|
||||
def test_page_count_returns_none_for_non_letter_templates(template_type):
|
||||
assert get_page_count_for_letter({'template_type': template_type}) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('partial_call, expected_template_preview_args', [
|
||||
(
|
||||
partial(get_page_count_for_letter),
|
||||
({'template_type': 'letter'}, None)
|
||||
),
|
||||
(
|
||||
partial(get_page_count_for_letter, values={'foo': 'bar'}),
|
||||
({'template_type': 'letter'}, {'foo': 'bar'})
|
||||
),
|
||||
])
|
||||
def test_page_count_unpacks_from_json_response(
|
||||
mocker,
|
||||
partial_call,
|
||||
expected_template_preview_args,
|
||||
):
|
||||
mock_template_preview = mocker.patch('app.template_previews.TemplatePreview.from_database_object')
|
||||
mock_template_preview.return_value = (b'{"count": 99}', 200, {})
|
||||
|
||||
assert partial_call({'template_type': 'letter'}) == 99
|
||||
mock_template_preview.assert_called_once_with(*expected_template_preview_args, filetype='json')
|
||||
|
||||
Reference in New Issue
Block a user