问题描述
我已经在 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 测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)