diff --git a/src/dashboard/src/components/api/views.py b/src/dashboard/src/components/api/views.py index d03ff14ab1..c4c871ae02 100644 --- a/src/dashboard/src/components/api/views.py +++ b/src/dashboard/src/components/api/views.py @@ -680,7 +680,7 @@ def get_levels_of_description(request): each level of description. """ levels = models.LevelOfDescription.objects.all().order_by("sortorder") - response = [{level.id: level.name} for level in levels] + response = [{str(level.id): level.name} for level in levels] return helpers.json_response(response) diff --git a/src/dashboard/src/components/ingest/urls.py b/src/dashboard/src/components/ingest/urls.py index 77d8c8f864..187f3baafb 100644 --- a/src/dashboard/src/components/ingest/urls.py +++ b/src/dashboard/src/components/ingest/urls.py @@ -60,7 +60,11 @@ name="ingest_metadata_add_files", ), path("upload/url/check/", views.ingest_upload_destination_url_check), - re_path(r"^(?P" + settings.UUID_REGEX + ")/upload/$", views.ingest_upload), + re_path( + r"^(?P" + settings.UUID_REGEX + ")/upload/$", + views.ingest_upload, + name="ingest_upload", + ), path("status/", views.ingest_status), re_path(r"^status/(?P" + settings.UUID_REGEX + ")/$", views.ingest_status), re_path( diff --git a/src/dashboard/src/components/ingest/views.py b/src/dashboard/src/components/ingest/views.py index 296b8b3823..ffe2592dfe 100644 --- a/src/dashboard/src/components/ingest/views.py +++ b/src/dashboard/src/components/ingest/views.py @@ -324,14 +324,16 @@ def ingest_upload(request, uuid): access = models.Access.objects.get(sipuuid=uuid) except: access = models.Access(sipuuid=uuid) - access.target = pickle.dumps({"target": request.POST["target"]}, protocol=0) + access.target = pickle.dumps( + {"target": request.POST["target"]}, protocol=0 + ).decode() access.save() response = {"ready": True} return helpers.json_response(response) elif request.method == "GET": try: access = models.Access.objects.get(sipuuid=uuid) - data = pickle.loads(str(access.target)) + data = pickle.loads(access.target.encode()) except: raise Http404 return helpers.json_response(data) diff --git a/src/dashboard/tests/test_api.py b/src/dashboard/tests/test_api.py index 38403b6f80..2825ec535f 100644 --- a/src/dashboard/tests/test_api.py +++ b/src/dashboard/tests/test_api.py @@ -15,6 +15,7 @@ from django.utils.timezone import make_aware from lxml import etree from main.models import Job +from main.models import LevelOfDescription from main.models import SIP from main.models import Task from main.models import Transfer @@ -467,6 +468,23 @@ def test_task(self): assert payload["time_ended"] == "2019-06-18T00:00:05" assert payload["duration"] == 5 + @e2e + def test_get_levels_of_description(self): + LevelOfDescription.objects.create(name="Item", sortorder=2) + LevelOfDescription.objects.create(name="Collection", sortorder=0) + LevelOfDescription.objects.create(name="Fonds", sortorder=1) + expected = ["Collection", "Fonds", "Item"] + + resp = self.client.get(reverse("api:get_levels_of_description")) + payload = json.loads(resp.content.decode("utf8")) + + result = [] + for level_of_description in payload: + name = next(iter(level_of_description.values())) + result.append(name) + + assert result == expected + class TestProcessingConfigurationAPI(TestCase): fixtures = ["test_user"] diff --git a/src/dashboard/tests/test_ingest.py b/src/dashboard/tests/test_ingest.py index b1b3a76cb6..820897b5f3 100644 --- a/src/dashboard/tests/test_ingest.py +++ b/src/dashboard/tests/test_ingest.py @@ -1,4 +1,6 @@ +import json import os +import pickle from unittest import mock import pytest @@ -11,6 +13,7 @@ from django.test import TestCase from django.test.client import Client from django.urls import reverse +from main.models import Access from main.models import DashboardSetting @@ -77,6 +80,40 @@ def test_add_metadata_files_view(self): ) assert title in response.content.decode("utf8") + def test_ingest_upload_get(self): + sip_uuid = "4060ee97-9c3f-4822-afaf-ebdf838284c3" + access_target = {"target": "description-slug"} + Access.objects.create( + sipuuid=sip_uuid, + target=pickle.dumps(access_target, protocol=0).decode(), + ) + + response = self.client.get( + reverse("ingest:ingest_upload", args=[sip_uuid]), + ) + + assert response.status_code == 200 + assert json.loads(response.content) == access_target + + def test_ingest_upload_post(self): + sip_uuid = "4060ee97-9c3f-4822-afaf-ebdf838284c3" + access_target = {"target": "description-slug"} + + # Check there is no Access object associated with the SIP yet. + assert Access.objects.filter(sipuuid=sip_uuid).count() == 0 + + response = self.client.post( + reverse("ingest:ingest_upload", args=[sip_uuid]), + data=access_target, + ) + assert response.status_code == 200 + assert json.loads(response.content) == {"ready": True} + + # An Access object was created for the SIP with the right target. + assert Access.objects.filter(sipuuid=sip_uuid).count() == 1 + access = Access.objects.get(sipuuid=sip_uuid) + assert pickle.loads(access.target.encode()) == access_target + def _assert_file_node_properties_match_record(file_node, record): assert file_node["type"] == "file"