Skip to content

Commit

Permalink
feat: prepare for iso deprecated field removal
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed Oct 20, 2023
1 parent f1627d4 commit f71b482
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
17 changes: 13 additions & 4 deletions hcloud/isos/domain.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from dateutil.parser import isoparse
from datetime import datetime
from warnings import warn

from ..core import BaseDomain, DomainIdentityMixin
from ..deprecation import DeprecationInfo
Expand Down Expand Up @@ -32,7 +33,6 @@ class Iso(BaseDomain, DomainIdentityMixin):
"type",
"architecture",
"description",
"deprecated",
"deprecation",
)

Expand All @@ -43,15 +43,24 @@ def __init__(
type: str | None = None,
architecture: str | None = None,
description: str | None = None,
deprecated: str | None = None,
deprecated: str | None = None, # pylint: disable=unused-argument
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
)

@property
def deprecated(self) -> datetime | None:
warn(
"The `deprecated` field is deprecated, please use the `deprecation` field instead.",
DeprecationWarning,
)
if self.deprecation is None:
return None
return self.deprecation.unavailable_after
14 changes: 13 additions & 1 deletion tests/unit/isos/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def iso_response():
"type": "public",
"architecture": "x86",
"deprecated": "2018-02-28T00:00:00+00:00",
"deprecation": {
"announced": "2018-01-28T00:00:00+00:00",
"unavailable_after": "2018-02-28T00:00:00+00:00",
},
}
}

Expand All @@ -28,14 +32,18 @@ def two_isos_response():
"type": "public",
"architecture": "x86",
"deprecated": "2018-02-28T00:00:00+00:00",
"deprecation": {
"announced": "2018-01-28T00:00:00+00:00",
"unavailable_after": "2018-02-28T00:00:00+00:00",
},
},
{
"id": 4712,
"name": "FreeBSD-11.0-RELEASE-amd64-dvd1",
"description": "FreeBSD 11.0 x64",
"type": "public",
"architecture": "x86",
"deprecated": "2018-02-28T00:00:00+00:00",
"deprecated": None,
},
]
}
Expand All @@ -52,6 +60,10 @@ def one_isos_response():
"type": "public",
"architecture": "x86",
"deprecated": "2018-02-28T00:00:00+00:00",
"deprecation": {
"announced": "2018-01-28T00:00:00+00:00",
"unavailable_after": "2018-02-28T00:00:00+00:00",
},
}
]
}
9 changes: 8 additions & 1 deletion tests/unit/isos/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ def test_bound_iso_init(self, iso_response):
assert bound_iso.description == "FreeBSD 11.0 x64"
assert bound_iso.type == "public"
assert bound_iso.architecture == "x86"
assert bound_iso.deprecated == datetime.datetime(
with pytest.deprecated_call():
assert bound_iso.deprecated == datetime.datetime(
2018, 2, 28, 0, 0, tzinfo=timezone.utc
)
assert bound_iso.deprecation.announced == datetime.datetime(
2018, 1, 28, 0, 0, tzinfo=timezone.utc
)
assert bound_iso.deprecation.unavailable_after == datetime.datetime(
2018, 2, 28, 0, 0, tzinfo=timezone.utc
)

Expand Down
7 changes: 4 additions & 3 deletions tests/unit/isos/test_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def deprecated_iso(self):
)

def test_deprecation(self, deprecated_iso: Iso):
assert deprecated_iso.deprecated == datetime(
2023, 11, 5, 8, 27, 1, tzinfo=timezone.utc
)
with pytest.deprecated_call():
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
Expand Down

0 comments on commit f71b482

Please sign in to comment.