Coverage for src/tests/test_resources.py: 100%

53 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-12-20 11:53 +0000

1import pytest 

2from google.protobuf import empty_pb2 

3 

4from tests.test_fixtures import db, resources_session, testconfig # noqa 

5 

6 

7@pytest.fixture(autouse=True) 

8def _(testconfig): 

9 pass 

10 

11 

12def test_GetTermsOfService(): 

13 # make sure it works and we get out a bunch of text 

14 with resources_session() as api: 

15 res = api.GetTermsOfService(empty_pb2.Empty()).terms_of_service 

16 assert len(res) > 100 

17 assert "couchers, inc." in res.lower() 

18 

19 

20def test_GetCommunityGuidelines(): 

21 # make sure it works and we get out a bunch of text 

22 with resources_session() as api: 

23 res = api.GetCommunityGuidelines(empty_pb2.Empty()).community_guidelines 

24 assert len(res) == 4 

25 assert res[2].title == "Be safe and sensible" 

26 assert "inappropriate content" in res[2].guideline 

27 assert "stroke" in res[2].icon_svg 

28 

29 

30def test_GetRegions(db): 

31 with resources_session() as api: 

32 regions = api.GetRegions(empty_pb2.Empty()).regions 

33 regions_list = [(r.alpha3, r.name) for r in regions] 

34 assert ("FIN", "Finland") in regions_list 

35 assert ("SWE", "Sweden") in regions_list 

36 assert ("???", "Nonexistent region") not in regions_list 

37 

38 

39def test_GetLanguages(db): 

40 with resources_session() as api: 

41 languages = api.GetLanguages(empty_pb2.Empty()).languages 

42 languages_list = [(r.code, r.name) for r in languages] 

43 assert ("fin", "Finnish") in languages_list 

44 assert ("swe", "Swedish") in languages_list 

45 assert ("???", "Nonexistent language") not in languages_list 

46 

47 

48def test_GetBadges(db): 

49 with resources_session() as api: 

50 badges = api.GetBadges(empty_pb2.Empty()).badges 

51 badges_dict = {b.id: b for b in badges} 

52 

53 # Check that all expected badges are present 

54 expected_badge_ids = { 

55 "founder", 

56 "board_member", 

57 "past_board_member", 

58 "moderator", 

59 "volunteer", 

60 "past_volunteer", 

61 "donor", 

62 "phone_verified", 

63 "strong_verification", 

64 "swagster", 

65 } 

66 assert set(badges_dict.keys()) == expected_badge_ids 

67 

68 # Check that a specific badge has the correct properties 

69 founder = badges_dict["founder"] 

70 assert founder.id == "founder" 

71 assert founder.name == "Founder" 

72 assert founder.description == "This user is one of the two founders of Couchers.org" 

73 assert founder.color == "#e47701" 

74 

75 # Check another badge to ensure translations are working 

76 moderator = badges_dict["moderator"] 

77 assert moderator.id == "moderator" 

78 assert moderator.name == "Moderator" 

79 assert moderator.description == "This user is a moderator of Couchers.org" 

80 assert moderator.color == "#c74f5b" 

81 

82 # Check strong_verification badge 

83 strong_verification = badges_dict["strong_verification"] 

84 assert strong_verification.id == "strong_verification" 

85 assert strong_verification.name == "Strong Verification" 

86 assert ( 

87 strong_verification.description 

88 == "This user has verified their gender and date of birth with a biometric passport" 

89 ) 

90 assert strong_verification.color == "#1b8aa0"