Coverage for app / backend / src / couchers / constants.py: 100%

46 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-05 09:44 +0000

1from datetime import UTC, datetime, timedelta 

2 

3# terms of service version 

4TOS_VERSION = 2 

5 

6# community guidelines version 

7GUIDELINES_VERSION = 1 

8 

9EMAIL_REGEX = r"^[0-9a-z]([0-9a-z\-\_\+]|(\.[0-9a-z\-\_\+]))*@([0-9a-z\-]+\.)*[0-9a-z\-]+\.[a-z]{2,}$" 

10 

11BANNED_USERNAME_PHRASES = [ 

12 "admin", 

13 "bot", 

14 "safety", 

15 "security", 

16 "secure", 

17 "trust", 

18 "couchers", 

19 "help", 

20 "moderation", 

21 "moderator", 

22 "noreply", 

23 "official", 

24 "security", 

25 "staff", 

26 "support", 

27 "system", 

28 "team", 

29 "verify", 

30] 

31 

32# expiry time for a verified phone number 

33PHONE_VERIFICATION_LIFETIME = timedelta(days=2 * 365) 

34 

35# shortest period between phone verification code requests 

36PHONE_REVERIFICATION_INTERVAL = timedelta(days=2) 

37 

38# expiry time for an sms code 

39SMS_CODE_LIFETIME = timedelta(hours=24) 

40 

41# max attempts to enter the sms code 

42SMS_CODE_ATTEMPTS = 3 

43 

44# Postal verification constants 

45POSTAL_VERIFICATION_CODE_LENGTH = 6 

46# Reduced alphabet to avoid confusion (no I, O, 0, 1) 

47POSTAL_VERIFICATION_CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789" 

48# Code valid for 90 days after postcard sent 

49POSTAL_VERIFICATION_CODE_LIFETIME = timedelta(days=90) 

50# Max wrong code attempts before lockout 

51POSTAL_VERIFICATION_MAX_ATTEMPTS = 5 

52# Can only initiate once per 30 days 

53POSTAL_VERIFICATION_RATE_LIMIT = timedelta(days=30) 

54 

55SIGNUP_EMAIL_TOKEN_VALIDITY = timedelta(hours=48) 

56 

57DATETIME_MINUS_INFINITY = datetime(1, 1, 1, tzinfo=UTC) 

58DATETIME_INFINITY = datetime(9876, 12, 31, hour=23, minute=59, second=59, tzinfo=UTC) 

59 

60SERVER_THREADS = 128 

61 

62WORKER_THREADS = 1 

63 

64# how long the user has to undelete their account 

65UNDELETE_DAYS = 7 

66 

67# expiry time for preferred language cookie 

68PREFERRED_LANGUAGE_COOKIE_EXPIRY = timedelta(days=3650) 

69 

70 

71# activeness probe settings 

72# wait about 11 months before sending one out 

73ACTIVENESS_PROBE_INACTIVITY_PERIOD = timedelta(days=333) 

74# times at which to send notifications after inactivity (cumulative since start of probe) 

75ACTIVENESS_PROBE_TIME_REMINDERS = [timedelta(days=0), timedelta(days=2, hours=8)] 

76# total time from initiation after which to expire the probe 

77ACTIVENESS_PROBE_EXPIRY_TIME = timedelta(days=4) 

78 

79HOST_REQUEST_MAX_REMINDERS = 1 

80HOST_REQUEST_REMINDER_INTERVAL = timedelta(days=2) 

81 

82# Note: Javascript's string.length is in utf16 code units, Python's len(str) is in utf8 code units. 

83HOST_REQUEST_MIN_LENGTH_UTF16 = 250 # Must match frontend 

84PUBLIC_TRIP_DESCRIPTION_MIN_LENGTH_UTF16 = 150 # Must match frontend 

85 

86ANTIBOT_FREQ = timedelta(hours=48) 

87 

88EVENT_REMINDER_TIMEDELTA = timedelta(hours=24) 

89 

90COMMUNITIES_SEARCH_FUZZY_SIMILARITY_THRESHOLD = 0.35 

91 

92UNKNOWN_ERROR_MESSAGE = "An unknown backend error occurred. Please consider filing a bug!" 

93 

94# NOTE: these codes are on purpose not translatable 

95NONEXISTENT_API_CALL_ERROR_MESSAGE = "API call does not exist. Please refresh and try again." 

96MISSING_AUTH_LEVEL_ERROR_MESSAGE = "Internal authentication error." 

97COOKIES_AND_AUTH_HEADER_ERROR_MESSAGE = 'Both "cookie" and "authorization" in request' 

98CALL_CANCELLED_ERROR_MESSAGE = "Call cancelled." 

99 

100# NOTE: the frontend uses these (and error codes) to distinguish between jailed and logged out 

101UNAUTHORIZED_ERROR_MESSAGE = "Unauthorized" 

102PERMISSION_DENIED_ERROR_MESSAGE = "Permission denied" 

103 

104GHOST_USERNAME = "ghost" 

105 

106# Donation drive start date - set to None to disable donation drive banner 

107# When set, users who haven't donated since this date will see a donation banner 

108DONATION_DRIVE_START: datetime | None = None 

109 

110DONATION_GOAL_USD = 5000 

111# exclude big donations from Aapeli + Itsi that we're hoping to do without :) 

112DONATION_OFFSET_USD = 2000 

113 

114# Photo gallery limits 

115GALLERY_MAX_PHOTOS_NOT_VERIFIED = 1 

116GALLERY_MAX_PHOTOS_VERIFIED = 4 

117 

118COMPLETED_PROFILE_MINIMUM_CHAR_LENGTH = 150 

119 

120# How long a container must run uninterrupted before /status reports stable=true 

121STABLE_THRESHOLD_SECONDS = 5 * 60