問題描述
我已經在 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模板網!