diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index fd0b991f31..2d3727d40f 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -516,3 +516,16 @@ def test_get_letter_validation_error_for_known_errors( @freeze_time('2020-02-14T12:00:00') def test_is_less_than_90_days_ago(date_from_db, expected_result): assert is_less_than_90_days_ago(date_from_db) == expected_result + + +@pytest.mark.parametrize('method', ('get', 'post')) +@freeze_time('2010-12-31 23:59:59') +def test_freeze_time_before_2010_warning(client_request, method): + with pytest.raises(ValueError) as exception: + getattr(client_request, method)('main.index') + assert str( + exception.value + ) == ( + 'You can’t freeze time to before 2011 because it breaks the ' + 'session serializer' + ) diff --git a/tests/conftest.py b/tests/conftest.py index c2aa8d3add..6047e3b5fd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2687,6 +2687,14 @@ def session_transaction(): with logged_in_client.session_transaction() as session: yield session + @staticmethod + def check_current_time(): + if datetime.utcnow().strftime('%Y') < '2011': + raise ValueError( + 'You can’t freeze time to before 2011 because it ' + 'breaks the session serializer' + ) + @staticmethod def login(user, service=service_one): logged_in_client.login(user, mocker, service) @@ -2722,6 +2730,7 @@ def get_url( _test_page_title=True, **endpoint_kwargs ): + ClientRequest.check_current_time() resp = logged_in_client.get( url, follow_redirects=_follow_redirects, @@ -2750,6 +2759,7 @@ def post( _expected_redirect=None, **endpoint_kwargs ): + ClientRequest.check_current_time() if _expected_status is None: _expected_status = 200 if _follow_redirects else 302 resp = logged_in_client.post(