Skip to content

Commit

Permalink
Use choice widget for processing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
replaceafill committed Aug 23, 2024
1 parent a7d645c commit 74923be
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/dashboard/src/components/archival_storage/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#
# You should have received a copy of the GNU General Public License
# along with Archivematica. If not, see <http://www.gnu.org/licenses/>.
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 _
Expand Down Expand Up @@ -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"
Expand All @@ -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")}),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"}},
Expand All @@ -519,34 +539,50 @@ 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 '<select name="reingest-processing_config"' in content
assert (
'name="reingest-processing_config" value="default"' in response.content.decode()
" ".join(
[
'<option value="automated">automated</option>',
'<option value="custom">custom</option>',
'<option value="default" selected>default</option>',
]
)
in content
)


@pytest.mark.parametrize(
"error,message", [(False, "success!"), (True, "error!")], ids=["success", "error"]
)
@mock.patch("components.helpers.processing_config_path")
@mock.patch("storageService.request_reingest")
@mock.patch("elasticSearchFunctions.get_aip_data")
@mock.patch("elasticSearchFunctions.get_client")
def test_view_aip_reingest_form_submits_reingest(
get_client,
get_aip_data,
request_reingest,
processing_config_path,
error,
message,
amsetup,
admin_client,
processing_configurations_dir,
):
processing_config_path.return_value = str(processing_configurations_dir)
request_reingest.return_value = {"error": error, "message": message}
aip_uuid = str(uuid.uuid4())
reingest_type = "metadata"
Expand Down

0 comments on commit 74923be

Please sign in to comment.