I've got a function to manually create a new AccessToken
for a user (using the rest_framework_simplejwt
library):
from rest_framework_simplejwt.tokens import AccessToken
def create_access_token_for_user(user):
access_token = AccessToken.for_user(user)
Now I'm trying to write a test to verify that this is actually working as expected, and I can't seem to find any way of getting the AccessToken
for a given user. The test should look something like:
def test_access_token_created(client):
user = create_user()
create_access_token_for_user(user)
access_token = AccessToken.get_token_for_user(user) # This, but real
assert access_token is not None # Or some check to see if it exists
The rest_framework_simplejwt docs don't seem to have anything that does this, or at least nothing that I've been able to use correctly.
I don't know the exact implementation behind the library, but usually JWT is stateless, which means that it isn't stored anywhere in your server (not in your database), so don't think of the AccessToken as a Model you could query on to find the related user or which token was generated for which user.
Also, it's usually unnecessary to test an external library, at least if it's popular. You can refer to the tests written by the developers, available in the official repository.