7
7
8
8
9
9
class TestEmailService :
10
- def test_send_creates_email_message (self , email_service , pyramid_mailer ):
11
- email = EmailData (
12
-
13
- subject = "My email subject" ,
14
- body = "Some text body" ,
15
- tag = EmailTag .TEST ,
16
- )
17
- email_service .send (email )
10
+ def test_send_creates_email_message (
11
+ self , email_data , log_data , email_service , pyramid_mailer
12
+ ):
13
+ email_service .send (email_data , log_data )
18
14
19
15
pyramid_mailer .message .Message .assert_called_once_with (
20
16
@@ -25,16 +21,16 @@ def test_send_creates_email_message(self, email_service, pyramid_mailer):
25
21
)
26
22
27
23
def test_send_creates_email_message_with_html_body (
28
- self , email_service , pyramid_mailer
24
+ self , log_data , email_service , pyramid_mailer
29
25
):
30
- email = EmailData (
26
+ email_data = EmailData (
31
27
32
28
subject = "My email subject" ,
33
29
body = "Some text body" ,
34
30
tag = EmailTag .TEST ,
35
31
html = "<p>An HTML body</p>" ,
36
32
)
37
- email_service .send (email )
33
+ email_service .send (email_data , log_data )
38
34
39
35
pyramid_mailer .message .Message .assert_called_once_with (
40
36
@@ -45,41 +41,25 @@ def test_send_creates_email_message_with_html_body(
45
41
)
46
42
47
43
def test_send_dispatches_email_using_request_mailer (
48
- self , email_service , pyramid_mailer
44
+ self , email_data , log_data , email_service , pyramid_mailer
49
45
):
50
46
request_mailer = pyramid_mailer .get_mailer .return_value
51
47
message = pyramid_mailer .message .Message .return_value
52
48
53
- email = EmailData (
54
-
55
- subject = "My email subject" ,
56
- body = "Some text body" ,
57
- tag = EmailTag .TEST ,
58
- )
59
- email_service .send (email )
49
+ email_service .send (email_data , log_data )
60
50
61
51
request_mailer .send_immediately .assert_called_once_with (message )
62
52
63
- def test_raises_smtplib_exception (self , email_service , pyramid_mailer ):
53
+ def test_raises_smtplib_exception (
54
+ self , email_data , log_data , email_service , pyramid_mailer
55
+ ):
64
56
request_mailer = pyramid_mailer .get_mailer .return_value
65
57
request_mailer .send_immediately .side_effect = smtplib .SMTPException ()
66
58
67
- email = EmailData (
68
-
69
- subject = "My email subject" ,
70
- body = "Some text body" ,
71
- tag = EmailTag .TEST ,
72
- )
73
59
with pytest .raises (smtplib .SMTPException ):
74
- email_service .send (email )
60
+ email_service .send (email_data , log_data )
75
61
76
- def test_send_logging (self , email_service , info_caplog ):
77
- email_data = EmailData (
78
-
79
- subject = "My email subject" ,
80
- body = "Some text body" ,
81
- tag = EmailTag .TEST ,
82
- )
62
+ def test_send_logging (self , email_service , info_caplog , email_data ):
83
63
user_id = 123
84
64
annotation_id = "annotation_id"
85
65
log_data = LogData (
@@ -94,6 +74,23 @@ def test_send_logging(self, email_service, info_caplog):
94
74
f"Sent email: tag={ email_data .tag !r} , sender_id={ user_id } , recipient_ids=[{ user_id } ], annotation_id={ annotation_id !r} "
95
75
]
96
76
77
+ @pytest .fixture
78
+ def email_data (self ):
79
+ return EmailData (
80
+
81
+ subject = "My email subject" ,
82
+ body = "Some text body" ,
83
+ tag = EmailTag .TEST ,
84
+ )
85
+
86
+ @pytest .fixture
87
+ def log_data (self ):
88
+ return LogData (
89
+ sender_id = 123 ,
90
+ tag = EmailTag .TEST ,
91
+ recipient_ids = [456 ],
92
+ )
93
+
97
94
@pytest .fixture
98
95
def pyramid_request (self , pyramid_request ):
99
96
pyramid_request .debug = False
0 commit comments