验证在Django测试中失败 [英] Authentication failed in Django test
本文介绍了验证在Django测试中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Django中,我尝试创建一个用户,然后尝试使用selenium登录该用户,但是当我运行测试失败时,它显示了身份验证错误。这是我的代码:
In Django I tried to create a user and then I tried to login that user using selenium , but when I run the test it failed , It was showing authentication error. Here is my code :
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)
任何想法为什么失败了?
Any idea why its failing ?
推荐答案
所以我才弄清楚这个FN测试是使用默认数据库而不是测试数据库,所以我改变了流量
So I just figured it out this FN test is using default database rather then test database, so I changed the flow
这篇关于验证在Django测试中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文