Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix amazon_ses inbound email ESP provider #3509

Merged
merged 17 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions engine/apps/email/tests/test_inbound_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest, anymail
from apps.email.inbound import InboundEmailWebhookView
from django.test.client import RequestFactory

@pytest.mark.django_db
def test_amazon_ses_provider_load(
settings
):
result = False

settings.INBOUND_EMAIL_ESP = "amazon_ses"
rf = RequestFactory()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest looking into the rest_framework.test.APIClient instead here (we have many examples throughout the tests in the codebase).

With APIClient you will actually be invoking the post handler that raises the exception according to the stack trace in the issue description in #3508


inbound_view = InboundEmailWebhookView()
try:
inbound_view.post(rf.post('/fake-mock-location'))
result = True
except anymail.exceptions.AnymailAPIError:
# We don't test anymail, but it's invocation ability
result = True
assert result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on an aside, if you would like to assert that an exception is raised, you can do something like this 🙂

with pytest.raises(anymail.exceptions.AnymailAPIError):
        inbound_view.post(rf.post('/fake-mock-location'))

From the pytest docs:

Assert that a code block/function call raises expected_exception or raise a failure exception otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I think now it looks better😅

1 change: 1 addition & 0 deletions engine/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ opentelemetry-exporter-otlp-proto-grpc==1.15.0
django-dbconn-retry==0.1.7
django-ipware==4.0.2
django-anymail==8.6
django-amazon-ses==4.0.1
django-deprecate-fields==0.1.1
pymdown-extensions==10.0
requests==2.31.0
Expand Down
Loading