mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 10:03:21 -04:00
Test URLs separately
It’s hard to read the tests when they have HTML bundled up with content. So this commit: - introduces BeautifulSoup to parse the HTML - asserts separately on the text and any links found in the HTML
This commit is contained in:
@@ -4,6 +4,7 @@ from io import StringIO
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
|
||||||
from app import format_datetime_relative
|
from app import format_datetime_relative
|
||||||
@@ -418,40 +419,36 @@ def test_get_letter_validation_error_for_unknown_error():
|
|||||||
'letter-not-a4-portrait-oriented',
|
'letter-not-a4-portrait-oriented',
|
||||||
'Your letter is not A4 portrait size',
|
'Your letter is not A4 portrait size',
|
||||||
(
|
(
|
||||||
'You need to change the size or orientation of page 2. <br>Files must meet our '
|
'You need to change the size or orientation of page 2. '
|
||||||
'<a href="https://docs.notifications.service.gov.uk/documentation/images/notify-pdf-letter-spec-v2.4.pdf" '
|
'Files must meet our letter specification.'
|
||||||
'target="_blank">letter specification</a>.'
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
'Validation failed because page 2 is not A4 portrait size.<br>'
|
'Validation failed because page 2 is not A4 portrait size.'
|
||||||
'Files must meet our <a href="https://docs.notifications.service.gov.uk/'
|
'Files must meet our letter specification.'
|
||||||
'documentation/images/notify-pdf-letter-spec-v2.4.pdf" target="_blank">'
|
|
||||||
'letter specification</a>.'
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
'content-outside-printable-area',
|
'content-outside-printable-area',
|
||||||
'Your content is outside the printable area',
|
'Your content is outside the printable area',
|
||||||
(
|
(
|
||||||
'You need to edit page 2.<br>Files must meet our '
|
'You need to edit page 2.'
|
||||||
'<a href="https://docs.notifications.service.gov.uk/documentation/images/notify-pdf-letter-spec-v2.4.pdf" '
|
'Files must meet our letter specification.'
|
||||||
'target="_blank">letter specification</a>.'
|
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
'Validation failed because content is outside the printable area '
|
'Validation failed because content is outside the printable area '
|
||||||
'on page 2.<br>Files must meet our <a href="https://docs.notifications.service.gov.uk/'
|
'on page 2.'
|
||||||
'documentation/images/notify-pdf-letter-spec-v2.4.pdf" target="_blank">'
|
'Files must meet our letter specification.'
|
||||||
'letter specification</a>.'
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
'letter-too-long',
|
'letter-too-long',
|
||||||
'Your letter is too long',
|
'Your letter is too long',
|
||||||
(
|
(
|
||||||
'Letters must be 10 pages or less. <br>Your letter is 13 pages long.'
|
'Letters must be 10 pages or less. '
|
||||||
|
'Your letter is 13 pages long.'
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
'Validation failed because this letter is 13 pages long.<br>'
|
'Validation failed because this letter is 13 pages long.'
|
||||||
'Letters must be 10 pages or less.'
|
'Letters must be 10 pages or less.'
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -462,8 +459,22 @@ def test_get_letter_validation_error_for_known_errors(
|
|||||||
expected_content,
|
expected_content,
|
||||||
expected_summary,
|
expected_summary,
|
||||||
):
|
):
|
||||||
|
expected_letter_spec_url = (
|
||||||
|
'https://docs.notifications.service.gov.uk/'
|
||||||
|
'documentation/images/notify-pdf-letter-spec-v2.4.pdf'
|
||||||
|
)
|
||||||
error = get_letter_validation_error(error_message, invalid_pages=[2], page_count=13)
|
error = get_letter_validation_error(error_message, invalid_pages=[2], page_count=13)
|
||||||
|
detail = BeautifulSoup(error['detail'], 'html.parser')
|
||||||
|
summary = BeautifulSoup(error['summary'], 'html.parser')
|
||||||
|
|
||||||
assert error['title'] == expected_title
|
assert error['title'] == expected_title
|
||||||
assert expected_content in error['detail']
|
|
||||||
assert error['summary'] == expected_summary
|
assert detail.text == expected_content
|
||||||
|
if detail.select_one('a'):
|
||||||
|
assert detail.select_one('a')['href'] == expected_letter_spec_url
|
||||||
|
assert detail.select_one('a')['target'] == '_blank'
|
||||||
|
|
||||||
|
assert summary.text == expected_summary
|
||||||
|
if summary.select_one('a'):
|
||||||
|
assert summary.select_one('a')['href'] == expected_letter_spec_url
|
||||||
|
assert summary.select_one('a')['target'] == '_blank'
|
||||||
|
|||||||
Reference in New Issue
Block a user