Comments (3)
I take it back about my tests failing that was just me being wrong as the code should have been:
msg = self.generate_email()
msg.send()
status = msg.anymail_status
email_sent = self.create_sent_object(email_id=status.message_id)
I'll do a pull request about adding to the docs though. Is the override_settings line above the correct way or should I be doing something else?
from django-anymail.
Django does indeed substitute its own special email backend during testing, by default.
I had actually intended Anymail's TestBackend for testing Anymail itself, and hadn't been thinking about other apps trying to test their use of Anymail. (That's why the TestBackend isn't documented. And why it has that weird required TEST_SAMPLE_SETTING, which was part of testing setting overrides.)
But what you're trying to do makes perfect sense, and it would probably be good to clean up and document the TestBackend. You're using it correctly with @override_settings. The ANYMAIL_TEST_SAMPLE_SETTING has to be there (for now), but can be set to anything.
from django-anymail.
FYI, I just committed a change that would let you run your tests with Django's normal testing backend. The one change you'd need to make is to create an AnymailMessage, rather than a EmailMultiAlternatives, in your generate_email function.
With this update, the AnymailMessage now initializes anymail_status immediately, so you won't get an AttributeError on a missing anymail_status if Django's test backend processes the message instead of Anymail. The status.message_id will be None in this case, but hopefully your create_sent_object function is already handling a missing message_id (since that can also occur in production if, say, your ESP has an error).
(I'd still like to clean up and document Anymail's TestBackend, and will leave this issue open to cover that enhancement. But hopefully this change makes using the TestBackend less necessary in the common case.)
from django-anymail.
Related Issues (20)
- Support Brevo inbound
- "Package would be ignored" warnings from setuptools when building package HOT 2
- Sendgrid multiple reply to HOT 1
- Can't lock with poetry HOT 2
- [Inbound] Apple Mail inline attachments not taken into account HOT 5
- Add support to Resend.com HOT 5
- Handlebars variables not substitued in mandrill templates HOT 1
- mailgun api key HOT 2
- Merging/Combine ESP Options get lost/overwritten HOT 2
- parse_address_list: Inability to Parse Email Addresses with Special Characters in Display Name Without Double-Quote Encapsulation HOT 1
- Mailjet Open tracking? HOT 4
- Inaccuracy in documentation about Brevo's behaviour HOT 2
- Feature request: Mailtrap HOT 4
- Resend: confusing ReadTimeout error for incorrect API key
- Add support to Unisender Go HOT 2
- Support Brevo batch sending with merge_data HOT 2
- Add batch sending support for Resend HOT 1
- Mailgun webhooks: AttributeError 'NoneType' object has no attribute 'get' HOT 1
- boto3 sesv2 client does not have method 'send_email'. Check AmazonSESV2SendEmailPayload HOT 4
- Bad UTF-8 "To" header encoding? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-anymail.