Skip to content

Commit bcbdd7d

Browse files
authored
fix: equality for some domain classes (#510)
Some domains were missing the `__api_properties__` and `__slots__` properties required for the equality check.
1 parent 8491fea commit bcbdd7d

File tree

21 files changed

+373
-5
lines changed

21 files changed

+373
-5
lines changed

hcloud/certificates/domain.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ class ManagedCertificateStatus(BaseDomain):
8787
If issuance or renewal reports failure, this property contains information about what happened
8888
"""
8989

90+
__api_properties__ = (
91+
"issuance",
92+
"renewal",
93+
"error",
94+
)
95+
__slots__ = __api_properties__
96+
9097
def __init__(
9198
self,
9299
issuance: str | None = None,
@@ -107,6 +114,12 @@ class ManagedCertificateError(BaseDomain):
107114
Message detailing the error
108115
"""
109116

117+
__api_properties__ = (
118+
"code",
119+
"message",
120+
)
121+
__slots__ = __api_properties__
122+
110123
def __init__(self, code: str | None = None, message: str | None = None):
111124
self.code = code
112125
self.message = message

hcloud/load_balancers/domain.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ class LoadBalancerServiceHttp(BaseDomain):
229229
Use sticky sessions. Only available if protocol is "http" or "https".
230230
"""
231231

232+
__api_properties__ = (
233+
"cookie_name",
234+
"cookie_lifetime",
235+
"certificates",
236+
"redirect_http",
237+
"sticky_sessions",
238+
)
239+
__slots__ = __api_properties__
240+
232241
def __init__(
233242
self,
234243
cookie_name: str | None = None,
@@ -261,6 +270,16 @@ class LoadBalancerHealthCheck(BaseDomain):
261270
HTTP Config
262271
"""
263272

273+
__api_properties__ = (
274+
"protocol",
275+
"port",
276+
"interval",
277+
"timeout",
278+
"retries",
279+
"http",
280+
)
281+
__slots__ = __api_properties__
282+
264283
def __init__(
265284
self,
266285
protocol: str | None = None,
@@ -293,6 +312,15 @@ class LoadBalancerHealthCheckHttp(BaseDomain):
293312
Type of health check
294313
"""
295314

315+
__api_properties__ = (
316+
"domain",
317+
"path",
318+
"response",
319+
"status_codes",
320+
"tls",
321+
)
322+
__slots__ = __api_properties__
323+
296324
def __init__(
297325
self,
298326
domain: str | None = None,
@@ -350,6 +378,16 @@ class LoadBalancerTarget(BaseDomain):
350378
List of health statuses of the services on this target. Only present for target types "server" and "ip".
351379
"""
352380

381+
__api_properties__ = (
382+
"type",
383+
"server",
384+
"label_selector",
385+
"ip",
386+
"use_private_ip",
387+
"health_status",
388+
)
389+
__slots__ = __api_properties__
390+
353391
def __init__(
354392
self,
355393
type: str | None = None,
@@ -401,6 +439,12 @@ class LoadBalancerTargetHealthStatus(BaseDomain):
401439
:param status: Load Balancer Target status. Choices: healthy, unhealthy, unknown
402440
"""
403441

442+
__api_properties__ = (
443+
"listen_port",
444+
"status",
445+
)
446+
__slots__ = __api_properties__
447+
404448
def __init__(
405449
self,
406450
listen_port: int | None = None,
@@ -416,6 +460,9 @@ class LoadBalancerTargetLabelSelector(BaseDomain):
416460
:param selector: str Target label selector
417461
"""
418462

463+
__api_properties__ = ("selector",)
464+
__slots__ = __api_properties__
465+
419466
def __init__(self, selector: str | None = None):
420467
self.selector = selector
421468

@@ -426,6 +473,9 @@ class LoadBalancerTargetIP(BaseDomain):
426473
:param ip: str Target IP
427474
"""
428475

476+
__api_properties__ = ("ip",)
477+
__slots__ = __api_properties__
478+
429479
def __init__(self, ip: str | None = None):
430480
self.ip = ip
431481

@@ -437,6 +487,9 @@ class LoadBalancerAlgorithm(BaseDomain):
437487
Algorithm of the Load Balancer. Choices: round_robin, least_connections
438488
"""
439489

490+
__api_properties__ = ("type",)
491+
__slots__ = __api_properties__
492+
440493
def __init__(self, type: str | None = None):
441494
self.type = type
442495

tests/unit/actions/test_domain.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
)
1414

1515

16+
@pytest.mark.parametrize(
17+
"value",
18+
[
19+
(Action(id=1),),
20+
],
21+
)
22+
def test_eq(value):
23+
assert value == value
24+
25+
1626
class TestAction:
1727
def test_started_finished_is_datetime(self):
1828
action = Action(

tests/unit/certificates/test_domain.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,25 @@
33
import datetime
44
from datetime import timezone
55

6-
from hcloud.certificates import Certificate
6+
import pytest
7+
8+
from hcloud.certificates import (
9+
Certificate,
10+
ManagedCertificateError,
11+
ManagedCertificateStatus,
12+
)
13+
14+
15+
@pytest.mark.parametrize(
16+
"value",
17+
[
18+
(Certificate(id=1),),
19+
(ManagedCertificateError()),
20+
(ManagedCertificateStatus()),
21+
],
22+
)
23+
def test_eq(value):
24+
assert value == value
725

826

927
class TestCertificate:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from hcloud.datacenters import Datacenter, DatacenterServerTypes
6+
7+
8+
@pytest.mark.parametrize(
9+
"value",
10+
[
11+
(Datacenter(id=1),),
12+
(DatacenterServerTypes(available=[], available_for_migration=[], supported=[])),
13+
],
14+
)
15+
def test_eq(value):
16+
assert value == value

tests/unit/deprecation/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
5+
from hcloud.deprecation import DeprecationInfo
6+
7+
8+
@pytest.mark.parametrize(
9+
"value",
10+
[
11+
(DeprecationInfo(),),
12+
],
13+
)
14+
def test_eq(value):
15+
assert value == value

tests/unit/firewalls/test_domain.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,29 @@
33
import datetime
44
from datetime import timezone
55

6-
from hcloud.firewalls import Firewall
6+
import pytest
7+
8+
from hcloud.firewalls import (
9+
Firewall,
10+
FirewallResource,
11+
FirewallResourceAppliedToResources,
12+
FirewallResourceLabelSelector,
13+
FirewallRule,
14+
)
15+
16+
17+
@pytest.mark.parametrize(
18+
"value",
19+
[
20+
(Firewall(id=1),),
21+
(FirewallRule(direction="in", protocol="icmp", source_ips=[]),),
22+
(FirewallResource(type="server"),),
23+
(FirewallResourceAppliedToResources(type="server"),),
24+
(FirewallResourceLabelSelector(),),
25+
],
26+
)
27+
def test_eq(value):
28+
assert value == value
729

830

931
class TestFirewall:

tests/unit/floating_ips/test_domain.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
import datetime
44
from datetime import timezone
55

6+
import pytest
7+
68
from hcloud.floating_ips import FloatingIP
79

810

11+
@pytest.mark.parametrize(
12+
"value",
13+
[
14+
(FloatingIP(id=1),),
15+
],
16+
)
17+
def test_eq(value):
18+
assert value == value
19+
20+
921
class TestFloatingIP:
1022
def test_created_is_datetime(self):
1123
floatingIP = FloatingIP(id=1, created="2016-01-30T23:50+00:00")

tests/unit/images/test_domain.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,21 @@
33
import datetime
44
from datetime import timezone
55

6+
import pytest
7+
68
from hcloud.images import Image
79

810

11+
@pytest.mark.parametrize(
12+
"value",
13+
[
14+
(Image(id=1),),
15+
],
16+
)
17+
def test_eq(value):
18+
assert value == value
19+
20+
921
class TestImage:
1022
def test_created_is_datetime(self):
1123
image = Image(id=1, created="2016-01-30T23:50+00:00")

0 commit comments

Comments
 (0)