Coverage for website/utils/google_api.py: 71.43%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2025-08-14 10:31 +0000

1from django.conf import settings 

2 

3from googleapiclient.discovery import build 

4from googleapiclient.discovery_cache.base import Cache 

5 

6 

7class MemoryCache(Cache): 

8 _CACHE = {} 

9 

10 def get(self, url): 

11 return MemoryCache._CACHE.get(url) 

12 

13 def set(self, url, content): 

14 MemoryCache._CACHE[url] = content 

15 

16 

17memory_cache = MemoryCache() 

18 

19 

20def get_directory_api(): 

21 return build( 

22 "admin", 

23 "directory_v1", 

24 credentials=settings.GSUITE_ADMIN_CREDENTIALS, 

25 cache=memory_cache, 

26 ) 

27 

28 

29def get_groups_settings_api(): 

30 return build( 

31 "groupssettings", 

32 "v1", 

33 credentials=settings.GSUITE_ADMIN_CREDENTIALS, 

34 cache=memory_cache, 

35 )