Skip to content

Commit cc4876a

Browse files
author
Mathias Bigaignon
committed
Test and client module cleanup
1 parent b5adfd2 commit cc4876a

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

entitled/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def allows(self, actor, action, resource, context: dict | None = None) -> bool:
2424
policy = self._policy_lookup(resource)
2525
return policy.allows(actor, action, resource, context)
2626

27-
def actions(self, actor, resource, context: dict | None = None):
27+
def grants(self, actor, resource, context: dict | None = None):
2828
policy = self._policy_lookup(resource)
2929
return policy.grants(actor, resource, context)
3030

31-
def register_policy(self, policy: policies.Policy):
31+
def register(self, policy: policies.Policy):
3232
if hasattr(policy, "__orig_class__"):
3333
resource_type = getattr(policy, "__orig_class__").__args__[0]
3434
if resource_type not in self._policy_registrar:
@@ -63,7 +63,7 @@ def _register_from_module(self, module: types.ModuleType):
6363
attr = getattr(module, attribute_name)
6464
if isinstance(attr, policies.Policy):
6565
try:
66-
self.register_policy(attr)
66+
self.register(attr)
6767
except (ValueError, AttributeError):
6868
pass
6969

tests/test_policies.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Any
2-
31
from entitled.policies import Policy
42
from entitled.rules import Rule
53
from tests.fixtures.models import Tenant, User
@@ -19,7 +17,7 @@ def test_register_rule_decorator(self):
1917

2018
@policy.rule("is_member")
2119
def is_member(
22-
actor: User, resource: Tenant, context: dict[str, Any] | None = None
20+
actor: User, resource: Tenant, context: dict | None = None
2321
) -> bool:
2422
return actor.tenant == resource
2523

@@ -34,7 +32,7 @@ def test_register_rule_function(self):
3432

3533
@policy.rule("is_member")
3634
def is_member(
37-
actor: User, resource: Tenant, context: dict[str, Any] | None = None
35+
actor: User, resource: Tenant, context: dict | None = None
3836
) -> bool:
3937
return actor.tenant == resource
4038

@@ -54,19 +52,19 @@ def test_list_grants(self):
5452

5553
@policy.rule("is_member")
5654
def is_member(
57-
actor: User, resource: Tenant, context: dict[str, Any] | None = None
55+
actor: User, resource: Tenant, context: dict | None = None
5856
) -> bool:
5957
return actor.tenant == resource
6058

6159
@policy.rule("has_admin_role")
6260
def has_admin_role(
63-
actor: User, resource: Tenant, context: dict[str, Any] | None = None
61+
actor: User, resource: Tenant, context: dict | None = None
6462
) -> bool:
6563
return "admin" in actor.roles
6664

6765
@policy.rule("is_tenant_admin")
6866
def is_tenant_admin(
69-
actor: User, resource: Tenant, context: dict[str, Any] | None = None
67+
actor: User, resource: Tenant, context: dict | None = None
7068
) -> bool:
7169
return is_member(actor, resource, context) and has_admin_role(
7270
actor, resource, context

0 commit comments

Comments
 (0)