diff --git a/DRF_simplejwt/settings.py b/DRF_simplejwt/settings.py index 1cac7fe..89e4b92 100644 --- a/DRF_simplejwt/settings.py +++ b/DRF_simplejwt/settings.py @@ -175,6 +175,12 @@ 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', ), + 'DEFAULT_PARSER_CLASSES': [ + 'rest_framework.parsers.JSONParser', + 'rest_framework.parsers.FormParser', + 'rest_framework.parsers.MultiPartParser' + ], + 'TEST_REQUEST_DEFAULT_FORMAT': 'json', } PASSWORD_HASHERS = [ diff --git a/users/serializers.py b/users/serializers.py index 08eddd4..77bbdb5 100644 --- a/users/serializers.py +++ b/users/serializers.py @@ -5,7 +5,6 @@ from rest_framework import serializers from rest_framework.serializers import ModelSerializer from rest_framework_simplejwt.serializers import TokenObtainPairSerializer -from rest_framework_simplejwt.tokens import OutstandingToken, BlacklistedToken from users.models import User @@ -49,9 +48,6 @@ def validate(self, data): if not check_password(password, user.password): raise serializers.ValidationError('detail : invalid password') - - for token in OutstandingToken.objects.filter(user=user): - BlacklistedToken.objects.get_or_create(token=token) token = super().get_token(user) refresh_token = str(token) diff --git a/users/tests.py b/users/tests.py index 7ce503c..f80bc8a 100644 --- a/users/tests.py +++ b/users/tests.py @@ -1,3 +1,56 @@ -from django.test import TestCase +import json -# Create your tests here. +from rest_framework.test import APITestCase +from rest_framework_simplejwt.tokens import OutstandingToken + +from users.models import User + +class UserSignUpTest(APITestCase): + + maxDiff = None + + def test_success_user_signup(self): + data = { + 'email' : 'DGK-test-01@gmail.com', + 'nickname' : 'DGK-01', + 'password' : 'DGK12345678' + } + + response = self.client.post('/users/signup', data=json.dumps(data), content_type='application/json') + + self.assertEqual(response.status_code, 201) + self.assertEqual( + response.data, + { + 'email' : 'DGK-test-01@gmail.com', + 'nickname' : 'DGK-01' + } + ) + + +class UserSignInTest(APITestCase): + + maxDiff = None + + @classmethod + def setUpTestData(cls): + User.objects.create_user( + email = 'DGK-test@gmail.com', + nickname = 'DGK01', + password = 'DGK12345678' + ) + + def test_success_user_signin(self): + data = { + 'email' : 'DGK-test@gmail.com', + 'nickname' : 'DGK01', + 'password' : 'DGK12345678' + } + + response = self.client.post('/users/signin', data=json.dumps(data), content_type='application/json') + + user = User.objects.get(email='DGK-test@gmail.com') + token = OutstandingToken.objects.get(user=user).token + + self.assertEqual(response.status_code, 200) + self.assertEqual(token, response.json()['refresh']) \ No newline at end of file diff --git a/users/urls.py b/users/urls.py index 4bcd07e..db08f5d 100644 --- a/users/urls.py +++ b/users/urls.py @@ -7,6 +7,6 @@ path('/signup', UserSignUpView.as_view()), path('/signin', UserSignInView.as_view()), path('/signout', UserSignOutView.as_view()), - path('/auth', UserinfoView.as_view()), + path('/auth-info', UserinfoView.as_view()), path('/token/refresh', TokenRefreshView.as_view()), ] diff --git a/users/views.py b/users/views.py index 037cf7d..fea3041 100644 --- a/users/views.py +++ b/users/views.py @@ -6,7 +6,6 @@ from drf_yasg import openapi from drf_yasg.utils import swagger_auto_schema -from users.models import User from users.serializers import SignUpSerializer, SignInSerializer class UserSignUpView(APIView):