1+ from datetime import date
12from urllib .parse import urlencode
23
34import pytest
@@ -51,12 +52,15 @@ def test_no_data_not_valid(self):
5152 "systemic_treatments" : ["Select what systemic treatments they have had" ],
5253 }
5354
54- def test_valid_form (self ):
55+ def test_valid_form (self , time_machine ):
56+ time_machine .move_to (date (2025 , 1 , 1 ))
57+
5558 form = BreastCancerHistoryForm (
5659 data = QueryDict (
5760 urlencode (
5861 {
5962 "diagnosis_location" : "RIGHT_BREAST" ,
63+ "diagnosis_year" : "2013" ,
6064 "intervention_location" : "NHS_HOSPITAL" ,
6165 "intervention_location_details_nhs_hospital" : "abc" ,
6266 "left_breast_other_surgery" : "NO_SURGERY" ,
@@ -73,6 +77,32 @@ def test_valid_form(self):
7377
7478 assert form .is_valid (), form .errors
7579
80+ def test_invalid_date (self , time_machine ):
81+ time_machine .move_to (date (2025 , 1 , 1 ))
82+
83+ form = BreastCancerHistoryForm (
84+ data = QueryDict (
85+ urlencode (
86+ {
87+ "diagnosis_location" : "RIGHT_BREAST" ,
88+ "diagnosis_year" : "1900" ,
89+ "intervention_location" : "NHS_HOSPITAL" ,
90+ "intervention_location_details_nhs_hospital" : "abc" ,
91+ "left_breast_other_surgery" : "NO_SURGERY" ,
92+ "left_breast_procedure" : "NO_PROCEDURE" ,
93+ "left_breast_treatment" : "NO_RADIOTHERAPY" ,
94+ "right_breast_other_surgery" : "LYMPH_NODE_SURGERY" ,
95+ "right_breast_procedure" : "LUMPECTOMY" ,
96+ "right_breast_treatment" : "BREAST_RADIOTHERAPY" ,
97+ "systemic_treatments" : "NO_SYSTEMIC_TREATMENTS" ,
98+ }
99+ )
100+ )
101+ )
102+
103+ assert not form .is_valid ()
104+ assert form .errors == {"diagnosis_year" : ["Year must be 1945 or later" ]}
105+
76106 def test_missing_intervention_location_details (self ):
77107 form = BreastCancerHistoryForm (
78108 data = QueryDict (
0 commit comments