Skip to content

Commit 5396167

Browse files
committed
save blob_name on an Appointment when reading from storage
We want to avoid reading an incoming data file of appointments twice - so we need to store some kind of reference to the original file the Appointment is from. In the near future we can then check whether an Appointment already exists from the file before saving it `create_appointments`
1 parent a3507be commit 5396167

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

manage_breast_screening/notifications/management/commands/create_appointments.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def handle(self, *args, **options):
5252
self.stdout.write(f"{clinic} created")
5353

5454
appt, appt_created = self.update_or_create_appointment(
55-
row, clinic
55+
row, clinic, blob.name
5656
)
5757
if appt_created:
5858
self.stdout.write(f"{appt} created")
@@ -93,10 +93,11 @@ def find_or_create_clinic(self, row: pandas.Series) -> tuple[Clinic, bool]:
9393
)
9494

9595
def update_or_create_appointment(
96-
self, row: pandas.Series, clinic: Clinic
96+
self, row: pandas.Series, clinic: Clinic, blob_name: str
9797
) -> tuple[Appointment, bool]:
9898
defaults = {
9999
"batch_id": row["BatchID"],
100+
"blob_name": blob_name,
100101
"number": row["Sequence"],
101102
"status": row["Status"],
102103
"episode_type": row["Episode Type"],

manage_breast_screening/notifications/tests/integration/test_create_appointments_from_azure_storage.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ 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}"
3032

31-
with open(
32-
helpers.get_test_file_path("ABC_20241202091221_APPT_106.dat")
33-
) as test_file:
34-
BlobStorage().add(
35-
f"{today_dirname}/ABC_20241202091221_APPT_106.dat", test_file.read()
36-
)
33+
with open(helpers.get_test_file_path(test_file_path)) as test_file:
34+
BlobStorage().add(blob_name, test_file.read())
3735

3836
Command().handle(**{"date_str": today_dirname})
3937

@@ -80,3 +78,7 @@ def test_appointments_created_from_file_stored_in_azure(self, helpers):
8078
assert appointments[0].clinic == clinics[0]
8179
assert appointments[1].clinic == clinics[1]
8280
assert appointments[2].clinic == clinics[1]
81+
82+
assert appointments[0].blob_name == blob_name
83+
assert appointments[1].blob_name == blob_name
84+
assert appointments[2].blob_name == blob_name

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def test_handle_creates_records(self):
9595
assert appointments[1].clinic == clinics[1]
9696
assert appointments[2].clinic == clinics[1]
9797

98+
assert appointments[0].blob_name == mock_blob.name.return_value
99+
assert appointments[1].blob_name == mock_blob.name.return_value
100+
assert appointments[2].blob_name == mock_blob.name.return_value
101+
98102
@pytest.mark.django_db
99103
def test_handles_holding_clinics(self):
100104
"""Test does not create appointments for valid NBSS data marked as a Holding Clinic"""

0 commit comments

Comments
 (0)