集成测试 Django All-Auth 电子邮件确认
Integration Testing Django All-Auth Email Confirmation
我想做一些集成测试,但我不知道应该如何测试注册过程的电子邮件确认位。
我的用户故事(基本上)是一个新访问者来到该网站,决定他们想要注册,确认他们的电子邮件地址,然后被重定向到他们闪亮的新个人资料。
我如何模拟点击电子邮件中的 link 以重定向到用户个人资料?
我目前正在使用 Selenium 进行我的 functional/integration 测试,并在一定程度上使用 django 测试套件。
您应该查找 python 阅读电子邮件的方法。
步骤:
- 查找电子邮件
- 存储 link
- 启动你的 selenium 测试,然后打开 link
- 验证您在页面上
这两个文档页面包含您需要的一切:
- https://docs.djangoproject.com/en/1.10/topics/testing/overview/
- https://docs.djangoproject.com/en/1.10/topics/testing/tools/#email-services
一个简单的例子:
from django.test import TestCase
from django.core import mail
class EmailTestCase(TestCase):
def setUp(self):
## Do something
pass
def test_email_content(self):
## Do something that triggers an email.
## Check the number of emails.
print(len(mail.outbox))
## Check the content of the first email.
first_email = mail.outbox[0]
if first_email:
print(first_email.body)
我想做一些集成测试,但我不知道应该如何测试注册过程的电子邮件确认位。
我的用户故事(基本上)是一个新访问者来到该网站,决定他们想要注册,确认他们的电子邮件地址,然后被重定向到他们闪亮的新个人资料。
我如何模拟点击电子邮件中的 link 以重定向到用户个人资料?
我目前正在使用 Selenium 进行我的 functional/integration 测试,并在一定程度上使用 django 测试套件。
您应该查找 python 阅读电子邮件的方法。
步骤:
- 查找电子邮件
- 存储 link
- 启动你的 selenium 测试,然后打开 link
- 验证您在页面上
这两个文档页面包含您需要的一切:
- https://docs.djangoproject.com/en/1.10/topics/testing/overview/
- https://docs.djangoproject.com/en/1.10/topics/testing/tools/#email-services
一个简单的例子:
from django.test import TestCase
from django.core import mail
class EmailTestCase(TestCase):
def setUp(self):
## Do something
pass
def test_email_content(self):
## Do something that triggers an email.
## Check the number of emails.
print(len(mail.outbox))
## Check the content of the first email.
first_email = mail.outbox[0]
if first_email:
print(first_email.body)