From a149c6a8532f5169ec4a76b8eaeabd8afc35a898 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 3 Jun 2021 09:39:31 +0100 Subject: [PATCH] Fix HTML showing on old job page Using the `Markup` class tells Jinja that the content is safe to render without any escaping. --- app/main/views/jobs.py | 24 ++++++++++++++++-------- tests/app/main/views/test_jobs.py | 9 +++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/main/views/jobs.py b/app/main/views/jobs.py index eb8930c93..d6009c8b8 100644 --- a/app/main/views/jobs.py +++ b/app/main/views/jobs.py @@ -350,26 +350,34 @@ def _get_job_counts(job): count ) for label, query_param, count in [ [ - f'''total - {"text message" if job_type == "sms" else job_type}s''', + Markup( + f'''total + {"text message" if job_type == "sms" else job_type}s''' + ), '', job.notification_count ], [ - f'''sending - {message_count_noun(job.notifications_sending, job_type)}''', + Markup( + f'''sending + {message_count_noun(job.notifications_sending, job_type)}''' + ), 'sending', job.notifications_sending ], [ - f'''delivered - {message_count_noun(job.notifications_delivered, job_type)}''', + Markup( + f'''delivered + {message_count_noun(job.notifications_delivered, job_type)}''' + ), 'delivered', job.notifications_delivered ], [ - f'''failed - {message_count_noun(job.notifications_failed, job_type)}''', + Markup( + f'''failed + {message_count_noun(job.notifications_failed, job_type)}''' + ), 'failed', job.notifications_failed ] diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 4f9a420b5..96c08b543 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -283,6 +283,15 @@ def test_should_show_old_job( assert not page.select('p.hint') assert not page.select('a[download]') assert page.select_one('tbody').text.strip() == expected_message + assert [ + normalize_spaces(column.text) + for column in page.select('main .govuk-grid-column-one-quarter') + ] == [ + '1 total text messages', + '1 sending text message', + '0 delivered text messages', + '0 failed text messages', + ] @freeze_time("2016-01-01 11:09:00.061258")