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

10 statements  

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

1""" 

2Emails the recipient their verification code instead of posting them a postcard. 

3 

4Used when POSTAL_VERIFICATION_BYPASS_POST_AND_EMAIL_CODE_FOR_TESTING is set, so a deployment can run the whole 

5postal verification flow end to end without placing (billed) MyPostcard orders. The code is real and completes 

6verification; only the printing and posting is skipped. 

7""" 

8 

9import logging 

10 

11from sqlalchemy.orm.session import Session 

12 

13from couchers.email.queuing import queue_system_email 

14from couchers.postal.my_postcard import _generate_back_left_side_png 

15from couchers.proto.internal import jobs_pb2 

16 

17logger = logging.getLogger(__name__) 

18 

19ATTACHMENT_FILENAME = "postcard.png" 

20 

21 

22def email_verification_code_instead_of_posting( 

23 session: Session, 

24 *, 

25 recipient_email: str, 

26 recipient_name: str, 

27 address_line_1: str, 

28 address_line_2: str | None, 

29 city: str, 

30 state: str | None, 

31 postal_code: str | None, 

32 country: str, 

33 verification_code: str, 

34) -> None: 

35 address = ", ".join(part for part in (address_line_1, address_line_2, city, state, postal_code, country) if part) 

36 

37 queue_system_email( 

38 session, 

39 recipient_email, 

40 "postal_verification_testing_code", 

41 { 

42 "recipient_name": recipient_name, 

43 "address": address, 

44 "verification_code": verification_code, 

45 }, 

46 attachments=[ 

47 jobs_pb2.EmailPart( 

48 data=_generate_back_left_side_png(verification_code), 

49 content_type=f'image/png; name="{ATTACHMENT_FILENAME}"', 

50 content_disposition=f'attachment; filename="{ATTACHMENT_FILENAME}"', 

51 ) 

52 ], 

53 )