Fakultas Ilmu Komputer UI

Commit 6bf91940 authored by Kefas Satrio Bangkit Solidedantyo's avatar Kefas Satrio Bangkit Solidedantyo
Browse files

Merge branch 'modify-user-serializer' into 'staging'

Add id and name for user

See merge request !40
parents 594ef580 3b2b7c7d
Pipeline #71946 passed with stages
in 8 minutes and 19 seconds
# Generated by Django 3.1 on 2021-04-24 06:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('authentication', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='customuser',
name='name',
field=models.CharField(default='tes', max_length=100),
preserve_default=False,
),
]
...@@ -8,6 +8,7 @@ from dietela_quiz.models import DietProfile ...@@ -8,6 +8,7 @@ from dietela_quiz.models import DietProfile
from .managers import CustomUserManager from .managers import CustomUserManager
class CustomUser(AbstractBaseUser, PermissionsMixin): class CustomUser(AbstractBaseUser, PermissionsMixin):
name = models.CharField(max_length=100)
email = models.EmailField(_('email address'), unique=True) email = models.EmailField(_('email address'), unique=True)
is_staff = models.BooleanField(default=False) is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True) is_active = models.BooleanField(default=True)
......
...@@ -6,5 +6,5 @@ class CustomUserDetailsSerializer(serializers.ModelSerializer): ...@@ -6,5 +6,5 @@ class CustomUserDetailsSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = CustomUser model = CustomUser
fields = ('email',) fields = ('id', 'name', 'email',)
read_only_fields = ('email',) read_only_fields = ('id', 'email',)
...@@ -56,16 +56,16 @@ class UserModelTests(APITestCase): ...@@ -56,16 +56,16 @@ class UserModelTests(APITestCase):
problem_to_solve=2, problem_to_solve=2,
health_problem=[1]) health_problem=[1])
cls.custom_user_1 = CustomUser.objects.create_user(email='email@email.com', password='abc') cls.custom_user_1 = CustomUser.objects.create_user(name='tes', email='email@email.com', password='abc')
cls.custom_user_2 = CustomUser.objects.create_user(email='email2@gmail.com', password='abc') cls.custom_user_2 = CustomUser.objects.create_user(name='tes', email='email2@gmail.com', password='abc')
cls.num_of_diet_profile = DietProfile.objects.count() cls.num_of_diet_profile = DietProfile.objects.count()
cls.num_of_custom_user = CustomUser.objects.count() cls.num_of_custom_user = CustomUser.objects.count()
def test_create_user(self): def test_create_user(self):
user = CustomUser.objects.create_user(email='email2@email.com', password='tes', user = CustomUser.objects.create_user(name='tes', email='email2@email.com',
diet_profile=self.diet_profile_1,) password='tes', diet_profile=self.diet_profile_1,)
self.assertEqual(str(user), 'email2@email.com') self.assertEqual(str(user), 'email2@email.com')
self.assertEqual(user.email, 'email2@email.com') self.assertEqual(user.email, 'email2@email.com')
self.assertTrue(user.is_active) self.assertTrue(user.is_active)
...@@ -105,6 +105,7 @@ class UserModelTests(APITestCase): ...@@ -105,6 +105,7 @@ class UserModelTests(APITestCase):
def test_post_registration_user_succeed(self): def test_post_registration_user_succeed(self):
data = { data = {
'name': 'tes',
'email': 'abc123@gmail.com', 'email': 'abc123@gmail.com',
'password1': '2828abab', 'password1': '2828abab',
'password2': '2828abab', 'password2': '2828abab',
...@@ -128,6 +129,7 @@ class UserModelTests(APITestCase): ...@@ -128,6 +129,7 @@ class UserModelTests(APITestCase):
def test_post_registration_user_failed_because_different_password(self): def test_post_registration_user_failed_because_different_password(self):
data = { data = {
'name': 'tes',
'email': 'abc123@gmail.com', 'email': 'abc123@gmail.com',
'password1': '2828abaab', 'password1': '2828abaab',
'password2': '2828abab', 'password2': '2828abab',
...@@ -139,6 +141,7 @@ class UserModelTests(APITestCase): ...@@ -139,6 +141,7 @@ class UserModelTests(APITestCase):
def test_post_registration_user_failed_because_email_already_registered(self): def test_post_registration_user_failed_because_email_already_registered(self):
data = { data = {
'name': 'tes',
'email': self.custom_user_1.email, 'email': self.custom_user_1.email,
'password1': '2828abaab', 'password1': '2828abaab',
'password2': '2828abaab', 'password2': '2828abaab',
...@@ -192,6 +195,8 @@ class UserModelTests(APITestCase): ...@@ -192,6 +195,8 @@ class UserModelTests(APITestCase):
self.assertIn('access_token', json_response) self.assertIn('access_token', json_response)
self.assertIn('refresh_token', json_response) self.assertIn('refresh_token', json_response)
self.assertIn('user', json_response) self.assertIn('user', json_response)
self.assertTrue('id' in json_response.get('user'))
self.assertEquals(json_response.get('user').get('name'), 'tes')
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_post_login_user_failed_because_non_existing_email(self): def test_post_login_user_failed_because_non_existing_email(self):
......
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