Skip to content

Commit 42e85d1

Browse files
authored
Merge pull request #594 from NHSDigital/test-nbss-dat-file-processing-order
Add an integration test to verify blob file ordering
2 parents 1da056f + dc85ed1 commit 42e85d1

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"NBSSAPPT_HDR"|"00000013"|"20250128"|"170922"|"000003"
22
"NBSSAPPT_FLDS"|"Sequence"|"BSO"|"Action"|"Clinic Code"|"Holding Clinic"|"Status"|"Attended Not Scr"|"Appointment ID"|"NHS Num"|"Episode Type"|"Episode Start"|"Batch ID"|"Screen or Asses"|"Screen Appt num"|"Booked By"|"Cancelled By"|"Appt Date"|"Appt Time"|"Location"|"Clinic Name"|"Clinic Name (Let)"|"Clinic Address 1"|"Clinic Address 2"|"Clinic Address 3"|"Clinic Address 4"|"Clinic Address 5"|"Postcode"|"Action Timestamp"
3-
"NBSSAPPT_DATA"|"000001"|"KMK"|"C"|"BU011"|"N"|"C"|"N"|"BU011-67278-RA1-DN-Y1111-1"|"9449305552"|"F"|"20250128"|"KMK001326"|"S"|"1"|"H"|"C"|"20250314"|"1345"|"MKGH"|"BREAST CARE UNIT"|"BREAST CARE UNIT"|"BREAST CARE UNIT"|"MILTON KEYNES HOSPITAL"|"STANDING WAY"|"MILTON KEYNES"|"MK6 5LD"|"MK6 5LD"|"20250128-154003"
3+
"NBSSAPPT_DATA"|"000001"|"KMK"|"C"|"BU011"|"N"|"C"|"N"|"BU011-67278-RA1-DN-Y1111-1"|"9449305552"|"F"|"20250128"|"KMK001326"|"S"|"1"|"H"|"C"|"20250314"|"1345"|"MKGH"|"BREAST CARE UNIT"|"BREAST CARE UNIT"|"BREAST CARE UNIT"|"MILTON KEYNES HOSPITAL"|"STANDING WAY"|"MILTON KEYNES"|"MK6 5LD"|"MK6 5LD"|"20250128-175555"
44
"NBSSAPPT_END"|"00000013"|"20250128"|"17:09:22"|"000003"

manage_breast_screening/notifications/tests/integration/test_create_appointments_from_azure_storage.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def helpers(self):
2727
@pytest.mark.django_db
2828
def test_appointments_created_from_file_stored_in_azure(self, helpers):
2929
today_dirname = datetime.today().strftime("%Y-%m-%d")
30-
test_file_path = "ABC_20241202091221_APPT_106.dat"
31-
blob_name = f"{today_dirname}/{test_file_path}"
30+
test_file_name = "ABC_20241202091221_APPT_106.dat"
31+
blob_name = f"{today_dirname}/{test_file_name}"
3232

33-
with open(helpers.get_test_file_path(test_file_path)) as test_file:
33+
with open(helpers.get_test_file_path(test_file_name)) as test_file:
3434
BlobStorage().add(blob_name, test_file.read())
3535

3636
Command().handle(**{"date_str": today_dirname})
@@ -75,3 +75,27 @@ def test_appointments_created_from_file_stored_in_azure(self, helpers):
7575

7676
assert appointments[0].clinic == clinics[1]
7777
assert appointments[1].clinic == clinics[1]
78+
79+
@pytest.mark.django_db
80+
def test_files_are_processed_in_correct_order(self, helpers):
81+
today_dirname = datetime.today().strftime("%Y-%m-%d")
82+
test_file_names = [
83+
"ABC_20241202091221_APPT_106.dat",
84+
"ABC_20241202091321_APPT_107.dat",
85+
]
86+
for test_file_name in test_file_names:
87+
blob_name = f"{today_dirname}/{test_file_name}"
88+
89+
with open(helpers.get_test_file_path(test_file_name)) as test_file:
90+
BlobStorage().add(blob_name, test_file.read())
91+
92+
Command().handle(**{"date_str": today_dirname})
93+
94+
assessment = Appointment.objects.filter(nhs_number="9449306621").first()
95+
booked_then_cancelled = Appointment.objects.filter(
96+
nhs_number="9449305552"
97+
).first()
98+
assert booked_then_cancelled.updated_at is not None
99+
assert booked_then_cancelled.cancelled_at is not None
100+
assert assessment.created_at < booked_then_cancelled.updated_at
101+
assert booked_then_cancelled.booked_at < booked_then_cancelled.cancelled_at

manage_breast_screening/notifications/tests/management/commands/test_create_appointments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_handle_updates_records(self):
185185
assert appointments[0].status == "C"
186186
assert appointments[0].cancelled_by == "C"
187187
assert appointments[0].cancelled_at == datetime.strptime(
188-
"20250128-154003", "%Y%m%d-%H%M%S"
188+
"20250128-175555", "%Y%m%d-%H%M%S"
189189
).replace(tzinfo=TZ_INFO)
190190

191191
def test_only_updates_cancelled_appointments(self):

0 commit comments

Comments
 (0)