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

查看:192
本文介绍了与基于文件的电子邮件后端服务器Django的测试框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制定Django框架测试用例。

使用案例:
我使用的是通过发送电子邮件注册用户和API,当他们点击邮件中他们的帐户激活提供的链接。

在我的settings.py我使用

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

指向本地目录。

在运行的PyUnit测试情况下,从日食一切工作的文件。文本文件被每个发送的电子邮件生成

但是,当我使用

 蟒蛇./manage.py测试<&COMPONENT_NAME GT;

文件不生成。

任何有识之士的区别是什么,当我与 ./ manage.py 键,当我使用的PyUnit ?


解决方案

答案很简单:

您不能没有工程您自己的电子邮件系统做到这一点,但是这很可能将是愚蠢的。我建议做别的事情,以验证code是成功的,而无需电子邮件发送。像,运行code,假设用户点击该链接并创建RequestFactory到GET / POST运行与它相关的视图code的连接。

Django的测试应用程序


  

电邮服务

 如果您的任何意见的Django使用Django的电子邮件功能发送电子邮件,
你可能不希望每次发送电子邮件您使用的运行测试
视图。出于这个原因,Django的测试运行器会自动重定向所有
Django的电子邮件发送给一个虚拟的发件箱。这可以让你测试的每一个环节
发送电​​子邮件 - 从发送到每个内容的消息数
消息 - 无需实际发送邮件。


I have formulated test cases in Django framework.

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.

In my settings.py I am using

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

which points to the local directory.

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

But, When i am using

python ./manage.py test <component_name>

the files does not generate.

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

解决方案

The simple answer:

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.

From the Django Testing Application:

Email services

"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天全站免登陆