Skip to content

Commit

Permalink
feat: add deprecation field to ServerType (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
apricote committed Jun 19, 2023
1 parent 58714d1 commit 4a0fce7
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/api.deprecation.rst
@@ -0,0 +1,5 @@
Deprecation Info
==================

.. autoclass:: hcloud.deprecation.domain.DeprecationInfo
:members:
9 changes: 9 additions & 0 deletions docs/api.rst
Expand Up @@ -27,3 +27,12 @@ Exceptions

.. autoclass:: hcloud.actions.domain.ActionTimeoutException
:members:

Other
-------------

.. toctree::
:maxdepth: 3

api.helpers
api.deprecation
Empty file added hcloud/deprecation/__init__.py
Empty file.
31 changes: 31 additions & 0 deletions hcloud/deprecation/domain.py
@@ -0,0 +1,31 @@
from dateutil.parser import isoparse

from hcloud.core.domain import BaseDomain


class DeprecationInfo(BaseDomain):
"""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.
:param announced: datetime
Date of when the deprecation was announced.
:param unavailable_after: datetime
After the time in this field, the resource will not be available from the general listing endpoint of the
resource type, and it can not be used in new resources. For example, if this is an image, you can not create
new servers with this image after the mentioned date.
"""

__slots__ = (
"announced",
"unavailable_after",
)

def __init__(
self,
announced=None,
unavailable_after=None,
):
self.announced = isoparse(announced) if announced else None
self.unavailable_after = (
isoparse(unavailable_after) if unavailable_after else None
)
11 changes: 10 additions & 1 deletion hcloud/server_types/domain.py
@@ -1,4 +1,5 @@
from hcloud.core.domain import BaseDomain, DomainIdentityMixin
from hcloud.deprecation.domain import DeprecationInfo


class ServerType(BaseDomain, DomainIdentityMixin):
Expand All @@ -25,7 +26,10 @@ class ServerType(BaseDomain, DomainIdentityMixin):
:param architecture: string
Architecture of cpu. Choices: `x86`, `arm`
:param deprecated: bool
True if server type is deprecated
True if server type is deprecated. 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.
:param included_traffic: int
Free traffic per month in bytes
"""
Expand All @@ -42,6 +46,7 @@ class ServerType(BaseDomain, DomainIdentityMixin):
"cpu_type",
"architecture",
"deprecated",
"deprecation",
"included_traffic",
)

Expand All @@ -58,6 +63,7 @@ def __init__(
cpu_type=None,
architecture=None,
deprecated=None,
deprecation=None,
included_traffic=None,
):
self.id = id
Expand All @@ -71,4 +77,7 @@ def __init__(
self.cpu_type = cpu_type
self.architecture = architecture
self.deprecated = deprecated
self.deprecation = (
DeprecationInfo.from_dict(deprecation) if deprecation is not None else None
)
self.included_traffic = included_traffic
17 changes: 17 additions & 0 deletions tests/unit/server_types/conftest.py
Expand Up @@ -28,6 +28,11 @@ def server_type_response():
"cpu_type": "shared",
"architecture": "x86",
"included_traffic": 21990232555520,
"deprecated": True,
"deprecation": {
"announced": "2023-06-01T00:00:00+00:00",
"unavailable_after": "2023-09-01T00:00:00+00:00",
},
}
}

Expand Down Expand Up @@ -60,6 +65,11 @@ def two_server_types_response():
"cpu_type": "shared",
"architecture": "x86",
"included_traffic": 21990232555520,
"deprecated": True,
"deprecation": {
"announced": "2023-06-01T00:00:00+00:00",
"unavailable_after": "2023-09-01T00:00:00+00:00",
},
},
{
"id": 2,
Expand Down Expand Up @@ -96,6 +106,8 @@ def two_server_types_response():
"cpu_type": "shared",
"architecture": "x86",
"included_traffic": 21990232555520,
"deprecated": False,
"deprecation": None,
},
]
}
Expand Down Expand Up @@ -129,6 +141,11 @@ def one_server_types_response():
"cpu_type": "shared",
"architecture": "x86",
"included_traffic": 21990232555520,
"deprecated": True,
"deprecation": {
"announced": "2023-06-01T00:00:00+00:00",
"unavailable_after": "2023-09-01T00:00:00+00:00",
},
}
]
}
11 changes: 10 additions & 1 deletion tests/unit/server_types/test_client.py
@@ -1,11 +1,12 @@
from datetime import datetime, timezone
from unittest import mock

import pytest

from hcloud.server_types.client import BoundServerType, ServerTypesClient


class TestBoundIso:
class TestBoundServerType:
@pytest.fixture()
def bound_server_type(self, hetzner_client):
return BoundServerType(client=hetzner_client.server_types, data=dict(id=14))
Expand All @@ -24,6 +25,14 @@ def test_bound_server_type_init(self, server_type_response):
assert bound_server_type.storage_type == "local"
assert bound_server_type.cpu_type == "shared"
assert bound_server_type.architecture == "x86"
assert bound_server_type.deprecated is True
assert bound_server_type.deprecation is not None
assert bound_server_type.deprecation.announced == datetime(
2023, 6, 1, tzinfo=timezone.utc
)
assert bound_server_type.deprecation.unavailable_after == datetime(
2023, 9, 1, tzinfo=timezone.utc
)
assert bound_server_type.included_traffic == 21990232555520


Expand Down

0 comments on commit 4a0fce7

Please sign in to comment.