From 66f2dbb64aa4405eda9279fd6dfe0e57d1c609ea Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 25 Oct 2025 10:03:41 -0700 Subject: [PATCH] Fix assert_permissions_checked to handle PermissionCheck dataclass MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/fixtures.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/fixtures.py b/tests/fixtures.py index 5c51a7c5..8d600c9b 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -755,16 +755,41 @@ def assert_permissions_checked(datasette, actions): resource = None else: 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 [ pc 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={} Permission checks seen: {} """.format( action, 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, + ), )