Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add deprecation field to Iso #318

Merged
merged 1 commit into from
Oct 13, 2023
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
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
)