Skip to content

Commit 70f8176

Browse files
surajitsurajit
authored andcommitted
add tests for email exceptions
1 parent 905684a commit 70f8176

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
WELCOME_MESSAGE_TEMPLATE_ID = config("WELCOME_MESSAGE_TEMPLATE_ID")
2121
PAYMENT_CONFIRMATION_TEMPLATE_ID = config("WELCOME_MESSAGE_TEMPLATE_ID")
2222

23-
TEST_DATA_DIR = BASE_DIR.joinpath('tests/data')
23+
TEST_DATA_DIR = BASE_DIR.joinpath("tests/data")

tests/routes/test_email.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
from unittest import mock
33

4+
from email_api.email import UnauthorizedException, BadRequestException
45
from models.message import Message
56
from settings import TEST_DATA_DIR
67

@@ -29,3 +30,19 @@ def test_email_send(mock_send_email, client, db):
2930
assert message.message_type.value == "EMAIL"
3031
assert message.status_code == "202"
3132
assert message.carrier.value == "SENDGRID"
33+
34+
35+
@mock.patch("routes.v1.email.email.send_email")
36+
def test_email_send_with_sendgrid_unauthorizedexception(mock_send_email, client):
37+
mock_send_email.side_effect = UnauthorizedException("Not allowed to access the API")
38+
response = client.post("/api/v1/email/send/", json=read_json("email_data.json"))
39+
assert response.status_code == 200
40+
assert response.json() == {"detail": "Not allowed to access the API"}
41+
42+
43+
@mock.patch("routes.v1.email.email.send_email")
44+
def test_email_send_with_sendgrid_bad_request_exception(mock_send_email, client):
45+
mock_send_email.side_effect = BadRequestException("Bad request")
46+
response = client.post("/api/v1/email/send/", json=read_json("email_data.json"))
47+
assert response.status_code == 200
48+
assert response.json() == {"detail": "Bad request"}

0 commit comments

Comments
 (0)