Coverage for functions \ flipdare \ mailer \ admin \ admin_report_email.py: 84%
37 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#
13from typing import override
14from flipdare.mailer._jinja_email_template import JinjaEmailTemplate
15from flipdare.mailer.app_email_params import AppEmailParams
16from flipdare.mailer.app_email_type import AppEmailType
17from flipdare.mailer.email_image import EmailImage
18from flipdare.generated.schema.email.body.admin.report_email_schema import ReportEmailSchema
19from flipdare.generated.schema.email.subject.admin.report_subject_schema import ReportSubjectSchema
20from flipdare.generated.shared.backend.app_report_priority import AppReportPriority
22__all__ = ["AdminReportEmail"]
25class AdminReportEmail(JinjaEmailTemplate[ReportEmailSchema]):
27 __slots__ = ("_html_result", "_subject")
29 SCHEMA_CLASS = ReportEmailSchema
31 def __init__(
32 self,
33 report_date: str,
34 report_name: str,
35 report_description: str,
36 html: str,
37 text: str,
38 priority: AppReportPriority,
39 images: list[EmailImage] | None = None,
40 report_error: str | None = None,
41 ) -> None:
43 data = self._build_report(
44 report_date=report_date,
45 report_name=report_name,
46 report_description=report_description,
47 html=html,
48 text=text,
49 report_error=report_error,
50 priority=priority,
51 )
52 super().__init__(
53 data=data,
54 images=images,
55 params=AppEmailParams(
56 email_type=AppEmailType.ADM_REPORT,
57 schema=ReportSubjectSchema(
58 report_name=report_name,
59 report_date=report_date,
60 priority=priority.value.upper(),
61 ),
62 ),
63 )
65 def _build_report(
66 self,
67 report_date: str,
68 report_name: str,
69 report_description: str,
70 html: str,
71 text: str,
72 priority: AppReportPriority,
73 report_error: str | None = None,
74 ) -> ReportEmailSchema:
76 return ReportEmailSchema(
77 report_name=report_name,
78 html_report=html,
79 text_report=text,
80 report_description=report_description,
81 report_date=report_date,
82 report_errors=report_error if report_error is not None else "N/A",
83 priority=priority.value.upper(),
84 )
86 @override
87 def newline_fields(self) -> list[str]:
88 return ["report_description", "report_errors"]
90 @property
91 @override
92 def data(self) -> ReportEmailSchema:
93 assert isinstance(self._data, dict) # narrowing, we known we have a dict..
94 return self._data
96 @property
97 def report_date(self) -> str:
98 return self.data["report_date"]
100 @property
101 def report_error(self) -> str | None:
102 return self.data["report_errors"]
104 @property
105 def report_name(self) -> str:
106 return self.data["report_name"]
108 @property
109 def report_description(self) -> str:
110 return self.data["report_description"]