Coverage for functions \ flipdare \ mailer \ admin \ command_email.py: 68%

25 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 

13from typing import override 

14from flipdare.mailer.app_email_params import AppEmailParams 

15from flipdare.mailer.app_email_type import AppEmailType 

16from flipdare.generated.schema.email.subject.admin.command_subject_schema import ( 

17 CommandSubjectSchema, 

18) 

19from flipdare.result.outcome import Outcome 

20from flipdare.mailer._jinja_email_template import JinjaEmailTemplate 

21from flipdare.generated.schema.email.body.admin.command_email_schema import CommandEmailSchema 

22 

23__all__ = ["CommandEmail"] 

24 

25 

26class CommandEmail(JinjaEmailTemplate[CommandEmailSchema]): 

27 __slots__ = ("_subject",) 

28 

29 SCHEMA_CLASS = CommandEmailSchema 

30 

31 def __init__( 

32 self, 

33 command_date: str, 

34 command_name: str, 

35 description: str, 

36 message: str, 

37 ex_error: Exception | None = None, 

38 ) -> None: 

39 data = CommandEmailSchema( 

40 command_date=command_date, 

41 command_name=command_name, 

42 command_description=description, 

43 message=message, 

44 ) 

45 

46 if ex_error is not None: 

47 data["exception_message"] = str(ex_error) 

48 

49 outcome = Outcome.ERROR if ex_error else Outcome.OK 

50 super().__init__( 

51 data=data, 

52 params=AppEmailParams( 

53 email_type=AppEmailType.ADM_TYPESENSE_REPORT, 

54 schema=CommandSubjectSchema( 

55 command=command_name, 

56 report_name=command_name, 

57 report_date=command_date, 

58 outcome=outcome.value, 

59 ), 

60 ), 

61 ) 

62 

63 @override 

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

65 return ["command_description", "message", "exception_message"] 

66 

67 @property 

68 @override 

69 def data(self) -> CommandEmailSchema: 

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

71 return self._data