|
1 | 1 | import pytest
|
2 | 2 |
|
3 |
| -from app.internal.email import mail |
| 3 | +from app.internal.email import mail, send_email_invitation, send_email_file |
4 | 4 | from fastapi import BackgroundTasks, status
|
5 | 5 |
|
6 | 6 |
|
@@ -153,15 +153,43 @@ def test_send_mail_valid_email(client, configured_smtpd):
|
153 | 153 | assert outbox
|
154 | 154 |
|
155 | 155 |
|
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): |
157 | 161 | with mail.record_messages() as outbox:
|
158 | 162 | 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 |
162 | 166 | }
|
163 | 167 | )
|
164 | 168 | assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
|
165 | 169 | assert response.json() == {
|
166 | 170 | "detail": "Couldn't send the email!"}
|
167 | 171 | 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