|
5 | 5 | from manage_breast_screening.clinics.tests.factories import AppointmentFactory |
6 | 6 |
|
7 | 7 |
|
| 8 | +@pytest.fixture |
| 9 | +def appointment(): |
| 10 | + return AppointmentFactory.create() |
| 11 | + |
| 12 | + |
8 | 13 | @pytest.mark.django_db |
9 | 14 | class TestStartScreening: |
10 | | - @pytest.fixture(autouse=True) |
11 | | - def setup(self): |
12 | | - self.appointment = AppointmentFactory.create() |
13 | | - |
14 | | - def test_appointment_continued(self, client): |
| 15 | + def test_appointment_continued(self, client, appointment): |
15 | 16 | response = client.post( |
16 | 17 | reverse( |
17 | | - "record_a_mammogram:start_screening", kwargs={"id": self.appointment.pk} |
| 18 | + "record_a_mammogram:start_screening", kwargs={"id": appointment.pk} |
18 | 19 | ), |
19 | 20 | {"decision": "continue"}, |
20 | 21 | ) |
21 | 22 | assertRedirects( |
22 | 23 | response, |
23 | 24 | reverse( |
24 | 25 | "record_a_mammogram:ask_for_medical_information", |
25 | | - kwargs={"id": self.appointment.pk}, |
| 26 | + kwargs={"id": appointment.pk}, |
26 | 27 | ), |
27 | 28 | ) |
28 | 29 |
|
29 | | - def test_appointment_stopped(self, client): |
| 30 | + def test_appointment_stopped(self, client, appointment): |
30 | 31 | response = client.post( |
31 | 32 | reverse( |
32 | | - "record_a_mammogram:start_screening", kwargs={"id": self.appointment.pk} |
| 33 | + "record_a_mammogram:start_screening", kwargs={"id": appointment.pk} |
33 | 34 | ), |
34 | 35 | {"decision": "dropout"}, |
35 | 36 | ) |
36 | 37 | assertRedirects( |
37 | 38 | response, |
38 | 39 | reverse( |
39 | 40 | "record_a_mammogram:appointment_cannot_go_ahead", |
40 | | - kwargs={"id": self.appointment.pk}, |
| 41 | + kwargs={"id": appointment.pk}, |
41 | 42 | ), |
42 | 43 | ) |
43 | 44 |
|
44 | | - def test_renders_invalid_form(self, client): |
| 45 | + def test_renders_invalid_form(self, client, appointment): |
45 | 46 | response = client.post( |
46 | 47 | reverse( |
47 | | - "record_a_mammogram:start_screening", kwargs={"id": self.appointment.pk} |
| 48 | + "record_a_mammogram:start_screening", kwargs={"id": appointment.pk} |
48 | 49 | ), |
49 | 50 | {}, |
50 | 51 | ) |
51 | 52 | assertContains(response, "There is a problem") |
52 | 53 |
|
53 | 54 |
|
54 | 55 | @pytest.mark.django_db |
55 | | -class TestCheckIn: |
56 | | - @pytest.fixture(autouse=True) |
57 | | - def setup(self): |
58 | | - self.appointment = AppointmentFactory.create() |
| 56 | +class TestAskForMedicalInformation: |
| 57 | + def test_continue_to_record(self, client, appointment): |
| 58 | + response = client.post( |
| 59 | + reverse( |
| 60 | + "record_a_mammogram:ask_for_medical_information", |
| 61 | + kwargs={"id": appointment.pk}, |
| 62 | + ), |
| 63 | + {"decision": "yes"}, |
| 64 | + ) |
| 65 | + assertRedirects( |
| 66 | + response, |
| 67 | + reverse( |
| 68 | + "record_a_mammogram:record_medical_information", |
| 69 | + kwargs={"id": appointment.pk}, |
| 70 | + ), |
| 71 | + ) |
| 72 | + |
| 73 | + def test_continue_to_imaging(self, client, appointment): |
| 74 | + response = client.post( |
| 75 | + reverse( |
| 76 | + "record_a_mammogram:ask_for_medical_information", |
| 77 | + kwargs={"id": appointment.pk}, |
| 78 | + ), |
| 79 | + {"decision": "no"}, |
| 80 | + ) |
| 81 | + assertRedirects( |
| 82 | + response, |
| 83 | + reverse( |
| 84 | + "record_a_mammogram:awaiting_images", |
| 85 | + kwargs={"id": appointment.pk}, |
| 86 | + ), |
| 87 | + ) |
| 88 | + |
| 89 | + def test_renders_invalid_form(self, client, appointment): |
| 90 | + response = client.post( |
| 91 | + reverse( |
| 92 | + "record_a_mammogram:ask_for_medical_information", |
| 93 | + kwargs={"id": appointment.pk}, |
| 94 | + ), |
| 95 | + {}, |
| 96 | + ) |
| 97 | + assertContains(response, "There is a problem") |
| 98 | + |
59 | 99 |
|
60 | | - def test_known_redirect(self, client): |
| 100 | +@pytest.mark.django_db |
| 101 | +class TestCheckIn: |
| 102 | + def test_known_redirect(self, client, appointment): |
61 | 103 | response = client.post( |
62 | | - reverse("record_a_mammogram:check_in", kwargs={"id": self.appointment.pk}), |
| 104 | + reverse("record_a_mammogram:check_in", kwargs={"id": appointment.pk}), |
63 | 105 | {"next": "start-screening"}, |
64 | 106 | ) |
65 | 107 | assertRedirects( |
66 | 108 | response, |
67 | 109 | reverse( |
68 | | - "record_a_mammogram:start_screening", kwargs={"id": self.appointment.pk} |
| 110 | + "record_a_mammogram:start_screening", kwargs={"id": appointment.pk} |
69 | 111 | ), |
70 | 112 | ) |
0 commit comments