Skip to content

Commit

Permalink
Add tests for reingest form
Browse files Browse the repository at this point in the history
  • Loading branch information
replaceafill committed Aug 23, 2024
1 parent ef1ea78 commit a7d645c
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pathlib
import uuid
from io import StringIO
from unittest import mock
from urllib.parse import urlencode

import metsrw
Expand Down Expand Up @@ -508,3 +509,59 @@ def test_create_aic_creates_temporary_files(
for path in (d / "tmp" / "1e23e6e2-02d7-4b2d-a648-caffa3b489f3").iterdir():
temporary_files.add((path.name, path.read_text().strip()))
assert expected_file_contents == temporary_files


@mock.patch(
"elasticSearchFunctions.get_aip_data",
return_value={"_source": {"name": "My AIP", "filePath": "path"}},
)
@mock.patch("elasticSearchFunctions.get_client")
def test_view_aip_reingest_form_displays_processing_configurations_choices(
get_client,
get_aip_data,
amsetup,
admin_client,
):
response = admin_client.get(
reverse("archival_storage:view_aip", args=[uuid.uuid4()])
)
assert response.status_code == 200

assert (
'name="reingest-processing_config" value="default"' in response.content.decode()
)


@pytest.mark.parametrize(
"error,message", [(False, "success!"), (True, "error!")], ids=["success", "error"]
)
@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,
error,
message,
amsetup,
admin_client,
):
request_reingest.return_value = {"error": error, "message": message}
aip_uuid = str(uuid.uuid4())
reingest_type = "metadata"
processing_config = "default"

response = admin_client.post(
reverse("archival_storage:view_aip", args=[aip_uuid]),
{
"submit-reingest-form": "true",
"reingest-reingest_type": reingest_type,
"reingest-processing_config": processing_config,
},
follow=True,
)
assert response.status_code == 200

request_reingest.assert_called_once_with(aip_uuid, reingest_type, processing_config)
assert message in response.content.decode()

0 comments on commit a7d645c

Please sign in to comment.