Coverage for chalicelib/core/scope.py: 89%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 12:56 +0000

1from cachetools import cached, TTLCache 

2 

3from chalicelib.utils import pg_client 

4 

5cache = TTLCache(maxsize=1, ttl=60) 

6 

7 

8@cached(cache) 

9def get_scope(tenant_id) -> int: 

10 with pg_client.PostgresClient() as cur: 

11 query = cur.mogrify(f"""SELECT scope_state  

12 FROM public.tenants;""") 

13 cur.execute(query) 

14 return cur.fetchone()["scope_state"] 

15 

16 

17def update_scope(tenant_id, scope: int): 

18 with pg_client.PostgresClient() as cur: 

19 query = cur.mogrify(f"""UPDATE public.tenants 

20 SET scope_state = %(scope_state)s;""", 

21 {"scope_state": scope}) 

22 cur.execute(query) 

23 if tenant_id in cache: 23 ↛ 24line 23 didn't jump to line 24 because the condition on line 23 was never true

24 cache.pop(tenant_id) 

25 return scope