From d64d823caa3a864b9b0c57a819084d7d5750f53b Mon Sep 17 00:00:00 2001 From: Douglas Cerna Date: Fri, 26 Jan 2024 07:57:29 -0600 Subject: [PATCH] Use logger instead of temporary file in ingest view --- src/dashboard/src/components/ingest/urls.py | 1 + .../src/components/ingest/views_as.py | 16 ++++----- src/dashboard/tests/test_ingest.py | 35 +++++++++++++++++++ 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/dashboard/src/components/ingest/urls.py b/src/dashboard/src/components/ingest/urls.py index 187f3baafb..95ec61d23a 100644 --- a/src/dashboard/src/components/ingest/urls.py +++ b/src/dashboard/src/components/ingest/urls.py @@ -128,6 +128,7 @@ re_path( r"^(?P" + settings.UUID_REGEX + ")/upload/as/match/$", views_as.ingest_upload_as_match, + name="ingest_upload_as_match", ), re_path( r"^(?P" + settings.UUID_REGEX + ")/upload/as/reset/$", diff --git a/src/dashboard/src/components/ingest/views_as.py b/src/dashboard/src/components/ingest/views_as.py index 69998a3460..aeaadfc8d1 100644 --- a/src/dashboard/src/components/ingest/views_as.py +++ b/src/dashboard/src/components/ingest/views_as.py @@ -268,16 +268,12 @@ def ingest_upload_as_match(request, uuid): rows = models.ArchivesSpaceDIPObjectResourcePairing.objects.filter( dipuuid=uuid, resourceid=resource_id, fileuuid=file_uuid ) - with open("/tmp/delete.log", "a") as log: - print( - "Resource", - resource_id, - "File", - "file_uuid", - "matches", - rows.count(), - file=log, - ) + logger.debug( + "Resource %s File %s matches %d", + resource_id, + file_uuid, + rows.count(), + ) models.ArchivesSpaceDIPObjectResourcePairing.objects.filter( dipuuid=uuid, resourceid=resource_id, fileuuid=file_uuid ).delete() diff --git a/src/dashboard/tests/test_ingest.py b/src/dashboard/tests/test_ingest.py index 820897b5f3..c48f91f108 100644 --- a/src/dashboard/tests/test_ingest.py +++ b/src/dashboard/tests/test_ingest.py @@ -1,6 +1,7 @@ import json import os import pickle +import uuid from unittest import mock import pytest @@ -14,6 +15,7 @@ from django.test.client import Client from django.urls import reverse from main.models import Access +from main.models import ArchivesSpaceDIPObjectResourcePairing from main.models import DashboardSetting @@ -357,3 +359,36 @@ def test_adjust_directories_draggability(): # small turtles has some draggable children so it's draggable assert not small_turtles["not_draggable"] + + +@pytest.fixture +def dashboard_uuid(db): + helpers.set_setting("dashboard_uuid", str(uuid.uuid4())) + + +def test_ingest_upload_as_match_shows_deleted_rows( + admin_client, dashboard_uuid, caplog +): + dip_uuid = uuid.uuid4() + file_uuid = uuid.uuid4() + resource_id = "/repositories/2/archival_objects/1" + ArchivesSpaceDIPObjectResourcePairing.objects.create( + dipuuid=dip_uuid, + fileuuid=file_uuid, + resourceid=resource_id, + ) + ArchivesSpaceDIPObjectResourcePairing.objects.create( + dipuuid=dip_uuid, + fileuuid=file_uuid, + resourceid="/repositories/2/archival_objects/2", + ) + + response = admin_client.delete( + reverse("ingest:ingest_upload_as_match", kwargs={"uuid": dip_uuid}), + data=json.dumps({"resource_id": resource_id, "file_uuid": str(file_uuid)}), + content_type="application/json", + ) + assert response.status_code == 204 + + log_record = caplog.records[0] + assert log_record.message == f"Resource {resource_id} File {file_uuid} matches 1"