Fix failing test with new Python version

This test is now failing due to the combination of both Werkzeug having
had a major version bump in a previous PR and the Python version
changing. Calling `current_service` is now giving an error when trying
to get the `service` from the `_request_ctx_stack` because
`_request_ctx_stack` has no `service` attribute. There was no error
before, so it appears some underlying behaviour has changed. I've fixed
the test by changing the setup, but there is no effect on production
code - when the app is running `load_service_before_request` is called
before every request.
This commit is contained in:
Katie Smith
2021-11-03 09:33:16 +00:00
parent fdfdb9e498
commit 6b24b3072c

View File

@@ -5,6 +5,7 @@ from unittest.mock import Mock
import pytest
from notifications_utils.template import LetterPreviewTemplate
from app import load_service_before_request
from app.template_previews import (
TemplatePreview,
get_page_count_for_letter,
@@ -58,6 +59,10 @@ def test_from_database_object_makes_request(
expected_filename,
mock_get_service_letter_template
):
# This test is calling `current_service` outside a Flask endpoint, so we need to make sure
# `service` is in the `_request_ctx_stack` to avoid an error
load_service_before_request()
resp = Mock(content='a', status_code='b', headers={'c': 'd'})
request_mock = mocker.patch('app.template_previews.requests.post', return_value=resp)
mocker.patch('app.template_previews.current_service', letter_branding=letter_branding)