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