We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 198f549 commit 2e59d20Copy full SHA for 2e59d20
2 files changed
hcloud/core/domain.py
@@ -52,15 +52,22 @@ def has_id_or_name(self, id_or_name: int | str) -> bool:
52
the comparison will not work as expected (e.g. the domains are the same but
53
cannot be equal, if one provides an id and the other the name).
54
"""
55
- values: list[int | str] = []
+ result = None
56
+
57
if self.id is not None:
- values.append(self.id)
58
+ value = id_or_name
59
+ if isinstance(id_or_name, str) and id_or_name.isnumeric():
60
+ value = int(id_or_name)
61
62
+ result = result or self.id == value
63
64
if self.name is not None:
- values.append(self.name)
- if not values:
65
+ result = result or self.name == str(id_or_name)
66
67
+ if result is None:
68
raise ValueError("id or name must be set")
69
- return id_or_name in values
70
+ return result
71
72
73
class Pagination(BaseDomain):
tests/unit/core/test_domain.py
@@ -71,19 +71,19 @@ def test_id_or_name_exception(self):
assert str(error) == "id or name must be set"
@pytest.mark.parametrize(
74
- "other, expected",
+ "id_or_name, expected",
75
[
76
- (SomeDomain(id=1), True),
77
- (SomeDomain(name="name1"), True),
78
- (SomeDomain(id=1, name="name1"), True),
79
- (SomeDomain(id=2), False),
80
- (SomeDomain(name="name2"), False),
81
- (SomeDomain(id=2, name="name2"), False),
+ (1, True),
+ ("1", True),
+ ("name1", True),
+ (2, False),
+ ("2", False),
+ ("name2", False),
82
],
83
)
84
- def test_has_id_or_name_exception(self, other, expected):
+ def test_has_id_or_name(self, id_or_name, expected):
85
domain = SomeDomain(id=1, name="name1")
86
- assert domain.has_id_or_name(other.id_or_name) == expected
+ assert domain.has_id_or_name(id_or_name) == expected
87
88
89
class ActionDomain(BaseDomain, DomainIdentityMixin):
0 commit comments