Coverage for src/couchers/helpers/strong_verification.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-08-28 14:55 +0000

1from couchers.models import StrongVerificationAttempt 

2from couchers.sql import couchers_select as select 

3from proto import api_pb2 

4 

5 

6def has_strong_verification(session, user): 

7 attempt = session.execute( 

8 select(StrongVerificationAttempt) 

9 .where(StrongVerificationAttempt.user_id == user.id) 

10 .where(StrongVerificationAttempt.is_valid) 

11 .order_by(StrongVerificationAttempt.passport_expiry_datetime.desc()) 

12 .limit(1) 

13 ).scalar_one_or_none() 

14 if attempt: 

15 assert attempt.is_valid 

16 return attempt.has_strong_verification(user) 

17 return False 

18 

19 

20def get_strong_verification_fields(session, db_user): 

21 out = dict( 

22 birthdate_verification_status=api_pb2.BIRTHDATE_VERIFICATION_STATUS_UNVERIFIED, 

23 gender_verification_status=api_pb2.GENDER_VERIFICATION_STATUS_UNVERIFIED, 

24 has_strong_verification=False, 

25 ) 

26 attempt = session.execute( 

27 select(StrongVerificationAttempt) 

28 .where(StrongVerificationAttempt.user_id == db_user.id) 

29 .where(StrongVerificationAttempt.is_valid) 

30 .order_by(StrongVerificationAttempt.passport_expiry_datetime.desc()) 

31 .limit(1) 

32 ).scalar_one_or_none() 

33 if attempt: 

34 assert attempt.is_valid 

35 if attempt.matches_birthdate(db_user): 

36 out["birthdate_verification_status"] = api_pb2.BIRTHDATE_VERIFICATION_STATUS_VERIFIED 

37 else: 

38 out["birthdate_verification_status"] = api_pb2.BIRTHDATE_VERIFICATION_STATUS_MISMATCH 

39 

40 if attempt.matches_gender(db_user): 

41 out["gender_verification_status"] = api_pb2.GENDER_VERIFICATION_STATUS_VERIFIED 

42 else: 

43 out["gender_verification_status"] = api_pb2.GENDER_VERIFICATION_STATUS_MISMATCH 

44 

45 out["has_strong_verification"] = attempt.has_strong_verification(db_user) 

46 

47 assert out["has_strong_verification"] == ( 

48 out["birthdate_verification_status"] == api_pb2.BIRTHDATE_VERIFICATION_STATUS_VERIFIED 

49 and out["gender_verification_status"] == api_pb2.GENDER_VERIFICATION_STATUS_VERIFIED 

50 ) 

51 return out