Coverage for functions \ flipdare \ mailer \ user \ invite_email.py: 86%

44 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

3# 

4# This file is part of Flipdare's proprietary software and contains 

5# confidential and copyrighted material. Unauthorised copying, 

6# modification, distribution, or use of this file is strictly 

7# prohibited without prior written permission from Flipdare Pty Ltd. 

8# 

9# This software includes third-party components licensed under MIT, 

10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

11# 

12 

13 

14from typing import override 

15from flipdare.app_log import LOG 

16from flipdare.constants import IS_DEBUG 

17from flipdare.mailer._jinja_email_template import JinjaEmailTemplate 

18from flipdare.mailer.app_email_params import AppEmailParams 

19from flipdare.mailer.app_email_type import AppEmailType 

20from flipdare.generated.schema.email.subject.user.invite_subject_schema import InviteSubjectSchema 

21from flipdare.generated.schema.email.body.user.invite_email_schema import InviteEmailSchema 

22from flipdare.util.user_util import UserUtil 

23from flipdare.wrapper import InviteWrapper 

24 

25__all__ = ["InviteEmail"] 

26 

27 

28class InviteEmail(JinjaEmailTemplate[InviteEmailSchema]): 

29 __slots__ = ("_subject",) 

30 

31 SCHEMA_CLASS = InviteEmailSchema 

32 

33 def __init__( 

34 self, 

35 invite: InviteWrapper, 

36 signup_code: str, 

37 is_reminder: bool = False, 

38 ) -> None: 

39 

40 from_name = UserUtil.contact_name(name=invite.from_name, email=invite.from_email) 

41 to_name = UserUtil.contact_name(name=invite.to_name, email=invite.to_email) 

42 email_type = ( 

43 AppEmailType.USR_INVITE if not is_reminder else AppEmailType.USR_INVITE_REMINDER 

44 ) 

45 

46 data = self._build_data( 

47 from_name=from_name, 

48 to_name=to_name, 

49 signup_code=signup_code, 

50 is_reminder=is_reminder, 

51 ) 

52 

53 super().__init__( 

54 data=data, 

55 params=AppEmailParams(email_type=email_type, schema=InviteSubjectSchema(name=to_name)), 

56 ) 

57 

58 def _build_data( 

59 self, 

60 from_name: str, 

61 to_name: str, 

62 signup_code: str, 

63 is_reminder: bool = False, 

64 ) -> InviteEmailSchema: 

65 if IS_DEBUG: 

66 LOG().debug( 

67 f'Building invite with: from_name="{from_name}", to_name="{to_name}", ' 

68 f'signup_code="{signup_code}", is_reminder={is_reminder}', 

69 ) 

70 return InviteEmailSchema( 

71 { 

72 "from_name": from_name, 

73 "to_name": to_name, 

74 "signup_code": signup_code, 

75 "is_reminder": is_reminder, 

76 }, 

77 ) 

78 

79 @override 

80 def newline_fields(self) -> list[str]: 

81 return [] # no fields expected to have newlines, but can add if needed in the future 

82 

83 @property 

84 @override 

85 def data(self) -> InviteEmailSchema: 

86 assert isinstance(self._data, dict) # narrowing, we known we have a dict.. 

87 return self._data 

88 

89 @property 

90 def from_name(self) -> str: 

91 return self.data["from_name"] 

92 

93 @property 

94 def to_name(self) -> str: 

95 return self.data["to_name"] 

96 

97 @property 

98 def signup_code(self) -> str: 

99 return self.data["signup_code"] 

100 

101 @property 

102 def is_reminder(self) -> bool: 

103 return self.data["is_reminder"]