Browse Source

fix: implement hash

fix/nvc
Richard Nemeth 3 months ago
parent
commit
7c6fa1374f
No known key found for this signature in database GPG Key ID: 21C39470DF3DEC39
  1. 9
      src/keycloak/authorization/role.py
  2. 1
      tests/test_authorization.py

9
src/keycloak/authorization/role.py

@ -78,3 +78,12 @@ class Role:
msg = f"Cannot compare Role with {type(other)}"
raise NotImplementedError(msg)
def __hash__(self) -> int:
"""
Hash method.
:returns: Hash value
:rtype: int
"""
return hash(f"{self.name}-{self.required}")

1
tests/test_authorization.py

@ -40,6 +40,7 @@ def test_authorization_objects() -> None:
assert not r.required
assert r.get_name() == "test"
assert r == r # noqa: PLR0124
assert hash(r) == hash("test-False")
assert r == "test"
with pytest.raises(NotImplementedError) as err:

Loading…
Cancel
Save