带有基于文件的电子邮件后端服务器的 Django 测试框架 [英] Django Test framework with file based Email backend server

查看:16
本文介绍了带有基于文件的电子邮件后端服务器的 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 测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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