mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 18:22:37 -04:00
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:
@@ -5,6 +5,7 @@ from unittest.mock import Mock
|
|||||||
import pytest
|
import pytest
|
||||||
from notifications_utils.template import LetterPreviewTemplate
|
from notifications_utils.template import LetterPreviewTemplate
|
||||||
|
|
||||||
|
from app import load_service_before_request
|
||||||
from app.template_previews import (
|
from app.template_previews import (
|
||||||
TemplatePreview,
|
TemplatePreview,
|
||||||
get_page_count_for_letter,
|
get_page_count_for_letter,
|
||||||
@@ -58,6 +59,10 @@ def test_from_database_object_makes_request(
|
|||||||
expected_filename,
|
expected_filename,
|
||||||
mock_get_service_letter_template
|
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'})
|
resp = Mock(content='a', status_code='b', headers={'c': 'd'})
|
||||||
request_mock = mocker.patch('app.template_previews.requests.post', return_value=resp)
|
request_mock = mocker.patch('app.template_previews.requests.post', return_value=resp)
|
||||||
mocker.patch('app.template_previews.current_service', letter_branding=letter_branding)
|
mocker.patch('app.template_previews.current_service', letter_branding=letter_branding)
|
||||||
|
|||||||
Reference in New Issue
Block a user