-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨Feat : Login API 구현 및 confirm 관련 오류 수정
- login serializer, view, url 구현 - token refresh 생성 - JWT setting - user confirm관련 테스트 코드 오류 수정
- Loading branch information
Showing
6 changed files
with
161 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import json | ||
|
||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
|
||
from users.models import User | ||
|
||
|
||
class SignupViewTest(APITestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.confirmed_user = User.objects.create_user( | ||
email="testuser1@example.com", username="testusername1", password="testpassword", is_confirmed=True | ||
) | ||
cls.not_confirmed_user = User.objects.create_user( | ||
email="testuser2@example.com", username="testusername2", password="testpassword", is_confirmed=False | ||
) | ||
|
||
def test_post_login_success(self): | ||
response = self.client.post( | ||
path=reverse("login"), | ||
data=json.dumps( | ||
{ | ||
"username": "testusername1", | ||
"password": "testpassword", | ||
} | ||
), | ||
content_type="application/json", | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(self.confirmed_user.is_active, True) | ||
|
||
def test_post_login_fail_user_not_found(self): | ||
response = self.client.post( | ||
path=reverse("login"), | ||
data=json.dumps( | ||
{ | ||
"username": "testusername3", | ||
"password": "testpassword", | ||
} | ||
), | ||
content_type="application/json", | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
def test_post_login_fail_invalid_password(self): | ||
response = self.client.post( | ||
path=reverse("login"), | ||
data=json.dumps( | ||
{ | ||
"username": "testusername1", | ||
"password": "testpassword2", | ||
} | ||
), | ||
content_type="application/json", | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
def test_post_login_fail_not_confirmed_user(self): | ||
response = self.client.post( | ||
path=reverse("login"), | ||
data=json.dumps( | ||
{ | ||
"username": "testusername2", | ||
"password": "testpassword", | ||
} | ||
), | ||
content_type="application/json", | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
from django.urls import path | ||
from rest_framework_simplejwt.views import TokenRefreshView | ||
|
||
from users.views import ConfirmUserView, SignupView | ||
from users.views import ConfirmUserView, LoginView, SignupView | ||
|
||
urlpatterns = [path("signup/", SignupView.as_view(), name="signup"), path("confirm/", ConfirmUserView.as_view(), name="confirm")] | ||
urlpatterns = [ | ||
path("signup/", SignupView.as_view(), name="signup"), | ||
path("confirm/", ConfirmUserView.as_view(), name="confirm"), | ||
path("login/", LoginView.as_view(), name="login"), | ||
path("token/refresh/", TokenRefreshView.as_view(), name="token_refresh"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters