-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/weaverse-techtide/weaverse-b…
…ackend into yujeong/materials
- Loading branch information
Showing
9 changed files
with
183 additions
and
53 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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import pytest | ||
from rest_framework.test import APIClient | ||
from rest_framework import status | ||
from django.utils import timezone | ||
from django.urls import reverse | ||
from datetime import timedelta | ||
|
||
import jwt | ||
import pytest | ||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
|
||
from jwtauth.models import BlacklistedToken | ||
from jwtauth.utils.token_generator import generate_access_token, generate_refresh_token | ||
|
||
User = get_user_model() | ||
from accounts.models import CustomUser as User | ||
|
||
|
||
@pytest.fixture | ||
|
@@ -57,12 +53,12 @@ def test_로그인_성공(api_client, user): | |
# Given: 유효한 사용자 정보가 있음 | ||
# When: 로그인 API에 POST 요청을 보냄 | ||
response = api_client.post( | ||
"/api/login/", {"email": "[email protected]", "password": "testpass123"} | ||
reverse("login"), {"email": "[email protected]", "password": "testpass123"} | ||
) | ||
# Then: 응답 상태 코드가 200이고, 액세스 토큰과 리프레시 토큰이 포함되어 있음 | ||
assert response.status_code == status.HTTP_200_OK | ||
assert "access_token" in response.data | ||
assert "refresh_token" in response.data | ||
assert "refresh_token" in response.cookies | ||
|
||
|
||
@pytest.mark.django_db | ||
|
@@ -71,7 +67,7 @@ def test_로그인_실패(api_client): | |
# Given: 잘못된 사용자 정보가 있음 | ||
# When: 로그인 API에 잘못된 정보로 POST 요청을 보냄 | ||
response = api_client.post( | ||
"/api/login/", {"email": "[email protected]", "password": "wrongpass"} | ||
reverse("login"), {"email": "[email protected]", "password": "wrongpass"} | ||
) | ||
# Then: 응답 상태 코드가 401 (Unauthorized)임 | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||
|
@@ -83,7 +79,7 @@ def test_로그아웃_성공(api_client, user, refresh_token): | |
# Given: 인증된 사용자와 유효한 리프레시 토큰이 있음 | ||
api_client.force_authenticate(user=user) | ||
# When: 로그아웃 API에 리프레시 토큰과 함께 POST 요청을 보냄 | ||
response = api_client.post("/api/logout/", {"refresh_token": refresh_token}) | ||
response = api_client.post(reverse("logout"), {"refresh_token": refresh_token}) | ||
# Then: 응답 상태 코드가 200이고, 리프레시 토큰이 블랙리스트에 추가됨 | ||
assert response.status_code == status.HTTP_200_OK | ||
assert BlacklistedToken.objects.filter(token=refresh_token).exists() | ||
|
@@ -95,7 +91,7 @@ def test_로그아웃_실패_토큰없음(api_client, user): | |
# Given: 인증된 사용자가 있지만 리프레시 토큰이 없음 | ||
api_client.force_authenticate(user=user) | ||
# When: 로그아웃 API에 리프레시 토큰 없이 POST 요청을 보냄 | ||
response = api_client.post("/api/logout/", {}) | ||
response = api_client.post(reverse("logout"), {}) | ||
# Then: 응답 상태 코드가 400 (Bad Request)임 | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
|
||
|
@@ -105,7 +101,7 @@ def test_리프레시_토큰_갱신_성공(api_client, user, refresh_token): | |
"""리프레시 토큰 갱신 API를 테스트합니다.""" | ||
# Given: 유효한 리프레시 토큰이 있음 | ||
# When: 리프레시 API에 리프레시 토큰과 함께 POST 요청을 보냄 | ||
response = api_client.post("/api/refresh/", {"refresh_token": refresh_token}) | ||
response = api_client.post(reverse("refresh"), {"refresh_token": refresh_token}) | ||
# Then: 응답 상태 코드가 200이고, 새로운 액세스 토큰과 리프레시 토큰이 반환되며, 기존 리프레시 토큰이 블랙리스트에 추가됨 | ||
assert response.status_code == status.HTTP_200_OK | ||
assert "access_token" in response.data | ||
|
@@ -121,7 +117,7 @@ def test_리프레시_토큰_갱신_실패_블랙리스트(api_client, user, ref | |
token=refresh_token, user=user, token_type="refresh" | ||
) | ||
# When: 리프레시 API에 블랙리스트에 등록된 리프레시 토큰과 함께 POST 요청을 보냄 | ||
response = api_client.post("/api/refresh/", {"refresh_token": refresh_token}) | ||
response = api_client.post(reverse("refresh"), {"refresh_token": refresh_token}) | ||
# Then: 응답 상태 코드가 400 (Bad Request)임 | ||
assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
|
||
|
@@ -146,8 +142,8 @@ def test_JWT_인증_실패_만료된_토큰(api_client, user): | |
url = reverse("refresh") | ||
# When: 리프레시 API에 만료된 토큰과 함께 POST 요청을 보냄 | ||
response = api_client.post(url) | ||
# Then: 응답 상태 코드가 401 (Unauthorized)임 | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||
# Then: 응답 상태 코드가 403 (Forbidden)임 | ||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
|
||
|
||
@pytest.mark.django_db | ||
|
@@ -158,8 +154,8 @@ def test_JWT_인증_실패_유효하지_않은_토큰(api_client): | |
url = reverse("refresh") | ||
# When: 리프레시 API에 유효하지 않은 토큰과 함께 POST 요청을 보냄 | ||
response = api_client.post(url) | ||
# Then: 응답 상태 코드가 401 (Unauthorized)임 | ||
assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||
# Then: 응답 상태 코드가 403 (Forbidden)임 | ||
assert response.status_code == status.HTTP_403_FORBIDDEN | ||
|
||
|
||
@pytest.mark.django_db | ||
|
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,8 +1,10 @@ | ||
from django.urls import path | ||
from .views import LoginView, LogoutView, RefreshTokenView | ||
from .views import LoginView, LogoutView, RefreshTokenView, GoogleLogin | ||
|
||
|
||
urlpatterns = [ | ||
path("login/", LoginView.as_view(), name="login"), | ||
path("logout/", LogoutView.as_view(), name="logout"), | ||
path("refresh/", RefreshTokenView.as_view(), name="refresh"), | ||
path("social-login/google/", GoogleLogin.as_view(), name="google_login"), | ||
] |
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
Oops, something went wrong.