Coverage for functions \ flipdare \ mailer \ user \ delete_account_email.py: 83%
41 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« 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#
14from typing import Self, override
15from flipdare.mailer._jinja_email_template import JinjaEmailTemplate
16from flipdare.mailer.app_email_params import AppEmailParams
17from flipdare.mailer.app_email_type import AppEmailType
18from flipdare.error.app_error import CodePathError
19from flipdare.generated.schema.email.body.user.delete_account_email_schema import (
20 DeleteAccountEmailSchema,
21)
22from flipdare.wrapper import UserWrapper
24__all__ = ["DeleteAccountEmail"]
27class DeleteAccountEmail(JinjaEmailTemplate[DeleteAccountEmailSchema]):
29 SCHEMA_CLASS = DeleteAccountEmailSchema
31 @classmethod
32 def delete_complete(cls, to_user: UserWrapper) -> Self:
33 data = DeleteAccountEmailSchema(
34 {"to_name": to_user.model.contact_name, "is_confirm": False},
35 )
37 email_type = AppEmailType.USR_DELETE_ACCOUNT_COMPLETE
38 return cls(
39 data=data,
40 params=AppEmailParams(
41 email_type=email_type,
42 schema=None,
43 ),
44 )
46 @classmethod
47 def delete_confirm(cls, to_user: UserWrapper) -> Self:
48 to_model = to_user.model
49 if to_model.delete_code is None:
50 msg = f"User model '{to_model.contact_name}' does not have a delete_code, cant confirm"
51 raise CodePathError(message=msg)
53 data = DeleteAccountEmailSchema(
54 {
55 "to_name": to_model.contact_name,
56 "is_confirm": True,
57 },
58 )
60 email_type = AppEmailType.USR_DELETE_ACCOUNT
61 return cls(
62 data=data,
63 params=AppEmailParams(
64 email_type=email_type,
65 schema=None,
66 ),
67 )
69 @override
70 def newline_fields(self) -> list[str]:
71 return [] # no fields expected to have newlines, but can add if needed in the future
73 @property
74 @override
75 def data(self) -> DeleteAccountEmailSchema:
76 assert isinstance(self._data, dict) # narrowing, we known we have a dict..
77 return self._data
79 @property
80 def is_confirm(self) -> bool:
81 return self.data["is_confirm"]
83 @property
84 def to_name(self) -> str:
85 return self.data["to_name"]
87 @property
88 def delete_code(self) -> str | None:
89 return self.data.get("delete_code", None)