使用生菜,如何验证从Django Web应用程序发送的邮件是否具有正确的内容? [英] Using lettuce, how can I verify that an email sent from a Django web application has the correct contents?

查看:108
本文介绍了使用生菜,如何验证从Django Web应用程序发送的邮件是否具有正确的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Django的Web应用程序,需要向用户发送确认电子邮件,以尝试更改注册的电子邮件地址。该功能已经实现,但旨在验证电子邮件内容的莴苣测试是失败的。

I have a Django-based web application that is required to send a confirmation email to the user on an attempt to change the registered email address. The functionality has been implemented, but the lettuce test intended to verify the contents of the email is failing.

要验证操作,我的计划是使用文件后端( EMAIL_BACKEND ='django.core.mail.backends.filebased.EmailBackend')然后验证我的生菜步骤中文件的内容。

To verify the operation, my plan was to use the file backend (EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend') then verify the contents of the file within my lettuce step.

运行正常(例如通过manage.py runserver),电子邮件文件按预期创建。当通过生菜(manage.py收获)运行时,网站似乎正在正确驱动(我正在使用Selenium驱动它),但没有生成电子邮件文件。

When running "normally" (e.g. via manage.py runserver), the email file is created as expected. When run via lettuce (manage.py harvest), the web site appears to be getting driven correctly (I'm using Selenium to drive it) but no email file is generated.

我错过了什么?有没有一些设置(例如在terrain.py文件中),我需要使用,因此在测试过程中也会使用文件后端?

What have I missed? Is there some setting (e.g. in the terrain.py file) I need to use so the file backend is also used during the test process?

推荐答案

您可以使用django docs django.core.mail.outbox / topics / testing /#email-servicesrel =nofollow> https://docs.djangoproject.com/en/dev/topics/testing/#email-services

You can use django.core.mail.outbox as described in django docs https://docs.djangoproject.com/en/dev/topics/testing/#email-services

from django.core import mail

assert len(mail.outbox) == 1
assert mail.outbox[0].subject == 'Subject here'

Lettuse使用 django.test。 utils.setup_test_environment 将覆盖电子邮件后端到locmem电子邮件后端。

Lettuse uses django.test.utils.setup_test_environment that overrides email backend to the locmem email backend.

这篇关于使用生菜,如何验证从Django Web应用程序发送的邮件是否具有正确的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆