Skip to content

Commit

Permalink
Add test for deleted users.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay09 committed Jun 14, 2024
1 parent dbb5695 commit 300a5b7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.contrib.auth import get_user_model
from django.test import TestCase
from rest_framework import exceptions as drf_exceptions
from django.core import exceptions as django_exceptions

from rest_framework_simplejwt.exceptions import TokenError
from rest_framework_simplejwt.serializers import (
Expand Down Expand Up @@ -256,6 +257,18 @@ def setUp(self):
password=self.password,
)

def test_it_should_raise_error_for_deleted_users(self):
refresh = RefreshToken.for_user(self.user)
self.user.delete()

s = TokenRefreshSerializer(data={"refresh": str(refresh)})

with self.assertRaises(django_exceptions.ObjectDoesNotExist) as e:
s.is_valid()

self.assertIn("does not exist", str(e.exception))


def test_it_should_raise_error_for_inactive_users(self):
refresh = RefreshToken.for_user(self.user)
self.user.is_active = False
Expand Down

0 comments on commit 300a5b7

Please sign in to comment.