Using Basic HTTP access authentication in Django testing framework

前端 未结 6 1456
栀梦
栀梦 2020-12-08 01:41

For some of my Django views I\'ve created a decorator that performs Basic HTTP access authentication. However, while writing test cases in Django, it took me a while to wor

6条回答
  •  死守一世寂寞
    2020-12-08 02:40

    Assuming I have a login form, I use the following technique to login through the test framework:

        client = Client()
        client.post('/login/', {'username': 'john.smith', 'password': 'secret'})
    

    I then carry the client around in my other tests since it's already authenticated. What is your question to this post?

提交回复
热议问题