Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[김동규] 회원가입, 로그인, 로그아웃 테스트 코드 작성 #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DRF_simplejwt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
4 changes: 0 additions & 4 deletions users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
57 changes: 55 additions & 2 deletions users/tests.py
Original file line number Diff line number Diff line change
@@ -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'])
2 changes: 1 addition & 1 deletion users/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]
1 change: 0 additions & 1 deletion users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down