Skip to content

Commit c3b0e64

Browse files
authored
Merge pull request #788 from NHSDigital/check-for-existing-extract-when-creating-appointments
Skip files which have a matching Extract record
2 parents 5671495 + e679290 commit c3b0e64

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

manage_breast_screening/notifications/management/commands/create_appointments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def handle(self, *args, **options):
4646
for blob in container_client.list_blobs(
4747
name_starts_with=options["date_str"]
4848
):
49+
if Extract.objects.filter(filename=blob.name).exists():
50+
continue
51+
4952
blob_client = container_client.get_blob_client(blob.name)
5053
logger.debug("Processing blob %s", blob.name)
5154
blob_content = blob_client.download_blob(

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,22 +355,22 @@ def test_create_extract_and_cancel(self):
355355

356356
assert appointment_to_update.extracts.count() == 2
357357

358-
@pytest.mark.django_db(transaction=True)
359-
def test_errors_when_same_extract(self):
358+
@pytest.mark.django_db
359+
def test_skip_file_matching_extract(self):
360+
"""Test appointment creation where the file has been processed"""
360361
today_dirname = datetime.now().strftime("%Y-%m-%d")
362+
filename = f"{today_dirname}/{VALID_DATA_FILE}"
361363

362-
with stored_blob_data(today_dirname, [VALID_DATA_FILE]):
363-
Command().handle(**{"date_str": today_dirname})
364-
365-
assert Extract.objects.count() == 1
366-
assert Appointment.objects.count() == 2
364+
Extract.objects.create(
365+
sequence_number=13, filename=filename, bso_code="ABC", record_count=0
366+
)
367367

368368
with stored_blob_data(today_dirname, [VALID_DATA_FILE]):
369-
with pytest.raises(CommandError):
370-
Command().handle(**{"date_str": today_dirname})
369+
Command().handle(**{"date_str": today_dirname})
371370

372371
assert Extract.objects.count() == 1
373-
assert Appointment.objects.count() == 2
372+
assert Extract.objects.first().appointments.count() == 0
373+
assert Appointment.objects.count() == 0
374374

375375
@pytest.mark.django_db(transaction=True)
376376
def test_errors_with_wrong_format_filename(self):

0 commit comments

Comments
 (0)