class LoginUserTest(APITestCase):
def setUp(self):
self.data = {'email':'[email protected]','account':'tester','username':'testuser','password':'popk1214',}
self.user = User.objects.create_user('[email protected]','tester', 'testuser','popk1214')
def test_login(self):
response = self.client.post(reverse('token_obtain_pair'), self.data)
self.assertEqual(response.status_code, 200)
# 사용자 정보 가져오는 테스트
def test_get_user_data(self):
access_token = self.client.post(reverse('token_obtain_pair'), self.data).data['access']
response = self.client.get(
path=reverse("user_view"),
HTTP_AUTHORIZATION=f"Bearer {access_token}"
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['account'], self.data['account'])
# self.data는 34번째줄에서 셋업 데이터를 의미함.