mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Make function-level setup fixture clear cache
This means that anyone adding a new test to this file doesn’t have to remember to clear the cache in their test, or forget to and have a hard-to-debug test failure. Using `setup_function` means we don’t have to convert this module into using class-based tests.
This commit is contained in:
@@ -34,6 +34,12 @@ from tests.app.db import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_function(_function):
|
||||||
|
# pytest will run this function before each test. It makes sure the
|
||||||
|
# state of the cache is not shared between tests.
|
||||||
|
send_to_providers.provider_cache.clear()
|
||||||
|
|
||||||
|
|
||||||
def test_provider_to_use_should_return_random_provider(mocker, notify_db_session):
|
def test_provider_to_use_should_return_random_provider(mocker, notify_db_session):
|
||||||
mmg = get_provider_details_by_identifier('mmg')
|
mmg = get_provider_details_by_identifier('mmg')
|
||||||
firetext = get_provider_details_by_identifier('firetext')
|
firetext = get_provider_details_by_identifier('firetext')
|
||||||
@@ -53,8 +59,6 @@ def test_provider_to_use_should_cache_repeated_calls(mocker, notify_db_session):
|
|||||||
wraps=send_to_providers.random.choices,
|
wraps=send_to_providers.random.choices,
|
||||||
)
|
)
|
||||||
|
|
||||||
send_to_providers.provider_cache.clear()
|
|
||||||
|
|
||||||
results = [
|
results = [
|
||||||
send_to_providers.provider_to_use('sms', international=False)
|
send_to_providers.provider_to_use('sms', international=False)
|
||||||
for _ in range(10)
|
for _ in range(10)
|
||||||
@@ -90,8 +94,6 @@ def test_provider_to_use_raises_if_no_active_providers(mocker, restore_provider_
|
|||||||
mmg = get_provider_details_by_identifier('mmg')
|
mmg = get_provider_details_by_identifier('mmg')
|
||||||
mmg.active = False
|
mmg.active = False
|
||||||
|
|
||||||
send_to_providers.provider_cache.clear()
|
|
||||||
|
|
||||||
with pytest.raises(Exception):
|
with pytest.raises(Exception):
|
||||||
send_to_providers.provider_to_use('sms', international=True)
|
send_to_providers.provider_to_use('sms', international=True)
|
||||||
|
|
||||||
@@ -643,7 +645,6 @@ def test_should_send_sms_to_international_providers(
|
|||||||
international=True,
|
international=True,
|
||||||
reply_to_text=sample_template.service.get_default_sms_sender()
|
reply_to_text=sample_template.service.get_default_sms_sender()
|
||||||
)
|
)
|
||||||
send_to_providers.provider_cache.clear()
|
|
||||||
send_to_providers.send_sms_to_provider(
|
send_to_providers.send_sms_to_provider(
|
||||||
notification_uk
|
notification_uk
|
||||||
)
|
)
|
||||||
@@ -694,7 +695,6 @@ def test_should_handle_sms_sender_and_prefix_message(
|
|||||||
template = create_template(service, content='bar')
|
template = create_template(service, content='bar')
|
||||||
notification = create_notification(template, reply_to_text=sms_sender)
|
notification = create_notification(template, reply_to_text=sms_sender)
|
||||||
|
|
||||||
send_to_providers.provider_cache.clear()
|
|
||||||
send_to_providers.send_sms_to_provider(notification)
|
send_to_providers.send_sms_to_provider(notification)
|
||||||
|
|
||||||
mmg_client.send_sms.assert_called_once_with(
|
mmg_client.send_sms.assert_called_once_with(
|
||||||
|
|||||||
Reference in New Issue
Block a user