Authentication failed in Django test

懵懂的女人 提交于 2019-12-13 06:38:34

问题


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 ?


回答1:


So I just figured it out this FN test is using default database rather then test database, so I changed the flow



来源:https://stackoverflow.com/questions/30641806/authentication-failed-in-django-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!