In my unit test, I have the following code, where I’ve to generate a new token every time I need to run the test.
I want to provide some mock token which also means I need to mock the token validation as well. But I’m not sure how to mock the validation.
If I can get any help on this, it would be great. Thanks
Settings
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTStatelessUserAuthentication',
],
Testcase
from apps.common.helpers import get_auth0_access_token
class TestDatasetListTestCase(APITestCase):
def setUp(self):
options = {
"url": f"https://{auth0_domain}/oauth/token",
"headers": {"cache-control": "no-cache", "content-type": "application/json"},
"json": {"audience": audience, "grant_type": grant_type, "client_id":
client_id, "client_secret": client_secret},
}
res = requests.post(**options)
res_json = res.json()
access_token = res_json["access_token"]
self.client.credentials(HTTP_AUTHORIZATION=f"Bearer {access_token}")
payload = {"label": "new_label"}
response = self.client.post(self.url, payload, format="multipart")