mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix assert_permissions_checked to handle PermissionCheck dataclass
Updated the assert_permissions_checked() helper function to work with the new PermissionCheck dataclass instead of dictionaries. The function now: - Uses dataclass attributes (pc.action) instead of dict subscripting - Converts parent/child to old resource format for comparison - Updates error message formatting to show dataclass fields 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
10ea23a59c
commit
66f2dbb64a
1 changed files with 27 additions and 2 deletions
|
|
@ -755,16 +755,41 @@ def assert_permissions_checked(datasette, actions):
|
||||||
resource = None
|
resource = None
|
||||||
else:
|
else:
|
||||||
action, resource = action
|
action, resource = action
|
||||||
|
|
||||||
|
# Convert PermissionCheck dataclass to old resource format for comparison
|
||||||
|
def check_matches(pc, action, resource):
|
||||||
|
if pc.action != action:
|
||||||
|
return False
|
||||||
|
# Convert parent/child to old resource format
|
||||||
|
if pc.parent and pc.child:
|
||||||
|
pc_resource = (pc.parent, pc.child)
|
||||||
|
elif pc.parent:
|
||||||
|
pc_resource = pc.parent
|
||||||
|
else:
|
||||||
|
pc_resource = None
|
||||||
|
return pc_resource == resource
|
||||||
|
|
||||||
assert [
|
assert [
|
||||||
pc
|
pc
|
||||||
for pc in datasette._permission_checks
|
for pc in datasette._permission_checks
|
||||||
if pc["action"] == action and pc["resource"] == resource
|
if check_matches(pc, action, resource)
|
||||||
], """Missing expected permission check: action={}, resource={}
|
], """Missing expected permission check: action={}, resource={}
|
||||||
Permission checks seen: {}
|
Permission checks seen: {}
|
||||||
""".format(
|
""".format(
|
||||||
action,
|
action,
|
||||||
resource,
|
resource,
|
||||||
json.dumps(list(datasette._permission_checks), indent=4),
|
json.dumps(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"action": pc.action,
|
||||||
|
"parent": pc.parent,
|
||||||
|
"child": pc.child,
|
||||||
|
"result": pc.result,
|
||||||
|
}
|
||||||
|
for pc in datasette._permission_checks
|
||||||
|
],
|
||||||
|
indent=4,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue