From 74923bec99b222899520a58d250497ed8a494a7c Mon Sep 17 00:00:00 2001 From: "Douglas Cerna (Soy Douglas)" Date: Fri, 23 Aug 2024 14:52:14 +0000 Subject: [PATCH] Use choice widget for processing configuration --- .../src/components/archival_storage/forms.py | 20 +++++++++- .../archival_storage/test_archival_storage.py | 40 ++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/dashboard/src/components/archival_storage/forms.py b/src/dashboard/src/components/archival_storage/forms.py index abb9c69f2e..baeb8111cd 100644 --- a/src/dashboard/src/components/archival_storage/forms.py +++ b/src/dashboard/src/components/archival_storage/forms.py @@ -14,7 +14,10 @@ # # You should have received a copy of the GNU General Public License # along with Archivematica. If not, see . +import pathlib + from agentarchives.atom.client import CommunicationError +from components import helpers from components.archival_storage.atom import get_atom_client from django import forms from django.utils.translation import gettext as _ @@ -59,6 +62,19 @@ def clean_slug(self): return slug +def get_processing_configurations(): + processing_configs_dir = pathlib.Path(helpers.processing_config_path()) + suffix = "ProcessingMCP.xml" + return ( + (processing_config, processing_config) + for processing_config in sorted( + path.name[: -len(suffix)] + for path in processing_configs_dir.iterdir() + if path.name.endswith(suffix) + ) + ) + + class ReingestAIPForm(forms.Form): METADATA_ONLY = "metadata" OBJECTS = "objects" @@ -71,10 +87,10 @@ class ReingestAIPForm(forms.Form): reingest_type = forms.ChoiceField( choices=REINGEST_CHOICES, widget=forms.RadioSelect, required=True ) - processing_config = forms.CharField( + processing_config = forms.ChoiceField( + choices=get_processing_configurations, required=False, initial="default", - widget=forms.TextInput(attrs={"placeholder": _("default")}), ) diff --git a/tests/dashboard/components/archival_storage/test_archival_storage.py b/tests/dashboard/components/archival_storage/test_archival_storage.py index 2614c70413..456d3c9145 100644 --- a/tests/dashboard/components/archival_storage/test_archival_storage.py +++ b/tests/dashboard/components/archival_storage/test_archival_storage.py @@ -366,9 +366,16 @@ def test_load_datatable_state_404(self): assert payload["message"] == "Setting not found" +@mock.patch("components.helpers.processing_config_path") def test_view_aip_metadata_only_dip_upload_with_missing_description_slug( - mocker, amsetup, admin_client, tmpdir + processing_config_path, + mocker, + amsetup, + admin_client, + tmpdir, + processing_configurations_dir, ): + processing_config_path.return_value = str(processing_configurations_dir) sip_uuid = uuid.uuid4() file_path = tmpdir.mkdir("file") mocker.patch("elasticSearchFunctions.get_client") @@ -511,6 +518,19 @@ def test_create_aic_creates_temporary_files( assert expected_file_contents == temporary_files +@pytest.fixture +def processing_configurations_dir(tmp_path): + result = tmp_path / "sharedMicroServiceTasksConfigs" / "processingMCPConfigs" + result.mkdir(parents=True) + + (result / "defaultProcessingMCP.xml").touch() + (result / "automatedProcessingMCP.xml").touch() + (result / "customProcessingMCP.xml").touch() + + return result + + +@mock.patch("components.helpers.processing_config_path") @mock.patch( "elasticSearchFunctions.get_aip_data", return_value={"_source": {"name": "My AIP", "filePath": "path"}}, @@ -519,22 +539,35 @@ def test_create_aic_creates_temporary_files( def test_view_aip_reingest_form_displays_processing_configurations_choices( get_client, get_aip_data, + processing_config_path, amsetup, admin_client, + processing_configurations_dir, ): + processing_config_path.return_value = str(processing_configurations_dir) response = admin_client.get( reverse("archival_storage:view_aip", args=[uuid.uuid4()]) ) assert response.status_code == 200 + content = response.content.decode().replace("\n", "") + assert '