From 3bdbab3f32448b386955334a7626cdd1ba46f215 Mon Sep 17 00:00:00 2001 From: jo Date: Fri, 13 Oct 2023 12:31:07 +0200 Subject: [PATCH] feat: add deprecation field to Iso --- hcloud/isos/domain.py | 20 +++++++++++++++++-- tests/unit/isos/test_domain.py | 36 ++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/hcloud/isos/domain.py b/hcloud/isos/domain.py index 1578be17..17676ecf 100644 --- a/hcloud/isos/domain.py +++ b/hcloud/isos/domain.py @@ -3,6 +3,7 @@ from dateutil.parser import isoparse from ..core import BaseDomain, DomainIdentityMixin +from ..deprecation import DeprecationInfo class Iso(BaseDomain, DomainIdentityMixin): @@ -19,10 +20,21 @@ class Iso(BaseDomain, DomainIdentityMixin): :param architecture: str, None CPU Architecture that the ISO is compatible with. None means that the compatibility is unknown. Choices: `x86`, `arm` :param deprecated: datetime, None - 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. + 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. + :param deprecation: :class:`DeprecationInfo `, None + Describes if, when & how the resources was deprecated. If this field is set to None the resource is not + deprecated. If it has a value, it is considered deprecated. """ - __slots__ = ("id", "name", "type", "architecture", "description", "deprecated") + __slots__ = ( + "id", + "name", + "type", + "architecture", + "description", + "deprecated", + "deprecation", + ) def __init__( self, @@ -32,6 +44,7 @@ def __init__( architecture: str | None = None, description: str | None = None, deprecated: str | None = None, + deprecation: dict | None = None, ): self.id = id self.name = name @@ -39,3 +52,6 @@ def __init__( self.architecture = architecture self.description = description self.deprecated = isoparse(deprecated) if deprecated else None + self.deprecation = ( + DeprecationInfo.from_dict(deprecation) if deprecation is not None else None + ) diff --git a/tests/unit/isos/test_domain.py b/tests/unit/isos/test_domain.py index 7ba847bb..0e32e50a 100644 --- a/tests/unit/isos/test_domain.py +++ b/tests/unit/isos/test_domain.py @@ -1,14 +1,38 @@ from __future__ import annotations -import datetime -from datetime import timezone +from datetime import datetime, timezone + +import pytest from hcloud.isos import Iso class TestIso: - def test_deprecated_is_datetime(self): - iso = Iso(id=1, deprecated="2016-01-30T23:50+00:00") - assert iso.deprecated == datetime.datetime( - 2016, 1, 30, 23, 50, tzinfo=timezone.utc + @pytest.fixture() + def deprecated_iso(self): + return Iso( + **{ + "id": 10433, + "name": "vyos-1.4-rolling-202111150317-amd64.iso", + "description": "VyOS 1.4 (amd64)", + "type": "public", + "deprecation": { + "announced": "2023-10-05T08:27:01Z", + "unavailable_after": "2023-11-05T08:27:01Z", + }, + "architecture": "x86", + "deprecated": "2023-11-05T08:27:01Z", + } + ) + + def test_deprecation(self, deprecated_iso: Iso): + assert deprecated_iso.deprecated == datetime( + 2023, 11, 5, 8, 27, 1, tzinfo=timezone.utc + ) + assert deprecated_iso.deprecation is not None + assert deprecated_iso.deprecation.announced == datetime( + 2023, 10, 5, 8, 27, 1, tzinfo=timezone.utc + ) + assert deprecated_iso.deprecation.unavailable_after == datetime( + 2023, 11, 5, 8, 27, 1, tzinfo=timezone.utc )