Giter Club home page Giter Club logo

Comments (3)

martinwarne avatar martinwarne commented on May 24, 2024

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.

medmunds avatar medmunds commented on May 24, 2024

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.

medmunds avatar medmunds commented on May 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.