1717@pytest .mark .django_db
1818class TestBreastAugmentationHistoryForm :
1919 def test_no_data (self , clinical_user ):
20- appointment = AppointmentFactory ()
2120 request = RequestFactory ().get ("/test-form" )
2221 request .user = clinical_user
2322
24- form = BreastAugmentationHistoryForm (
25- QueryDict (), participant = appointment .participant
26- )
23+ form = BreastAugmentationHistoryForm (QueryDict ())
2724
2825 assert not form .is_valid ()
2926 assert form .errors == {
@@ -32,7 +29,6 @@ def test_no_data(self, clinical_user):
3229 }
3330
3431 def test_procedure_year_invalid_format (self , clinical_user ):
35- appointment = AppointmentFactory ()
3632 request = RequestFactory ().get ("/test-form" )
3733 request .user = clinical_user
3834
@@ -51,11 +47,10 @@ def test_procedure_year_invalid_format(self, clinical_user):
5147 doseq = True ,
5248 )
5349 ),
54- participant = appointment .participant ,
5550 )
5651
5752 assert not form .is_valid ()
58- assert form .errors == {"procedure_year" : ["Enter year as a number." ]}
53+ assert form .errors == {"procedure_year" : ["Enter a whole number." ]}
5954
6055 @pytest .mark .parametrize (
6156 "selected_breast_procedures" ,
@@ -78,7 +73,6 @@ def test_procedure_year_invalid_format(self, clinical_user):
7873 def test_no_procedures_and_other_options (
7974 self , clinical_user , selected_breast_procedures
8075 ):
81- appointment = AppointmentFactory ()
8276 request = RequestFactory ().get ("/test-form" )
8377 request .user = clinical_user
8478
@@ -94,7 +88,6 @@ def test_no_procedures_and_other_options(
9488 doseq = True ,
9589 )
9690 ),
97- participant = appointment .participant ,
9891 )
9992
10093 assert not form .is_valid ()
@@ -116,7 +109,6 @@ def test_no_procedures_and_other_options(
116109 doseq = True ,
117110 )
118111 ),
119- participant = appointment .participant ,
120112 )
121113
122114 assert not form .is_valid ()
@@ -127,7 +119,6 @@ def test_no_procedures_and_other_options(
127119 }
128120
129121 def test_removal_year_invalid_format (self , clinical_user ):
130- appointment = AppointmentFactory ()
131122 request = RequestFactory ().get ("/test-form" )
132123 request .user = clinical_user
133124
@@ -147,13 +138,12 @@ def test_removal_year_invalid_format(self, clinical_user):
147138 doseq = True ,
148139 )
149140 ),
150- participant = appointment .participant ,
151141 )
152142
153143 assert not form .is_valid ()
154144 assert form .errors == {
155145 "removal_year" : [
156- "Enter year as a number." ,
146+ "Enter a whole number." ,
157147 ]
158148 }
159149
@@ -168,14 +158,15 @@ def test_removal_year_invalid_format(self, clinical_user):
168158 ],
169159 )
170160 def test_procedure_year_outside_range (self , clinical_user , procedure_year ):
171- appointment = AppointmentFactory ()
172161 request = RequestFactory ().get ("/test-form" )
173162 request .user = clinical_user
174163
175164 max_year = datetime .date .today ().year
176165 min_year = max_year - 80
177166 year_outside_range_error_message = (
178- f"Year should be between { min_year } and { max_year } ."
167+ (f"Year must be { max_year } or earlier" )
168+ if procedure_year > max_year
169+ else (f"Year must be { min_year } or later" )
179170 )
180171 form = BreastAugmentationHistoryForm (
181172 QueryDict (
@@ -192,7 +183,6 @@ def test_procedure_year_outside_range(self, clinical_user, procedure_year):
192183 doseq = True ,
193184 )
194185 ),
195- participant = appointment .participant ,
196186 )
197187
198188 assert not form .is_valid ()
@@ -209,14 +199,15 @@ def test_procedure_year_outside_range(self, clinical_user, procedure_year):
209199 ],
210200 )
211201 def test_removal_year_outside_range (self , clinical_user , removal_year ):
212- appointment = AppointmentFactory ()
213202 request = RequestFactory ().get ("/test-form" )
214203 request .user = clinical_user
215204
216205 max_year = datetime .date .today ().year
217206 min_year = max_year - 80
218207 year_outside_range_error_message = (
219- f"Year should be between { min_year } and { max_year } ."
208+ (f"Year must be { max_year } or earlier" )
209+ if removal_year > max_year
210+ else (f"Year must be { min_year } or later" )
220211 )
221212 form = BreastAugmentationHistoryForm (
222213 QueryDict (
@@ -234,7 +225,6 @@ def test_removal_year_outside_range(self, clinical_user, removal_year):
234225 doseq = True ,
235226 )
236227 ),
237- participant = appointment .participant ,
238228 )
239229
240230 assert not form .is_valid ()
@@ -255,7 +245,6 @@ def test_removal_year_outside_range(self, clinical_user, removal_year):
255245 def test_removal_year_before_procedure_year (
256246 self , clinical_user , procedure_year , removal_year
257247 ):
258- appointment = AppointmentFactory ()
259248 request = RequestFactory ().get ("/test-form" )
260249 request .user = clinical_user
261250
@@ -276,7 +265,6 @@ def test_removal_year_before_procedure_year(
276265 doseq = True ,
277266 )
278267 ),
279- participant = appointment .participant ,
280268 )
281269
282270 assert not form .is_valid ()
@@ -306,7 +294,6 @@ def test_removal_year_when_not_removed(self, clinical_user):
306294 doseq = True ,
307295 )
308296 ),
309- participant = appointment .participant ,
310297 )
311298
312299 # confirm full_clean removes removal_year but keeps procedure_year
@@ -425,7 +412,6 @@ def test_success(self, clinical_user, data):
425412
426413 form = BreastAugmentationHistoryForm (
427414 QueryDict (urlencode (data , doseq = True )),
428- participant = appointment .participant ,
429415 )
430416
431417 assert form .is_valid ()
0 commit comments