1616 ClinicFactory ,
1717)
1818
19+ VALID_DATA_FILE = "ABC_20241202091221_APPT_106.dat"
20+ UPDATED_APPOINTMENT_FILE = "ABC_20241202091321_APPT_107.dat"
21+ HOLDING_CLINIC_APPOINTMENT_FILE = "ABC_20241202091421_APPT_108.dat"
22+
1923
2024class TestCreateAppointments :
2125 def fixture_file_path (self , filename ):
@@ -32,12 +36,10 @@ def test_handle_creates_records(self):
3236
3337 mock_container_client = PropertyMock (spec = ContainerClient )
3438 mock_blob = Mock (spec = BlobProperties )
35- mock_blob .name = PropertyMock (
36- return_value = f"{ today_dirname } /ABC_20241202091221_APPT_106.dat"
37- )
39+ mock_blob .name = PropertyMock (return_value = f"{ today_dirname } /{ VALID_DATA_FILE } " )
3840 mock_container_client .list_blobs .return_value = [mock_blob ]
3941 mock_container_client .get_blob_client ().download_blob ().readall .return_value = (
40- open (self .fixture_file_path ("ABC_20241202091221_APPT_106.dat" )).read ()
42+ open (self .fixture_file_path (VALID_DATA_FILE )).read ()
4143 )
4244 subject .container_client = mock_container_client
4345
@@ -93,6 +95,32 @@ def test_handle_creates_records(self):
9395 assert appointments [1 ].clinic == clinics [1 ]
9496 assert appointments [2 ].clinic == clinics [1 ]
9597
98+ @pytest .mark .django_db
99+ def test_handles_holding_clinics (self ):
100+ """Test does not create appointments for valid NBSS data marked as a Holding Clinic"""
101+ today_dirname = datetime .today ().strftime ("%Y-%m-%d" )
102+
103+ subject = Command ()
104+
105+ mock_container_client = PropertyMock (spec = ContainerClient )
106+ mock_blob = Mock (spec = BlobProperties )
107+ mock_blob .name = PropertyMock (
108+ return_value = f"{ today_dirname } /{ HOLDING_CLINIC_APPOINTMENT_FILE } "
109+ )
110+ mock_container_client .list_blobs .return_value = [mock_blob ]
111+ mock_container_client .get_blob_client ().download_blob ().readall .return_value = (
112+ open (self .fixture_file_path (HOLDING_CLINIC_APPOINTMENT_FILE )).read ()
113+ )
114+ subject .container_client = mock_container_client
115+
116+ subject .handle (** {"date_str" : today_dirname })
117+
118+ assert Clinic .objects .count () == 1
119+ assert Clinic .objects .filter (code = "BU011" ).first () is None
120+
121+ assert Clinic .objects .count () == 1
122+ assert Appointment .objects .filter (nhs_number = 9449306625 ).first () is None
123+
96124 @pytest .mark .django_db
97125 def test_handle_updates_records (self ):
98126 """Test Appointment record update from valid NBSS data stored in Azure storage blob"""
@@ -117,17 +145,15 @@ def test_handle_updates_records(self):
117145
118146 # Receive a cancellation for existing appointment
119147 today = datetime .now ()
120- raw_data = open (
121- self .fixture_file_path ("ABC_20241202091321_APPT_107.dat" )
122- ).read ()
148+ raw_data = open (self .fixture_file_path (UPDATED_APPOINTMENT_FILE )).read ()
123149 today_dirname = today .strftime ("%Y-%m-%d" )
124150
125151 subject = Command ()
126152
127153 mock_container_client = PropertyMock (spec = ContainerClient )
128154 mock_blob = Mock (spec = BlobProperties )
129155 mock_blob .name = PropertyMock (
130- return_value = f"{ today_dirname } /ABC_20241202091321_APPT_107.dat "
156+ return_value = f"{ today_dirname } /{ UPDATED_APPOINTMENT_FILE } "
131157 )
132158 mock_container_client .list_blobs .return_value = [mock_blob ]
133159 mock_container_client .get_blob_client ().download_blob ().readall .return_value = (
@@ -155,12 +181,10 @@ def test_handle_accept_date_arg(self):
155181
156182 mock_container_client = PropertyMock (spec = ContainerClient )
157183 mock_blob = Mock (spec = BlobProperties )
158- mock_blob .name = PropertyMock (
159- return_value = "2025-07-01/ABC_20241202091221_APPT_106.dat"
160- )
184+ mock_blob .name = PropertyMock (return_value = f"2025-07-01/{ VALID_DATA_FILE } " )
161185 mock_container_client .list_blobs .return_value = [mock_blob ]
162186 mock_container_client .get_blob_client ().download_blob ().readall .return_value = (
163- open (self .fixture_file_path ("ABC_20241202091221_APPT_106.dat" )).read ()
187+ open (self .fixture_file_path (VALID_DATA_FILE )).read ()
164188 )
165189 subject .container_client = mock_container_client
166190
0 commit comments