1515
1616@unittest .skipIf (os .getenv ("SKIP_HTTP_CASE" ), "TestFastapiLogMail skipped" )
1717class TestFastapiLogMail (Common , MailCase ):
18- @classmethod
19- def setUpClass (cls ):
20- super ().setUpClass ()
21- cls .fastapi_demo_app .api_log_mail_exception_activity_type_id = cls .env [
18+ def _set_mail_exception_activity_type (self , app ):
19+ app .api_log_mail_exception_activity_type_id = app .env [
2220 "mail.activity.type"
2321 ].create (
2422 {
2523 "name" : "Test exception activity type" ,
2624 "res_model" : "api.log" ,
2725 }
2826 )
29- cls . fastapi_demo_app . api_log_mail_exception_template_id = cls . env [
30- "mail.template"
31- ].create (
27+
28+ def _set_mail_exception_template ( self , app ):
29+ app . api_log_mail_exception_template_id = app . env [ "mail.template" ].create (
3230 {
3331 "name" : "Test exception email template" ,
34- "model_id" : cls .env .ref ("api_log.model_api_log" ).id ,
32+ "model_id" : app .env .ref ("api_log.model_api_log" ).id ,
3533 }
3634 )
3735
@@ -40,7 +38,8 @@ def test_endpoint_exception_create_activity(self):
4038 when an exception occurs an activity of the configured type is created.
4139 """
4240 # Arrange
43- app = self .fastapi_demo_app
41+ app = self ._get_log_env_records (self .fastapi_demo_app )
42+ self ._set_mail_exception_activity_type (app )
4443 activity_type = app .api_log_mail_exception_activity_type_id
4544 route = (
4645 "/fastapi_demo/test/demo/exception?"
@@ -65,7 +64,8 @@ def test_endpoint_exception_send_email(self):
6564 when an exception occurs an email is sent using the configured template.
6665 """
6766 # Arrange
68- app = self .fastapi_demo_app
67+ app = self ._get_log_env_records (self .fastapi_demo_app )
68+ self ._set_mail_exception_template (app )
6969 mail_template = app .api_log_mail_exception_template_id
7070 route = (
7171 "/fastapi_demo/test/demo/exception?"
0 commit comments