Coverage for postrfp/mail/factory.py: 64%
14 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-22 21:34 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-22 21:34 +0000
1"""
2Mailer factory for creating appropriate mailer implementations.
4Provides centralized mailer selection logic based on configuration.
5"""
7from postrfp import conf
8from postrfp.conf.settings import Mailer
9from postrfp.mail.protocol import MailerProtocol
12def get_mailer() -> MailerProtocol:
13 """
14 Factory function to get the appropriate mailer implementation.
16 Returns the correct mailer based on the application configuration:
17 - Mailer.postmark: Returns postmark module for production email delivery
18 - Mailer.logfile: Returns stub module for testing/development
20 Returns:
21 MailerProtocol: A mailer implementation that supports send_email()
22 """
23 match conf.CONF.mailer:
24 case Mailer.postmark:
25 from postrfp.mail import postmark
27 return postmark
28 case Mailer.logfile:
29 from postrfp.mail import stub
31 return stub
32 case _:
33 # Default to stub for safety
34 from postrfp.mail import stub
36 return stub