Coverage for src/couchers/servicers/resources.py: 93%

15 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-11-21 04:21 +0000

1import logging 

2 

3from couchers.resources import ( 

4 get_badge_dict, 

5 get_community_guidelines, 

6 get_language_dict, 

7 get_region_dict, 

8 get_terms_of_service, 

9) 

10from proto import resources_pb2, resources_pb2_grpc 

11 

12logger = logging.getLogger(__name__) 

13 

14 

15class Resources(resources_pb2_grpc.ResourcesServicer): 

16 def GetTermsOfService(self, request, context, session): 

17 return resources_pb2.GetTermsOfServiceRes(terms_of_service=get_terms_of_service()) 

18 

19 def GetCommunityGuidelines(self, request, context, session): 

20 return resources_pb2.GetCommunityGuidelinesRes(community_guidelines=get_community_guidelines()) 

21 

22 def GetRegions(self, request, context, session): 

23 return resources_pb2.GetRegionsRes( 

24 regions=[ 

25 resources_pb2.Region(alpha3=alpha3, name=name) for alpha3, name in sorted(get_region_dict().items()) 

26 ] 

27 ) 

28 

29 def GetLanguages(self, request, context, session): 

30 return resources_pb2.GetLanguagesRes( 

31 languages=[ 

32 resources_pb2.Language(code=code, name=name) for code, name in sorted(get_language_dict().items()) 

33 ] 

34 ) 

35 

36 def GetBadges(self, request, context, session): 

37 return resources_pb2.GetBadgesRes( 

38 badges=[ 

39 resources_pb2.Badge( 

40 id=badge["id"], name=badge["name"], description=badge["description"], color=badge["color"] 

41 ) 

42 for badge in get_badge_dict().values() 

43 ] 

44 )