Skip to content

Commit

Permalink
Skip the dynamic groups OneSecondCache if running under pytest
Browse files Browse the repository at this point in the history
This was causing weird test failures where a second test didn't work because it failed
to re-populate the dynamic groups ACL thanks to the 1 second cache. Refs #9
  • Loading branch information
simonw committed Aug 31, 2024
1 parent b03b985 commit 8ac74d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions datasette_acl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from datasette import hookimpl, Response, Permission, Forbidden
from datasette.events import CreateTableEvent
from datasette.utils import actor_matches_allow
import time
import json
import sys
import time


CREATE_TABLES_SQL = """
create table if not exists acl_resources (
Expand Down Expand Up @@ -240,7 +242,9 @@ def permission_allowed(datasette, actor, action, resource):
async def inner():
if not actor:
return None
await update_dynamic_groups(datasette, actor)
await update_dynamic_groups(
datasette, actor, skip_cache=hasattr(sys, "_pytest_running")
)
db = datasette.get_internal_database()
result = await db.execute(
ACL_RESOURCE_PAIR_SQL,
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys


def pytest_configure(config):
sys._pytest_running = True

0 comments on commit 8ac74d8

Please sign in to comment.