Skip to content

Commit

Permalink
feat: add deprecation field to Iso (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola authored Oct 13, 2023
1 parent d248bbd commit 036b52f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
20 changes: 18 additions & 2 deletions hcloud/isos/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dateutil.parser import isoparse

from ..core import BaseDomain, DomainIdentityMixin
from ..deprecation import DeprecationInfo


class Iso(BaseDomain, DomainIdentityMixin):
Expand All @@ -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 <hcloud.deprecation.domain.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,
Expand All @@ -32,10 +44,14 @@ def __init__(
architecture: str | None = None,
description: str | None = None,
deprecated: str | None = None,
deprecation: dict | None = None,
):
self.id = id
self.name = name
self.type = type
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
)
36 changes: 30 additions & 6 deletions tests/unit/isos/test_domain.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 036b52f

Please sign in to comment.