Coverage for functions \ flipdare \ task \ report \ core \ cron_report.py: 100%

0 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# pragma: no cover 

14# NOTE: this is currently unused, but may be required in the future 

15 

16from typing import Any, override 

17from flipdare.result.output_result import OutputResult 

18from flipdare.mailer._jinja_email_template import JinjaEmailTemplate 

19from flipdare.mailer.admin.cron_email import CronEmail 

20from flipdare.mailer.core.table_email_formatter import ExtraEmailInfo 

21from flipdare.task.report.core._admin_report import AdminReport 

22from flipdare.backend.app_logger import AppLogger 

23from flipdare.app_types import ReportListType 

24from flipdare.mailer.core.email_composer import EmailComposer 

25from flipdare.mailer.admin_mailer import AdminMailer 

26from flipdare.generated.shared.backend.app_job_type import AppJobType 

27 

28 

29class CronReport(AdminReport): 

30 __slots__ = ( 

31 "_cron_date", 

32 "_extra", 

33 "_headers", 

34 "_message", 

35 "_table_data", 

36 ) 

37 

38 def __init__( 

39 self, 

40 job_type: AppJobType, 

41 cron_date: str, 

42 message: str, 

43 table_data: ReportListType, 

44 headers: list[str], 

45 app_logger: AppLogger, 

46 mailer: AdminMailer, 

47 extra: ExtraEmailInfo | None = None, 

48 ) -> None: 

49 super().__init__( 

50 job_type=job_type, 

51 app_logger=app_logger, 

52 mailer=mailer, 

53 ) 

54 self._table_data = table_data 

55 self._headers = headers 

56 self._extra = extra 

57 self._cron_date = cron_date 

58 self._message = message 

59 

60 @property 

61 def cron_date(self) -> str: 

62 return self._cron_date 

63 

64 @property 

65 def message(self) -> str: 

66 return self._message 

67 

68 @override 

69 def compose(self) -> EmailComposer | None: 

70 try: 

71 return EmailComposer.table( 

72 data=self._table_data, 

73 headers=self._headers, 

74 priority=self.priority, 

75 extra=self._extra, 

76 ) 

77 except Exception as ex: 

78 msg = f"Failed to generate report for {self._debug_label}\tError: {ex}" 

79 self.add_error(msg) 

80 return None 

81 

82 @override 

83 def build_template(self) -> JinjaEmailTemplate[Any] | OutputResult: 

84 result = self.try_compose() 

85 if isinstance(result, OutputResult): 

86 return result 

87 

88 return CronEmail( 

89 cron_date=self.cron_date, 

90 job_type=self.job_type, 

91 message=self.message, 

92 html=result.html, 

93 text=result.text, 

94 priority=self.priority.value, 

95 errors=self.errors or None, 

96 )