【发布时间】:2018-10-11 23:31:19
【问题描述】:
我正在尝试为受Django Two-Factor Authentication 保护的网站编写LiveServerTestCase。到目前为止我所拥有的是:
import os
from urllib.parse import urljoin
from django.urls import reverse
from django.conf import settings
from lucy_web.test_factories import UserFactory
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
chromedriver_path = os.path.join(os.path.dirname(os.path.dirname(settings.BASE_DIR)), 'chromedriver')
assert os.path.isfile(chromedriver_path), f"There should be a chromedriver executable at {chromedriver_path}"
class SeleniumTest(StaticLiveServerTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.driver = webdriver.Chrome(chromedriver_path)
cls.password = 'foobar' # Set the password here to avoid using the hashed attribute
cls.user = UserFactory(password=cls.password, is_superuser=True)
def test_login(self):
url = urljoin(self.live_server_url, reverse('dashboard:families'))
self.driver.get(url)
self.driver.find_element_by_name('auth-username').send_keys(self.user.username)
self.driver.find_element_by_name('auth-password').send_keys(self.password)
self.driver.find_element_by_xpath('//input[@value="Next"]').click()
问题是,此时,驱动程序到达一个需要扫描二维码的双重身份验证登录页面:
使用测试浏览器太复杂了,所以我想使用override_settings 禁用两因素身份验证以进行测试。但是,查看 Django 双重身份验证的General Settings,我找不到禁用它的设置。
有什么方法可以禁用双因素身份验证以继续此实时服务器测试用例?
【问题讨论】:
标签: django selenium two-factor-authentication