66from pytest_django .asserts import assertInHTML , assertRedirects
77
88from manage_breast_screening .participants .forms import ParticipantReportedMammogramForm
9+ from manage_breast_screening .participants .models import ParticipantReportedMammogram
910from manage_breast_screening .participants .models .appointment import AppointmentStatus
1011from manage_breast_screening .participants .tests .factories import AppointmentFactory
1112
@@ -19,7 +20,7 @@ def test_get(self, clinical_user_client):
1920 response = clinical_user_client .http .get (
2021 reverse (
2122 "mammograms:add_previous_mammogram" ,
22- kwargs = {"appointment_pk " : appointment .pk },
23+ kwargs = {"pk " : appointment .pk },
2324 )
2425 )
2526 assert response .status_code == 200
@@ -31,31 +32,17 @@ def test_post_with_missing_parameters(self, clinical_user_client):
3132 response = clinical_user_client .http .post (
3233 reverse (
3334 "mammograms:add_previous_mammogram" ,
34- kwargs = {"appointment_pk " : appointment .pk },
35+ kwargs = {"pk " : appointment .pk },
3536 )
3637 )
3738 assert response .status_code == 200
3839 assertInHTML (
3940 """
40- <span id="id_where_taken-error" class="nhsuk-error-message">
41- <span class="nhsuk-u-visually-hidden">Error:</span> This field is required.
42- </span>
43- """ ,
44- response .text ,
45- )
46- assertInHTML (
47- """
48- <span id="id_when_taken-error" class="nhsuk-error-message">
49- <span class="nhsuk-u-visually-hidden">Error:</span> This field is required.
50- </span>
51- """ ,
52- response .text ,
53- )
54- assertInHTML (
55- """
56- <span id="id_name_is_the_same-error" class="nhsuk-error-message">
57- <span class="nhsuk-u-visually-hidden">Error:</span> This field is required.
58- </span>
41+ <ul class="nhsuk-list nhsuk-error-summary__list">
42+ <li><a href="#id_location_type">Select where the breast x-rays were taken</a></li>
43+ <li><a href="#id_when_taken">Select when the x-rays were taken</a></li>
44+ <li><a href="#id_name_is_the_same">Select if the x-rays were taken with the same name</a></li>
45+ </ul>
5946 """ ,
6047 response .text ,
6148 )
@@ -72,11 +59,11 @@ def test_post_date_unsure(self, clinical_user_client):
7259 response = clinical_user_client .http .post (
7360 reverse (
7461 "mammograms:add_previous_mammogram" ,
75- kwargs = {"appointment_pk " : appointment .pk },
62+ kwargs = {"pk " : appointment .pk },
7663 ),
7764 {
7865 "return_url" : return_url ,
79- "where_taken " : ParticipantReportedMammogramForm . WhereTaken . SAME_UNIT ,
66+ "location_type " : ParticipantReportedMammogram . LocationType . NHS_BREAST_SCREENING_UNIT ,
8067 "when_taken" : ParticipantReportedMammogramForm .WhenTaken .NOT_SURE ,
8168 "name_is_the_same" : ParticipantReportedMammogramForm .NameIsTheSame .YES ,
8269 },
@@ -96,11 +83,11 @@ def test_post_approx_date(self, clinical_user_client):
9683 response = clinical_user_client .http .post (
9784 reverse (
9885 "mammograms:add_previous_mammogram" ,
99- kwargs = {"appointment_pk " : appointment .pk },
86+ kwargs = {"pk " : appointment .pk },
10087 ),
10188 {
10289 "return_url" : return_url ,
103- "where_taken " : ParticipantReportedMammogramForm . WhereTaken . SAME_UNIT ,
90+ "location_type " : ParticipantReportedMammogram . LocationType . NHS_BREAST_SCREENING_UNIT ,
10491 "when_taken" : ParticipantReportedMammogramForm .WhenTaken .APPROX ,
10592 "approx_date" : "last month" ,
10693 "name_is_the_same" : ParticipantReportedMammogramForm .NameIsTheSame .YES ,
@@ -131,11 +118,11 @@ def test_post_exact_date_six_months_ago_or_later(
131118 response = clinical_user_client .http .post (
132119 reverse (
133120 "mammograms:add_previous_mammogram" ,
134- kwargs = {"appointment_pk " : appointment .pk },
121+ kwargs = {"pk " : appointment .pk },
135122 ),
136123 {
137124 "return_url" : return_url ,
138- "where_taken " : ParticipantReportedMammogramForm . WhereTaken . SAME_UNIT ,
125+ "location_type " : ParticipantReportedMammogram . LocationType . NHS_BREAST_SCREENING_UNIT ,
139126 "when_taken" : ParticipantReportedMammogramForm .WhenTaken .EXACT ,
140127 "exact_date_0" : exact_date .day ,
141128 "exact_date_1" : exact_date .month ,
@@ -165,28 +152,43 @@ def test_post_exact_date_within_last_six_months(
165152 kwargs = {"pk" : appointment .pk },
166153 )
167154
155+ assert (
156+ ParticipantReportedMammogram .objects .filter (
157+ participant = appointment .participant
158+ ).count ()
159+ == 0
160+ )
161+
168162 response = clinical_user_client .http .post (
169163 reverse (
170164 "mammograms:add_previous_mammogram" ,
171- kwargs = {"appointment_pk " : appointment .pk },
165+ kwargs = {"pk " : appointment .pk },
172166 ),
173167 {
174168 "return_url" : return_url ,
175- "where_taken " : ParticipantReportedMammogramForm . WhereTaken . SAME_UNIT ,
169+ "location_type " : ParticipantReportedMammogram . LocationType . NHS_BREAST_SCREENING_UNIT ,
176170 "when_taken" : ParticipantReportedMammogramForm .WhenTaken .EXACT ,
177171 "exact_date_0" : exact_date .day ,
178172 "exact_date_1" : exact_date .month ,
179173 "exact_date_2" : exact_date .year ,
180174 "name_is_the_same" : ParticipantReportedMammogramForm .NameIsTheSame .YES ,
181175 },
182176 )
177+
178+ mammogram = ParticipantReportedMammogram .objects .filter (
179+ participant = appointment .participant
180+ ).first ()
181+
183182 assertRedirects (
184183 response ,
185184 reverse (
186185 "mammograms:appointment_should_not_proceed" ,
187- kwargs = {"appointment_pk" : appointment .pk },
186+ kwargs = {
187+ "appointment_pk" : appointment .pk ,
188+ "participant_reported_mammogram_pk" : mammogram .pk ,
189+ },
188190 )
189- + f"?exact_date= { exact_date . isoformat () } " ,
191+ + f"?return_url= { return_url } " ,
190192 )
191193 assert appointment .current_status .state == AppointmentStatus .CONFIRMED
192194
0 commit comments