【问题标题】:Authentication failed in Django testDjango 测试中的身份验证失败
【发布时间】:2015-08-18 22:40:18
【问题描述】:

在 Django 中,我尝试创建一个用户,然后尝试使用 selenium 登录该用户,但是当我运行测试失败时,它显示身份验证错误。这是我的代码:

class LoginFunctionalTest(unittest.TestCase):

    def setUp(self):
        self.browser = webdriver.Firefox()
        self.browser.implicitly_wait(3)
        # self.browser.get('http://localhost:8000')

    def tearDown(self):
        self.browser.quit()

    def test_login_page(self):
        self.browser.get('http://localhost:8000')

        self.assertIn('Hiren->Login', self.browser.title)

    def test_login_form(self):
        self.browser.get('http://localhost:8000')
        user = User.objects.create_user('testHiren', 'myemail@test.com', 'testPass')
        user.save()
        username = self.browser.find_element_by_id('username-id')
        password = self.browser.find_element_by_id('password-id')
        submit = self.browser.find_element_by_id('login-button')
        username.send_keys('testHiren')
        password.send_keys('testPass')
        submit.click()
        time.sleep(10) # if authentication successful its redirects to /dashboard
        location = self.browser.current_url
        self.assertEqual('http://localhost:8000/dashboard', location)

知道为什么会失败吗?

【问题讨论】:

  • 发生了什么?有任何错误信息吗?
  • 它显示来自浏览器登录方法的标准身份验证错误消息(用户名/密码不正确)。

标签: python django django-testing


【解决方案1】:

所以我发现这个 FN 测试使用的是默认数据库而不是测试数据库,所以我改变了流程

【讨论】:

  • 你改变了什么“流程”?这个答案没有帮助。
猜你喜欢
  • 2022-01-04
  • 1970-01-01
  • 2022-01-11
  • 2016-05-09
  • 1970-01-01
  • 2011-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多