Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for JHOVE module validation #216

Merged
merged 9 commits into from
Feb 26, 2025
45 changes: 45 additions & 0 deletions features/black_box/validation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@black-box
Feature: Alma wants to ensure that JHOVE validation in Archivematica works correctly when files are validated, and that transfers fail when they contain unvalidated files.

Scenario: Validation for a transfer fail
Given a "standard" transfer type located in "SampleTransfers/JHOVEModulesValidation"
When the transfer compliance is verified
Then the "Identify file format" microservice completes successfully
And the "Validate formats" job fails
And 17 "Validate formats" transfer tasks were executed
And 8 "Validate formats" transfer tasks failed
And 9 "Validate formats" transfer tasks succeeded


Scenario Outline: JHOVE Validation for a transfer files
Given a "standard" transfer type located in "<sample_transfer_path>"
When the transfer compliance is verified
Then the "Identify file format" microservice completes successfully
And the "Validation" microservice is executed
And 1 AIFF file is failed
And 1 AIFF file is succeeded
And 1 GIF file is failed
And 1 GIF file is succeeded
And 1 JP2 file is failed
And 1 JP2 file is succeeded
And 1 JPG file is failed
And 1 JPG file is succeeded
And 1 PDF file is failed
And 1 PDF file is succeeded
And 1 TIFF file is failed
And 1 TIFF file is succeeded
And 1 WARC file is failed
And 1 WARC file is succeeded
And 1 WAVE file is failed
And 1 WAVE file is succeeded
And the AIP can be successfully stored
And there are <validated_objects_count> original objects in the AIP METS with a validation event


Examples: sample transfers
| sample_transfer_path | validated_objects_count |
| SampleTransfers/JHOVEModulesValidation | 16 |




75 changes: 75 additions & 0 deletions features/steps/black_box_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,3 +1527,78 @@ def step(context):
raise AssertionError(error)
else:
assert uses_order_indexes == sorted(uses_order_indexes), error


def get_uuid_value(context, unit_type):
return (
context.current_transfer["transfer_uuid"]
if unit_type == "transfer"
else context.current_transfer["sip_uuid"]
)


@then('{task_count:d} "{job_name}" {unit_type} tasks were executed')
def step_impl(context, task_count, job_name, unit_type):
unit_uuid = get_uuid_value(context, unit_type)
jobs = utils.get_jobs(context.api_clients_config, unit_uuid, job_name=job_name)
assert len(jobs), f"No jobs found for unit {unit_uuid}"
assert len(jobs[0]["tasks"]) == task_count


@then('{task_count:d} "{job_name}" {unit_type} tasks failed')
def step_impl(context, job_name, task_count, unit_type):
unit_uuid = get_uuid_value(context, unit_type)
jobs = utils.get_jobs(context.api_clients_config, unit_uuid, job_name=job_name)
assert len(jobs), f"No jobs found for unit {unit_uuid}"

fail_task = 0
for job in jobs:
for task in job["tasks"]:
if task["exit_code"] == 1:
fail_task += 1
assert fail_task == task_count


@then('{task_count:d} "{job_name}" {unit_type} tasks succeeded')
def step_impl(context, job_name, task_count, unit_type):
unit_uuid = get_uuid_value(context, unit_type)
jobs = utils.get_jobs(context.api_clients_config, unit_uuid, job_name=job_name)
assert len(jobs), f"No jobs found for unit {unit_uuid}"

success_task = 0
for job in jobs:
for task in job["tasks"]:
if task["exit_code"] == 0:
success_task += 1
assert success_task == task_count


@then("{file_count:d} {file_extension} file is {status}")
def step_impl(context, file_count, file_extension, status):
unit_uuid = context.current_transfer["transfer_uuid"] + "/?detailed=1"
jobs = utils.get_jobs(
context.api_clients_config, unit_uuid, job_microservice="Validation"
)
assert len(jobs), f"No jobs found for unit {unit_uuid}"

success_file = 0
fail_file = 0

for job in jobs:
for task in job["tasks"]:
if status == "failed":
if (file_extension).lower() == task["file_name"].split(".")[
-1
] and task["exit_code"] == 1:
fail_file += 1
assert file_count == fail_file
else:
continue
if status == "succeeded":
if (file_extension).lower() == task["file_name"].split(".")[
-1
] and task["exit_code"] == 0:
success_file += 1
assert file_count == success_file
else:
continue