|
| 1 | +from datetime import datetime |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from manage_breast_screening.notifications.management.commands.create_appointments import ( |
| 6 | + TZ_INFO, |
| 7 | + Command, |
| 8 | +) |
| 9 | +from manage_breast_screening.notifications.models import Appointment, Clinic |
| 10 | +from manage_breast_screening.notifications.tests.integration.helpers import Helpers |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.integration |
| 14 | +class TestCreateAppointmentsFromAzureStorage: |
| 15 | + @pytest.fixture(autouse=True) |
| 16 | + def setup(self, monkeypatch): |
| 17 | + monkeypatch.setenv( |
| 18 | + "BLOB_STORAGE_CONNECTION_STRING", Helpers().azurite_connection_string() |
| 19 | + ) |
| 20 | + monkeypatch.setenv("BLOB_CONTAINER_NAME", "nbss-appoinments-data") |
| 21 | + |
| 22 | + @pytest.fixture |
| 23 | + def helpers(self): |
| 24 | + return Helpers() |
| 25 | + |
| 26 | + @pytest.mark.django_db |
| 27 | + def test_appointments_created_from_file_stored_in_azure(self, helpers): |
| 28 | + today_dirname = datetime.today().strftime("%Y-%m-%d") |
| 29 | + |
| 30 | + with open(helpers.test_dat_file_path()) as test_file: |
| 31 | + helpers.add_to_blob_storage(f"{today_dirname}/test.dat", test_file.read()) |
| 32 | + |
| 33 | + Command().handle(**{"date_str": today_dirname}) |
| 34 | + |
| 35 | + assert Clinic.objects.count() == 2 |
| 36 | + clinics = Clinic.objects.all() |
| 37 | + |
| 38 | + assert clinics[0].code == "BU003" |
| 39 | + assert clinics[0].bso_code == "KMK" |
| 40 | + assert clinics[0].holding_clinic is False |
| 41 | + assert clinics[0].name == "BREAST CARE UNIT" |
| 42 | + assert clinics[0].address_line_1 == "BREAST CARE UNIT" |
| 43 | + assert clinics[0].address_line_2 == "MILTON KEYNES HOSPITAL" |
| 44 | + assert clinics[0].address_line_3 == "STANDING WAY" |
| 45 | + assert clinics[0].address_line_4 == "MILTON KEYNES" |
| 46 | + assert clinics[0].address_line_5 == "MK6 5LD" |
| 47 | + assert clinics[0].postcode == "MK6 5LD" |
| 48 | + |
| 49 | + assert clinics[1].code == "BU011" |
| 50 | + assert clinics[1].bso_code == "KMK" |
| 51 | + assert clinics[1].holding_clinic is False |
| 52 | + assert clinics[1].name == "BREAST CARE UNIT" |
| 53 | + assert clinics[1].address_line_1 == "BREAST CARE UNIT" |
| 54 | + assert clinics[1].address_line_2 == "MILTON KEYNES HOSPITAL" |
| 55 | + assert clinics[1].address_line_3 == "STANDING WAY" |
| 56 | + assert clinics[1].address_line_4 == "MILTON KEYNES" |
| 57 | + assert clinics[1].address_line_5 == "MK6 5LD" |
| 58 | + assert clinics[1].postcode == "MK6 5LD" |
| 59 | + |
| 60 | + assert Appointment.objects.count() == 3 |
| 61 | + appointments = Appointment.objects.all() |
| 62 | + |
| 63 | + assert appointments[0].nhs_number == 9449304424 |
| 64 | + assert appointments[1].nhs_number == 9449305552 |
| 65 | + assert appointments[2].nhs_number == 9449306621 |
| 66 | + |
| 67 | + assert appointments[0].starts_at == datetime(2025, 1, 10, 8, 45, tzinfo=TZ_INFO) |
| 68 | + assert appointments[1].starts_at == datetime( |
| 69 | + 2025, 3, 14, 13, 45, tzinfo=TZ_INFO |
| 70 | + ) |
| 71 | + assert appointments[2].starts_at == datetime( |
| 72 | + 2025, 3, 14, 14, 45, tzinfo=TZ_INFO |
| 73 | + ) |
| 74 | + |
| 75 | + assert appointments[0].clinic == clinics[0] |
| 76 | + assert appointments[1].clinic == clinics[1] |
| 77 | + assert appointments[2].clinic == clinics[1] |
0 commit comments