Fakultas Ilmu Komputer UI

Verified Commit 0d102fc7 authored by Giovan Isa Musthofa's avatar Giovan Isa Musthofa
Browse files

[RED] Add tests for UserProfielView to get and put

parent 5ddfa789
Pipeline #38403 failed with stages
in 1 minute and 57 seconds
......@@ -3,6 +3,7 @@ from django.core import mail
from rest_framework import status
from rest_framework.test import APITestCase
from rest_framework.exceptions import ErrorDetail
from rest_framework_authlib.tokens import AccessToken
from urllib.parse import urljoin
from .factories import UserFactory
......@@ -161,3 +162,42 @@ class AccessTokenAPITestCase(APITestCase):
self.assertIn('access', response.data)
self.assertNotIn('password', response.data)
class UserProfileView(APITestCase):
def setUp(self):
self.user = UserFactory()
self.user.save()
token = str(AccessToken.for_user(self.user))
self.client.credentials(HTTP_AUTHORIZATION=f'Bearer {token}')
def test_get_user_profile(self):
response = self.client.get('/user/profile/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['email'], self.user.email)
self.assertEqual(response.data['first_name'], self.user.first_name)
def test_put_new_user_profile(self):
response = self.client.get('/user/profile/')
data = response.data
data['first_name'] = 'Donald Duck'
data['profile']['city'] = 'Kendari'
response = self.client.put('/user/profile/', data=data, format='json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['first_name'], data['first_name'])
self.assertEqual(response.data['profile']['city'],
data['profile']['city'])
def test_put_new_user_profile_with_email(self):
response = self.client.get('/user/profile/')
data = response.data
data['email'] = 'donald@10minutesmail.xyz'
response = self.client.put('/user/profile/', data=data, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertNotEqual(response.data['email'], data['email'])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment