Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aiohasupervisor/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass
from datetime import datetime # noqa: TCH003
from enum import StrEnum
from typing import Any
from uuid import UUID # noqa: TCH003

from .base import Request, ResponseData
Expand Down Expand Up @@ -61,6 +62,7 @@ class Job(ResponseData):
errors: list[JobError]
created: datetime
child_jobs: list[Job]
extra: dict[str, Any] | None


@dataclass(slots=True, frozen=True)
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/jobs_get_job.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"done": true,
"errors": [],
"created": "2025-01-30T20:55:12.859349+00:00",
"extra": null,
"child_jobs": [
{
"name": "backup_store_folders",
Expand All @@ -19,6 +20,7 @@
"done": true,
"errors": [],
"created": "2025-01-30T20:55:12.892008+00:00",
"extra": null,
"child_jobs": [
{
"name": "backup_folder_save",
Expand All @@ -29,6 +31,7 @@
"done": true,
"errors": [],
"created": "2025-01-30T20:55:12.892699+00:00",
"extra": null,
"child_jobs": []
}
]
Expand Down
31 changes: 31 additions & 0 deletions tests/fixtures/jobs_get_job_extra.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"result": "ok",
"data": {
"name": "docker_interface_install",
"reference": "homeassistant",
"uuid": "2febe59311f94d6ba36f6f9f73357ca8",
"progress": 0,
"stage": null,
"done": false,
"errors": [],
"created": "2025-01-30T20:55:12.859349+00:00",
"extra": null,
"child_jobs": [
{
"name": "Pulling container image layer",
"reference": "1e214cd6d7d0",
"uuid": "f4bac7d9240f434a9f6a21aff7f7ade3",
"progress": 26.1,
"stage": "Downloading",
"done": false,
"errors": [],
"created": "2025-01-30T20:55:12.892008+00:00",
"extra": {
"current": 227726144,
"total": 436480882
},
"child_jobs": []
}
]
}
}
4 changes: 4 additions & 0 deletions tests/fixtures/jobs_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"done": true,
"errors": [],
"created": "2025-01-30T20:55:12.859349+00:00",
"extra": null,
"child_jobs": [
{
"name": "backup_store_folders",
Expand All @@ -22,6 +23,7 @@
"done": true,
"errors": [],
"created": "2025-01-30T20:55:12.892008+00:00",
"extra": null,
"child_jobs": [
{
"name": "backup_folder_save",
Expand All @@ -32,6 +34,7 @@
"done": true,
"errors": [],
"created": "2025-01-30T20:55:12.892699+00:00",
"extra": null,
"child_jobs": []
}
]
Expand All @@ -53,6 +56,7 @@
}
],
"created": "2025-01-30T20:55:15.000000+00:00",
"extra": null,
"child_jobs": []
}
]
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/jobs_info_no_stage.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}
],
"created": "2025-01-30T20:55:12.859349+00:00",
"extra": null,
"child_jobs": []
}
]
Expand Down
22 changes: 22 additions & 0 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,28 @@ async def test_jobs_get_job(
assert info.child_jobs[0].child_jobs[0].child_jobs == []


async def test_jobs_get_job_extra(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test jobs get job API with extra metadata."""
responses.get(
f"{SUPERVISOR_URL}/jobs/2febe59311f94d6ba36f6f9f73357ca8",
status=200,
body=load_fixture("jobs_get_job_extra.json"),
)
info = await supervisor_client.jobs.get_job(
UUID("2febe59311f94d6ba36f6f9f73357ca8")
)

assert info.name == "docker_interface_install"
assert info.reference == "homeassistant"
assert info.child_jobs[0].name == "Pulling container image layer"
assert info.child_jobs[0].reference == "1e214cd6d7d0"
assert info.child_jobs[0].progress == 26.1
assert info.child_jobs[0].stage == "Downloading"
assert info.child_jobs[0].extra == {"current": 227726144, "total": 436480882}


async def test_jobs_delete_job(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
Expand Down
Loading