Skip to content

Commit

Permalink
Use logger instead of temporary file in ingest view
Browse files Browse the repository at this point in the history
  • Loading branch information
replaceafill authored Jan 26, 2024
1 parent 5c64ba1 commit d64d823
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/dashboard/src/components/ingest/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
re_path(
r"^(?P<uuid>" + settings.UUID_REGEX + ")/upload/as/match/$",
views_as.ingest_upload_as_match,
name="ingest_upload_as_match",
),
re_path(
r"^(?P<uuid>" + settings.UUID_REGEX + ")/upload/as/reset/$",
Expand Down
16 changes: 6 additions & 10 deletions src/dashboard/src/components/ingest/views_as.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions src/dashboard/tests/test_ingest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import pickle
import uuid
from unittest import mock

import pytest
Expand All @@ -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


Expand Down Expand Up @@ -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"

0 comments on commit d64d823

Please sign in to comment.