Skip to content

Commit 859e834

Browse files
committed
Added a tests for coverage
1 parent cbb4e0b commit 859e834

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

tests/test_email.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from app.internal.email import mail
3+
from app.internal.email import mail, send_email_invitation, send_email_file
44
from fastapi import BackgroundTasks, status
55

66

@@ -153,15 +153,43 @@ def test_send_mail_valid_email(client, configured_smtpd):
153153
assert outbox
154154

155155

156-
def test_send_mail_bad_invitation(client, configured_smtpd):
156+
@pytest.mark.parametrize("sender_name,recipient_name,recipient_mail", [
157+
("", "other_person", "other@mail.com"),
158+
("us_person", "", "other@mail.com"),
159+
])
160+
def test_send_mail_bad_invitation(client, configured_smtpd, sender_name, recipient_name, recipient_mail):
157161
with mail.record_messages() as outbox:
158162
response = client.post("/email/invitation/", json={
159-
"sender_name": "",
160-
"recipient_name": "string",
161-
"recipient_mail": "test@mail.com"
163+
"sender_name": sender_name,
164+
"recipient_name": recipient_name,
165+
"recipient_mail": recipient_mail
162166
}
163167
)
164168
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
165169
assert response.json() == {
166170
"detail": "Couldn't send the email!"}
167171
assert not outbox
172+
173+
174+
@pytest.mark.parametrize("sender_name,recipient_name,recipient_mail", [
175+
("", "other_person", "other@mail.com"),
176+
("us_person", "", "other@mail.com"),
177+
("us_person", "other_person", "other#mail.com"),
178+
])
179+
def test_send_mail_bad_invitation_internal(client, configured_smtpd, sender_name, recipient_name, recipient_mail):
180+
background_task = BackgroundTasks()
181+
assert not send_email_invitation(sender_name, recipient_name, recipient_mail, background_task)
182+
183+
184+
@pytest.mark.parametrize("recipient_mail,file_path", [
185+
("other@mail.com", "non_existing_file"),
186+
("other#mail.com", __file__),
187+
])
188+
def test_send_mail_bad_file_internal(client, configured_smtpd, recipient_mail, file_path):
189+
background_task = BackgroundTasks()
190+
assert not send_email_file(file_path, recipient_mail, background_task)
191+
192+
193+
def test_send_mail_good_file_internal(client, configured_smtpd):
194+
background_task = BackgroundTasks()
195+
assert send_email_file(__file__, "good@mail.com", background_task)

0 commit comments

Comments
 (0)