Prometheus Prometheus - 1 month ago 12
Python Question

Testing in Django Rest Framework, reproduce this curl request?

I am trying to run some testing for Django Rest Framework (links to testing) and reproduce this curl call:

curl -X POST -d "grant_type=password&username=<user_name>&password=<password>"

This is what I have tried:

def test_oauth2_token_for_user(self):
Test Django OAuth Toolkit and make a request for am access token.
self.client.credentials(HTTP_AUTHORIZATION='grant_type ' + "password&username=<user_name>&password=<password")
response ='/api/token/')

Could someone tell me where to start. I am unsure how to send the header
and format the URL with the username and password.


That's not a header. That's perfectly normal POST data, which - as the test client documentation shows - you can just pass in a dictionary as the second parameter to post.

response ='/api/token/',
       {'grant_type': 'password', 'username': username, 'password': password})