mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
remove usage of notify_db fixture in unit tests
* notify_db fixture creates the database connection and ensures the test db exists and has migrations applied etc. It will run once per session (test run). * notify_db_session fixture runs after your test finishes and deletes all non static (eg type table) data. In unit tests that hit the database (ie: most of them), 99% of the time we will need to use notify_db_session to ensure everything is reset. The only time we don't need to use it is when we're querying things such as "ensure get X works when database is empty". This is such a low percentage of tests that it's easier for us to just use notify_db_session every time, and ensure that all our tests run much more consistently, at the cost of a small bit of performance when running tests. We used to use notify_db to access the session object for manually adding, committing, etc. To dissuade usage of that fixture I've moved that to the `notify_db_session`. I've then removed all uses of notify_db that I could find in the codebase. As a note, if you're writing a test that uses a `sample_x` fixture, all of those fixtures rely on notify_db_session so you'll get the teardown functionality for free. If you're just calling eg `create_x` db.py functions, then you'll need to make you add notify_db_session fixture to your test, even if you aren't manually accessing the session.
This commit is contained in:
@@ -77,7 +77,6 @@ def test_send_broadcast_event_calls_publish_govuk_alerts_task(
|
||||
|
||||
def test_send_broadcast_event_only_sends_to_one_provider_if_set_on_service(
|
||||
mocker,
|
||||
notify_db,
|
||||
notify_api,
|
||||
sample_broadcast_service
|
||||
):
|
||||
@@ -101,7 +100,6 @@ def test_send_broadcast_event_only_sends_to_one_provider_if_set_on_service(
|
||||
|
||||
def test_send_broadcast_event_does_nothing_if_provider_set_on_service_isnt_enabled_globally(
|
||||
mocker,
|
||||
notify_db,
|
||||
notify_api,
|
||||
sample_broadcast_service
|
||||
):
|
||||
@@ -186,7 +184,7 @@ def test_send_broadcast_provider_message_sends_data_correctly(
|
||||
])
|
||||
@pytest.mark.parametrize('channel', ['operator', 'test', 'severe', 'government'])
|
||||
def test_send_broadcast_provider_message_uses_channel_set_on_broadcast_service(
|
||||
notify_db, mocker, sample_broadcast_service, provider, provider_capitalised, channel
|
||||
mocker, sample_broadcast_service, provider, provider_capitalised, channel
|
||||
):
|
||||
sample_broadcast_service.broadcast_channel = channel
|
||||
template = create_template(sample_broadcast_service, BROADCAST_TYPE)
|
||||
|
||||
Reference in New Issue
Block a user