Skip to content

Commit

Permalink
Merge pull request #2289 from uktrade/fix-new-year-test-failure
Browse files Browse the repository at this point in the history
Use dynamic future year to stop tests failing
  • Loading branch information
kevincarrogan authored Jan 3, 2025
2 parents 633df0c + 6558230 commit 7451e92
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions unit_tests/exporter/goods/forms/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -590,25 +592,28 @@ def test_registered_firearms_dealer_form(data, valid, error_field, error_message
assert form.errors[error_field][0] == error_message


FUTURE_YEAR = datetime.date.today().year + 1


@pytest.mark.parametrize(
"data, files, valid, error_field, error_message",
(
(
{"reference_code": "ref_code", "expiry_date_0": 1, "expiry_date_1": 1, "expiry_date_2": 2025},
{"reference_code": "ref_code", "expiry_date_0": 1, "expiry_date_1": 1, "expiry_date_2": FUTURE_YEAR},
{"file": SimpleUploadedFile("test", b"test_content")},
True,
None,
None,
),
(
{"reference_code": "ref_code", "expiry_date_0": 1, "expiry_date_1": 1, "expiry_date_2": 2025},
{"reference_code": "ref_code", "expiry_date_0": 1, "expiry_date_1": 1, "expiry_date_2": FUTURE_YEAR},
{"file": ""},
False,
"file",
"Select certificate file to upload",
),
(
{"reference_code": "", "expiry_date_0": 1, "expiry_date_1": 1, "expiry_date_2": 2025},
{"reference_code": "", "expiry_date_0": 1, "expiry_date_1": 1, "expiry_date_2": FUTURE_YEAR},
{"file": SimpleUploadedFile("test", b"test_content")},
False,
"reference_code",
Expand Down Expand Up @@ -638,7 +643,7 @@ def test_attach_fiream_dealer_certificate_form(data, files, valid, error_field,
if valid:
assert form.cleaned_data["expiry_date_day"] == "1"
assert form.cleaned_data["expiry_date_month"] == "1"
assert form.cleaned_data["expiry_date_year"] == "2025"
assert form.cleaned_data["expiry_date_year"] == str(FUTURE_YEAR)
else:
assert form.errors[error_field][0] == error_message

Expand Down

0 comments on commit 7451e92

Please sign in to comment.