Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions aiohasupervisor/models/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime # noqa: TCH003
from datetime import datetime # noqa: TC003

Check failure on line 6 in aiohasupervisor/models/jobs.py

View workflow job for this annotation

GitHub Actions / Check ruff Python 3.12

Ruff (TCH003)

aiohasupervisor/models/jobs.py:6:22: TCH003 Move standard library import `datetime.datetime` into a type-checking block

Check failure on line 6 in aiohasupervisor/models/jobs.py

View workflow job for this annotation

GitHub Actions / Check ruff Python 3.13

Ruff (TCH003)

aiohasupervisor/models/jobs.py:6:22: TCH003 Move standard library import `datetime.datetime` into a type-checking block
from enum import StrEnum
from uuid import UUID # noqa: TCH003
from uuid import UUID # noqa: TC003

Check failure on line 8 in aiohasupervisor/models/jobs.py

View workflow job for this annotation

GitHub Actions / Check ruff Python 3.12

Ruff (TCH003)

aiohasupervisor/models/jobs.py:8:18: TCH003 Move standard library import `uuid.UUID` into a type-checking block

Check failure on line 8 in aiohasupervisor/models/jobs.py

View workflow job for this annotation

GitHub Actions / Check ruff Python 3.13

Ruff (TCH003)

aiohasupervisor/models/jobs.py:8:18: TCH003 Move standard library import `uuid.UUID` into a type-checking block

from .base import Request, ResponseData

Expand Down Expand Up @@ -45,6 +45,7 @@

type: str
message: str
stage: str | None = None


@dataclass(slots=True, frozen=True)
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/jobs_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"errors": [
{
"type": "BackupInvalidError",
"message": "Invalid password for backup cfddca18"
"message": "Invalid password for backup cfddca18",
"stage": "restore_backup"
}
],
"created": "2025-01-30T20:55:15.000000+00:00",
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/jobs_info_no_stage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"result": "ok",
"data": {
"ignore_conditions": ["free_space"],
"jobs": [
{
"name": "test_job_error_no_stage",
"reference": "test123",
"uuid": "3febe59311f94d6ba36f6f9f73357ca9",
"progress": 0,
"stage": null,
"done": true,
"errors": [
{
"type": "TestError",
"message": "Test error without stage field"
}
],
"created": "2025-01-30T20:55:12.859349+00:00",
"child_jobs": []
}
]
}
}
20 changes: 20 additions & 0 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def test_jobs_info(
assert info.jobs[1].reference == "cfddca18"
assert info.jobs[1].errors[0].type == "BackupInvalidError"
assert info.jobs[1].errors[0].message == "Invalid password for backup cfddca18"
assert info.jobs[1].errors[0].stage == "restore_backup"


async def test_jobs_set_options(
Expand Down Expand Up @@ -112,3 +113,22 @@ async def test_jobs_delete_job(
assert responses.requests.keys() == {
("DELETE", URL(f"{SUPERVISOR_URL}/jobs/2febe59311f94d6ba36f6f9f73357ca8"))
}


async def test_jobs_info_backward_compatibility_no_stage(
responses: aioresponses, supervisor_client: SupervisorClient
) -> None:
"""Test jobs info API with error lacking stage field for backward compatibility."""
responses.get(
f"{SUPERVISOR_URL}/jobs/info",
status=200,
body=load_fixture("jobs_info_no_stage.json"),
)
info = await supervisor_client.jobs.info()
assert info.ignore_conditions == [JobCondition.FREE_SPACE]

assert info.jobs[0].name == "test_job_error_no_stage"
assert info.jobs[0].reference == "test123"
assert info.jobs[0].errors[0].type == "TestError"
assert info.jobs[0].errors[0].message == "Test error without stage field"
assert info.jobs[0].errors[0].stage is None
Loading