Django: test failing on a view with @login_required

后端 未结 3 1878
梦谈多话
梦谈多话 2020-12-13 20:56

I\'m trying to build a test for a view that\'s decorated with @login_required, since I failed to make it work, I did a simple test and still can\'t make it pass.

Her

3条回答
  •  没有蜡笔的小新
    2020-12-13 21:36

    OK I was to facing same problem @resto solved my problem.

    creating user this way below, lets the test client get the user logged in and get the response other than redirect (302)

    self.user = User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')
    

提交回复
热议问题