Skip to content

Commit b34ae76

Browse files
committed
Support detailed tasks in the get_jobs method
This adds support for the detailed parameter introduced in the Jobs API endpoint in Archivematica 1.16.0.
1 parent 784cbab commit b34ae76

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

amclient/amclient.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ def get_jobs(self):
626626
value = getattr(self, f"job_{attribute}", None)
627627
if value is not None:
628628
params[attribute] = value
629+
if hasattr(self, "detailed"):
630+
params["detailed"] = self.detailed
629631
return utils._call_url_json(
630632
url, headers=self._am_auth_headers(), params=params, method=utils.METHOD_GET
631633
)

tests/test_amclient.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,55 @@ def test_get_jobs(call_url: mock.Mock):
27632763
]
27642764

27652765

2766+
@pytest.mark.parametrize(
2767+
"set_detailed_param", [(True,), (False)], ids=["detailed_set", "detailed_not_set"]
2768+
)
2769+
@mock.patch("amclient.utils._call_url")
2770+
def test_get_jobs_returns_detailed_tasks(call_url: mock.Mock, set_detailed_param: bool):
2771+
unit_uuid = str(uuid.uuid4())
2772+
expected_tasks = [
2773+
{
2774+
"uuid": str(uuid.uuid4()),
2775+
"exit_code": 0,
2776+
"file_uuid": str(uuid.uuid4()),
2777+
"file_name": "file.pdf",
2778+
"time_created": "2025-02-13 12:00:00",
2779+
"time_started": "2025-02-13 12:00:00",
2780+
"time_ended": "2025-02-13 12:00:10",
2781+
"duration": 10,
2782+
}
2783+
]
2784+
call_url.side_effect = [[{"tasks": expected_tasks}]]
2785+
client = amclient.AMClient(
2786+
am_api_key=AM_API_KEY,
2787+
am_user_name=AM_USER_NAME,
2788+
am_url=AM_URL,
2789+
unit_uuid=unit_uuid,
2790+
)
2791+
expected_params = {}
2792+
if set_detailed_param:
2793+
# Demonstrates that any value can be used, as the API endpoint only
2794+
# checks for the presence of the attribute in the request.
2795+
client.detailed = object()
2796+
expected_params["detailed"] = client.detailed
2797+
2798+
response = client.get_jobs()
2799+
2800+
assert len(response) == 1
2801+
assert response[0]["tasks"] == expected_tasks
2802+
2803+
# Since this test mocks the API endpoint interaction, this assertion
2804+
# serves as the real test verifying whether the 'detailed' parameter has
2805+
# been correctly set.
2806+
call_url.assert_called_once_with(
2807+
f"{AM_URL}/api/v2beta/jobs/{unit_uuid}",
2808+
method="GET",
2809+
params=expected_params,
2810+
headers={"Authorization": f"ApiKey {AM_USER_NAME}:{AM_API_KEY}"},
2811+
assume_json=True,
2812+
)
2813+
2814+
27662815
@mock.patch("requests.request")
27672816
def test_get_status(mock_request: mock.Mock):
27682817
transfer_uuid = "ca480d94-892c-4d99-bbb1-290698406571"

0 commit comments

Comments
 (0)