I'm using django rest framework for exposing an api and django oauth toolkit for authentication. So after writing a custom ModelBackend and relevant unit tests, I was trying to write some integration tests too, to verify the endpoint using this backend is returning an access token for some scenarios..
I'm using drf APIClient for making test requests and works great for everything else, but in this I case I'm getting {"error": "unsupported_grant_type"} when I do:
from requests.auth import _basic_auth_str
from rest_framework.test import APIClient
client = APIClient()
client.credentials(HTTP_AUTHORIZATION=_basic_auth_str(CLIENT_ID, CLIENT_SECRET))
client.post(
'/oauth2/token/',
{'grant_type': 'password', 'username': 'user1', 'password': 'pass1'},
content_type='application/x-www-form-urlencoded'
)
Any ideas?