Skip to content

Commit 036b52f

Browse files
authored
1 parent d248bbd commit 036b52f

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

hcloud/isos/domain.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from dateutil.parser import isoparse
44

55
from ..core import BaseDomain, DomainIdentityMixin
6+
from ..deprecation import DeprecationInfo
67

78

89
class Iso(BaseDomain, DomainIdentityMixin):
@@ -19,10 +20,21 @@ class Iso(BaseDomain, DomainIdentityMixin):
1920
:param architecture: str, None
2021
CPU Architecture that the ISO is compatible with. None means that the compatibility is unknown. Choices: `x86`, `arm`
2122
:param deprecated: datetime, None
22-
ISO 8601 timestamp of deprecation, None if ISO is still available. After the deprecation time it will no longer be possible to attach the ISO to servers.
23+
ISO 8601 timestamp of deprecation, None if ISO is still available. After the deprecation time it will no longer be possible to attach the ISO to servers. This field is deprecated. Use `deprecation` instead.
24+
:param deprecation: :class:`DeprecationInfo <hcloud.deprecation.domain.DeprecationInfo>`, None
25+
Describes if, when & how the resources was deprecated. If this field is set to None the resource is not
26+
deprecated. If it has a value, it is considered deprecated.
2327
"""
2428

25-
__slots__ = ("id", "name", "type", "architecture", "description", "deprecated")
29+
__slots__ = (
30+
"id",
31+
"name",
32+
"type",
33+
"architecture",
34+
"description",
35+
"deprecated",
36+
"deprecation",
37+
)
2638

2739
def __init__(
2840
self,
@@ -32,10 +44,14 @@ def __init__(
3244
architecture: str | None = None,
3345
description: str | None = None,
3446
deprecated: str | None = None,
47+
deprecation: dict | None = None,
3548
):
3649
self.id = id
3750
self.name = name
3851
self.type = type
3952
self.architecture = architecture
4053
self.description = description
4154
self.deprecated = isoparse(deprecated) if deprecated else None
55+
self.deprecation = (
56+
DeprecationInfo.from_dict(deprecation) if deprecation is not None else None
57+
)

tests/unit/isos/test_domain.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
from __future__ import annotations
22

3-
import datetime
4-
from datetime import timezone
3+
from datetime import datetime, timezone
4+
5+
import pytest
56

67
from hcloud.isos import Iso
78

89

910
class TestIso:
10-
def test_deprecated_is_datetime(self):
11-
iso = Iso(id=1, deprecated="2016-01-30T23:50+00:00")
12-
assert iso.deprecated == datetime.datetime(
13-
2016, 1, 30, 23, 50, tzinfo=timezone.utc
11+
@pytest.fixture()
12+
def deprecated_iso(self):
13+
return Iso(
14+
**{
15+
"id": 10433,
16+
"name": "vyos-1.4-rolling-202111150317-amd64.iso",
17+
"description": "VyOS 1.4 (amd64)",
18+
"type": "public",
19+
"deprecation": {
20+
"announced": "2023-10-05T08:27:01Z",
21+
"unavailable_after": "2023-11-05T08:27:01Z",
22+
},
23+
"architecture": "x86",
24+
"deprecated": "2023-11-05T08:27:01Z",
25+
}
26+
)
27+
28+
def test_deprecation(self, deprecated_iso: Iso):
29+
assert deprecated_iso.deprecated == datetime(
30+
2023, 11, 5, 8, 27, 1, tzinfo=timezone.utc
31+
)
32+
assert deprecated_iso.deprecation is not None
33+
assert deprecated_iso.deprecation.announced == datetime(
34+
2023, 10, 5, 8, 27, 1, tzinfo=timezone.utc
35+
)
36+
assert deprecated_iso.deprecation.unavailable_after == datetime(
37+
2023, 11, 5, 8, 27, 1, tzinfo=timezone.utc
1438
)

0 commit comments

Comments
 (0)