mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 16:01:15 -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:
@@ -52,7 +52,7 @@ def mock_s3_get_list_diff(bucket_name, subfolder='', suffix='', last_modified=No
|
||||
|
||||
@freeze_time('2016-10-18T10:00:00')
|
||||
def test_will_remove_csv_files_for_jobs_older_than_seven_days(
|
||||
notify_db, notify_db_session, mocker, sample_template
|
||||
notify_db_session, mocker, sample_template
|
||||
):
|
||||
"""
|
||||
Jobs older than seven days are deleted, but only two day's worth (two-day window)
|
||||
@@ -84,7 +84,7 @@ def test_will_remove_csv_files_for_jobs_older_than_seven_days(
|
||||
|
||||
@freeze_time('2016-10-18T10:00:00')
|
||||
def test_will_remove_csv_files_for_jobs_older_than_retention_period(
|
||||
notify_db, notify_db_session, mocker
|
||||
notify_db_session, mocker
|
||||
):
|
||||
"""
|
||||
Jobs older than retention period are deleted, but only two day's worth (two-day window)
|
||||
@@ -319,7 +319,7 @@ def test_get_letter_notifications_still_sending_when_they_shouldnt_finds_friday_
|
||||
|
||||
|
||||
@freeze_time('2018-01-11T23:00:00')
|
||||
def test_letter_raise_alert_if_no_ack_file_for_zip_does_not_raise_when_files_match_zip_list(mocker, notify_db):
|
||||
def test_letter_raise_alert_if_no_ack_file_for_zip_does_not_raise_when_files_match_zip_list(mocker, notify_db_session):
|
||||
mock_file_list = mocker.patch("app.aws.s3.get_list_of_files_by_suffix", side_effect=mock_s3_get_list_match)
|
||||
letter_raise_alert_if_no_ack_file_for_zip()
|
||||
|
||||
@@ -334,7 +334,7 @@ def test_letter_raise_alert_if_no_ack_file_for_zip_does_not_raise_when_files_mat
|
||||
|
||||
|
||||
@freeze_time('2018-01-11T23:00:00')
|
||||
def test_letter_raise_alert_if_ack_files_not_match_zip_list(mocker, notify_db):
|
||||
def test_letter_raise_alert_if_ack_files_not_match_zip_list(mocker, notify_db_session):
|
||||
mock_file_list = mocker.patch("app.aws.s3.get_list_of_files_by_suffix", side_effect=mock_s3_get_list_diff)
|
||||
mock_create_ticket = mocker.spy(NotifySupportTicket, '__init__')
|
||||
mock_send_ticket_to_zendesk = mocker.patch(
|
||||
@@ -360,7 +360,7 @@ def test_letter_raise_alert_if_ack_files_not_match_zip_list(mocker, notify_db):
|
||||
|
||||
|
||||
@freeze_time('2018-01-11T23:00:00')
|
||||
def test_letter_not_raise_alert_if_no_files_do_not_cause_error(mocker, notify_db):
|
||||
def test_letter_not_raise_alert_if_no_files_do_not_cause_error(mocker, notify_db_session):
|
||||
mock_file_list = mocker.patch("app.aws.s3.get_list_of_files_by_suffix", side_effect=None)
|
||||
letter_raise_alert_if_no_ack_file_for_zip()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user