From 0bffc5b6fd1337f0b4d6a7cc458df90936a3a5f9 Mon Sep 17 00:00:00 2001 From: Andy Mitchell <326561+Themitchell@users.noreply.github.com> Date: Thu, 2 Apr 2026 12:04:23 +0100 Subject: [PATCH] Ensure user must be logged in to see book an appointment --- .../unit/views/test_book_an_appointment.py | 20 +++++++++++++++++++ .../questions/views/book_an_appointment.py | 5 ++--- 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 lung_cancer_screening/questions/tests/unit/views/test_book_an_appointment.py diff --git a/lung_cancer_screening/questions/tests/unit/views/test_book_an_appointment.py b/lung_cancer_screening/questions/tests/unit/views/test_book_an_appointment.py new file mode 100644 index 00000000..43662565 --- /dev/null +++ b/lung_cancer_screening/questions/tests/unit/views/test_book_an_appointment.py @@ -0,0 +1,20 @@ +from django.test import TestCase, tag +from django.urls import reverse + +from .helpers.authentication import login_user + +@tag("BookAnAppointment") +class TestGetBookAnAppointment(TestCase): + def setUp(self): + self.user = login_user(self.client) + + def test_get_redirects_if_the_user_is_not_logged_in(self): + self.client.logout() + + response = self.client.get(reverse("questions:book_an_appointment")) + + self.assertRedirects( + response, + "/oidc/authenticate/?next=/call-us-to-book-an-appointment", + fetch_redirect_response=False, + ) diff --git a/lung_cancer_screening/questions/views/book_an_appointment.py b/lung_cancer_screening/questions/views/book_an_appointment.py index b73bef79..280b9c89 100644 --- a/lung_cancer_screening/questions/views/book_an_appointment.py +++ b/lung_cancer_screening/questions/views/book_an_appointment.py @@ -1,10 +1,9 @@ from django.shortcuts import render from django.views import View +from django.contrib.auth.mixins import LoginRequiredMixin -from .mixins.ensure_response_set import EnsureResponseSet - -class BookAnAppointmentExitView(EnsureResponseSet, View): +class BookAnAppointmentExitView(LoginRequiredMixin, View): def get(self, request): return render( request,