Skip to content

Commit

Permalink
🧪Failing Test : 사용자 로그인 테스트 케이스 #3
Browse files Browse the repository at this point in the history
- 로그인 정상 응답의 경우 토큰을 포함
- 등록되지 않은 사용자 혹은 잘못된 패스워드의 경우 400
  • Loading branch information
Chestnut90 committed Nov 15, 2023
1 parent 13126a2 commit a4791ed
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/users/tests/test_signin_view.py
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)

0 comments on commit a4791ed

Please sign in to comment.