mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Updates:
* Skip the decorated tests as that doesn't work as we expect * Remove magic numbers in tests
This commit is contained in:
@@ -44,9 +44,10 @@ from tests.app.conftest import (
|
||||
sample_job as create_sample_job,
|
||||
sample_notification_history as create_notification_history,
|
||||
create_custom_template,
|
||||
set_config_values
|
||||
datetime_in_past
|
||||
)
|
||||
from tests.app.aws.test_s3 import single_s3_object_stub, datetime_in_past
|
||||
from tests.app.aws.test_s3 import single_s3_object_stub
|
||||
from tests.conftest import set_config_values
|
||||
|
||||
|
||||
def _create_slow_delivery_notification(provider='mmg'):
|
||||
@@ -74,14 +75,13 @@ def _create_slow_delivery_notification(provider='mmg'):
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def prepare_current_provider(restore_provider_details):
|
||||
initial_provider = get_current_provider('sms')
|
||||
initial_provider.updated_at = datetime.utcnow() - timedelta(minutes=30)
|
||||
dao_update_provider_details(initial_provider)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="This doesn't actually test the celery task wraps the function")
|
||||
def test_should_have_decorated_tasks_functions():
|
||||
"""
|
||||
TODO: This test needs to be reviewed as this doesn't actually
|
||||
test that the celery task is wrapping the function. We're also
|
||||
running similar tests elsewhere which also need review.
|
||||
"""
|
||||
assert delete_verify_codes.__wrapped__.__name__ == 'delete_verify_codes'
|
||||
assert delete_notifications_created_more_than_a_week_ago_by_type.__wrapped__.__name__ == \
|
||||
'delete_notifications_created_more_than_a_week_ago_by_type'
|
||||
@@ -100,6 +100,13 @@ def test_should_have_decorated_tasks_functions():
|
||||
'delete_dvla_response_files_older_than_seven_days'
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def prepare_current_provider(restore_provider_details):
|
||||
initial_provider = get_current_provider('sms')
|
||||
initial_provider.updated_at = datetime.utcnow() - timedelta(minutes=30)
|
||||
dao_update_provider_details(initial_provider)
|
||||
|
||||
|
||||
def test_should_call_delete_sms_notifications_more_than_week_in_task(notify_api, mocker):
|
||||
mocked = mocker.patch('app.celery.scheduled_tasks.delete_notifications_created_more_than_a_week_ago_by_type')
|
||||
delete_sms_notifications_older_than_seven_days()
|
||||
@@ -555,11 +562,13 @@ def test_remove_dvla_transformed_files_does_not_remove_files(mocker, sample_serv
|
||||
s3.remove_transformed_dvla_file.assert_has_calls([])
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:00:00")
|
||||
def test_delete_dvla_response_files_older_than_seven_days_removes_old_files(notify_api, mocker):
|
||||
AFTER_SEVEN_DAYS = datetime_in_past(days=8)
|
||||
single_page_s3_objects = [{
|
||||
"Contents": [
|
||||
single_s3_object_stub('bar/foo1.txt', datetime_in_past(days=8)),
|
||||
single_s3_object_stub('bar/foo2.txt', datetime_in_past(days=8)),
|
||||
single_s3_object_stub('bar/foo1.txt', AFTER_SEVEN_DAYS),
|
||||
single_s3_object_stub('bar/foo2.txt', AFTER_SEVEN_DAYS),
|
||||
]
|
||||
}]
|
||||
mocker.patch(
|
||||
@@ -575,18 +584,25 @@ def test_delete_dvla_response_files_older_than_seven_days_removes_old_files(noti
|
||||
])
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:00:00")
|
||||
def test_delete_dvla_response_files_older_than_seven_days_does_not_remove_files(notify_api, mocker):
|
||||
START_DATE = datetime_in_past(days=9)
|
||||
JUST_BEFORE_START_DATE = datetime_in_past(days=9, seconds=1)
|
||||
END_DATE = datetime_in_past(days=7)
|
||||
JUST_AFTER_END_DATE = END_DATE + timedelta(seconds=1)
|
||||
|
||||
single_page_s3_objects = [{
|
||||
"Contents": [
|
||||
single_s3_object_stub('bar/foo1.txt', datetime_in_past(days=6)),
|
||||
single_s3_object_stub('bar/foo2.txt', datetime_in_past(days=9)),
|
||||
single_s3_object_stub('bar/foo1.txt', JUST_BEFORE_START_DATE),
|
||||
single_s3_object_stub('bar/foo2.txt', START_DATE),
|
||||
single_s3_object_stub('bar/foo3.txt', END_DATE),
|
||||
single_s3_object_stub('bar/foo4.txt', JUST_AFTER_END_DATE),
|
||||
]
|
||||
}]
|
||||
mocker.patch(
|
||||
'app.celery.scheduled_tasks.s3.get_s3_bucket_objects', return_value=single_page_s3_objects[0]["Contents"]
|
||||
)
|
||||
remove_s3_mock = mocker.patch('app.celery.scheduled_tasks.s3.remove_s3_object')
|
||||
|
||||
delete_dvla_response_files_older_than_seven_days()
|
||||
|
||||
remove_s3_mock.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user