Skip to content

Commit 4d32389

Browse files
committed
Enhance testing
1 parent 34beba6 commit 4d32389

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

autosubmit/notifications/mail_notifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def notify_status_change(
208208
raise ValueError('mail_to must be a list of emails!')
209209
message_text = _generate_message_text(
210210
exp_id, job_name, prev_status, status)
211-
message = MIMEText(message_text)
211+
message = MIMEMultipart()
212212
message['From'] = email.utils.formataddr(
213213
('Autosubmit', self.config.MAIL_FROM))
214214
message['Subject'] = f'[Autosubmit] The job {job_name} status has changed to {status}'

test/unit/test_mail.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,32 +168,37 @@ def test_compress_file(
168168

169169

170170
@pytest.mark.parametrize(
171-
"sendmail_error, expected_log_message",
171+
"new_status, sendmail_error, expected_log_message",
172172
[
173173
# Normal case: No errors, should not log anything
174174
# No logs are expected, everything works fine
175-
(None, None),
175+
(Status.VALUE_TO_KEY[Status.FAILED], None, None),
176176
177177
# Log connection error: Simulate an error while sending email
178-
(Exception("SMTP server error"),
179-
'Trace:SMTP server error\nAn error has occurred while sending a mail for the job Job1')
178+
(Status.VALUE_TO_KEY[Status.FAILED], Exception("SMTP server error"),
179+
'Trace:SMTP server error\nAn error has occurred while sending a mail for the job Job1'),
180+
181+
# Job is now failing
182+
(Status.VALUE_TO_KEY[Status.COMPLETED], None, None)
180183
],
181184
ids=[
182185
"Normal case: No errors",
183-
"Log connection error (SMTP server error)"
186+
"Log connection error (SMTP server error)",
187+
"No notification needed"
184188
]
185189
)
186190
def test_notify_status_change(
187191
mock_basic_config,
188192
mock_smtp,
189193
mocker,
190194
mail_notifier,
195+
new_status,
191196
sendmail_error: Optional[Exception],
192197
expected_log_message):
193198
exp_id = 'a123'
194199
job_name = 'Job1'
195200
prev_status = Status.VALUE_TO_KEY[Status.RUNNING]
196-
status = Status.VALUE_TO_KEY[Status.COMPLETED]
201+
status = new_status
197202
mail_to = ['[email protected]']
198203

199204
mock_smtp = mocker.patch(

0 commit comments

Comments
 (0)