-
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.
- 로그인 정상 응답의 경우 토큰을 포함 - 등록되지 않은 사용자 혹은 잘못된 패스워드의 경우 400
- Loading branch information
1 parent
13126a2
commit a4791ed
Showing
1 changed file
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,56 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APITestCase | ||
|
||
|
||
class SignInAPITestCase(APITestCase): | ||
viewname = "signin" | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
# create user | ||
cls.username = "user" | ||
cls.password = "SNFae@12%" | ||
cls.user = get_user_model().objects.create(username=cls.username) | ||
cls.user.set_password(cls.password) | ||
cls.user.save() | ||
|
||
def test_matched_viewname(self): | ||
reverse(self.viewname) | ||
|
||
def test_signin_success(self): | ||
response = self.client.post( | ||
reverse(self.viewname), | ||
data={"username": self.username, "password": self.password}, | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
# response contain tokens | ||
self.assertIsNotNone(response.data.get("refresh", None)) | ||
self.assertIsNotNone(response.data.get("access", None)) | ||
|
||
def test_signin_unregistered_user(self): | ||
username = "user1" | ||
|
||
self.assertNotEqual(self.username, username) | ||
|
||
response = self.client.post( | ||
reverse(self.viewname), | ||
data={"username": username, "password": "asdfj"}, | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_signin_invalid_password(self): | ||
password = "asdfnsfdlj!@#9" | ||
|
||
self.assertNotEqual(self.password, password) | ||
|
||
response = self.client.post( | ||
reverse(self.viewname), | ||
data={"username": self.username, "password": password}, | ||
) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |