Test utils¶
JWT allauth provides a custom JATestCase that simplifies the authentication process in your django tests.
Default user loaded in the database. The user info is defined in the
PASS,FIRST_NAMEandLAST_NAMEattributes. The user model object is available at theUSERattribute.Staff user loaded in the database. The user info is defined in the
STAFF_EMAIL,STAFF_PASS,STAFF_FIRST_NAMEandSTAFF_LAST_NAMEattributes. The user model object is available at theSTAFF_USERattribute.
JAClientclient accessible viaJATestCase.ja_clientproperty.
JSON content type automatically set.
Bearer access token configurable via the
access_tokenparameter in theget,post,patchandputmethods.
JATestCase.USERautomatic authentication through theauth_get,auth_post,auth_patchandauth_putmethods.
JATestCase.STAFF_USERautomatic authentication through thestaff_get,staff_post,staff_patchandstaff_putmethods.
Usage example¶
from jwt_allauth.test import JATestCase
from django.urls import reverse
class ExampleTest(JATestCase):
def test_patch_user_details(self):
payload = {"first_name": "other name"}
self.assertNotEqual(self.USER.first_name, payload["first_name"])
resp = self.ja_client.auth_patch(reverse("rest_user_details"), data=payload)
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.data["first_name"], payload["first_name"])