带有基于文件的电子邮件后端服务器的 Django 测试框架

Django Test framework with file based Email backend server(带有基于文件的电子邮件后端服务器的 Django 测试框架)
本文介绍了带有基于文件的电子邮件后端服务器的 Django 测试框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我已经在 Django 框架中制定了测试用例.

I have formulated test cases in Django framework.

用例:我正在使用 API 通过向他们发送电子邮件来注册用户,当他们点击电子邮件中提供的链接时,他们的帐户就会被激活.

Use Case: I am using API that register user by sending them an Email and when they click on the link provided in the Email their account get activated.

在我的 settings.py 中我正在使用

In my settings.py I am using

EMAIL_FILE_PATH  ='django.core.mail.backends.filebased.EmailBackend'

指向本地目录.

从 Eclipse 运行 PyUnit 测试用例时,一切工作文件.为发送的每封电子邮件生成文本文件

When running PyUnit test case from eclipse everything works file. Text file gets generated for each email sent

但是,当我使用时

python ./manage.py test <component_name>

文件不会生成.

任何见解当我使用 ./manage.py 执行测试用例和使用 pyUnit 时有什么区别?

Any insight what is the difference when I execute test case with ./manage.py and when I use pyUnit ?

推荐答案

简单的答案:

如果不设计自己的电子邮件系统,就无法做到这一点,但这可能很愚蠢.我建议做其他事情来验证代码是否成功,而无需发送电子邮件.比如,运行代码,假设用户单击链接并创建 RequestFactory 来获取/发布链接以运行与其关联的视图代码.

You can't do this without engineering your own email system, but that would probably be silly. I would suggest doing something else to verify that the code was successful without requiring the email to be sent. Like, run the code, assume the user clicks the link and create RequestFactory to get/post the link to run the view code associated with it.

来自 Django 测试应用程序:

电子邮件服务

"If any of your Django views send email using Django's email functionality,
you probably don't want to send email each time you run a test using that
view. For this reason, Django's test runner automatically redirects all
Django-sent email to a dummy outbox. This lets you test every aspect of
sending email -- from the number of messages sent to the contents of each
message -- without actually sending the messages."

这篇关于带有基于文件的电子邮件后端服务器的 Django 测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

build conda package from local python package(从本地 python 包构建 conda 包)
How can I see all packages that depend on a certain package with PIP?(如何使用 PIP 查看依赖于某个包的所有包?)
How to organize multiple python files into a single module without it behaving like a package?(如何将多个 python 文件组织到一个模块中而不像一个包一样?)
Check if requirements are up to date(检查要求是否是最新的)
How to upload new versions of project to PyPI with twine?(如何使用 twine 将新版本的项目上传到 PyPI?)
Why #egg=foo when pip-installing from git repo(为什么从 git repo 进行 pip 安装时 #egg=foo)