diff --git a/src/keycloak/authorization/role.py b/src/keycloak/authorization/role.py index 0ffb193..7d01f77 100644 --- a/src/keycloak/authorization/role.py +++ b/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}") diff --git a/tests/test_authorization.py b/tests/test_authorization.py index 2ceb622..bc30f8f 100644 --- a/tests/test_authorization.py +++ b/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: