Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard against obscure bug in test setup #3308

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/app/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down