Skip to content

Commit 1810cb9

Browse files
committed
Handle stale deletes when appointment note doesn't exist
If a user clicks on a stale delete link for an appointment note that has already been deleted, simply redirect them back to the note tab.
1 parent b0a5909 commit 1810cb9

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

manage_breast_screening/mammograms/tests/views/test_appointment_note_views.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,36 @@ def test_users_can_update_note(self, request, client_fixture):
8585
updated_note = AppointmentNote.objects.get(pk=note.pk)
8686
assert updated_note.content == updated_content
8787
assert AppointmentNote.objects.count() == 1
88+
89+
90+
@pytest.mark.django_db
91+
class TestDeleteAppointmentNoteView:
92+
def test_get_redirects_when_note_does_not_exist(self, clinical_user_client):
93+
appointment = AppointmentFactory.create(
94+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
95+
)
96+
response = clinical_user_client.http.get(
97+
reverse(
98+
"mammograms:delete_appointment_note",
99+
kwargs={"pk": appointment.pk},
100+
)
101+
)
102+
assertRedirects(
103+
response,
104+
reverse("mammograms:appointment_note", kwargs={"pk": appointment.pk}),
105+
)
106+
107+
def test_post_redirects_when_note_does_not_exist(self, clinical_user_client):
108+
appointment = AppointmentFactory.create(
109+
clinic_slot__clinic__setting__provider=clinical_user_client.current_provider
110+
)
111+
response = clinical_user_client.http.post(
112+
reverse(
113+
"mammograms:delete_appointment_note",
114+
kwargs={"pk": appointment.pk},
115+
)
116+
)
117+
assertRedirects(
118+
response,
119+
reverse("mammograms:appointment_note", kwargs={"pk": appointment.pk}),
120+
)

manage_breast_screening/mammograms/views/appointment_note_views.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,15 @@ def get_object(self):
7878

7979
def get_success_url(self):
8080
return reverse("mammograms:appointment_note", kwargs={"pk": self.kwargs["pk"]})
81+
82+
def get(self, request, *args, **kwargs):
83+
try:
84+
return super().get(request, *args, **kwargs)
85+
except AppointmentNote.DoesNotExist:
86+
return redirect(self.get_success_url())
87+
88+
def post(self, request, *args, **kwargs):
89+
try:
90+
return super().post(request, *args, **kwargs)
91+
except AppointmentNote.DoesNotExist:
92+
return redirect(self.get_success_url())

0 commit comments

Comments
 (0)