Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2021
Kelas D
PT Gizi Sehat - Dietela
Dietela Backend
Commits
6bf91940
Commit
6bf91940
authored
Apr 24, 2021
by
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
authentication/migrations/0002_customuser_name.py
0 → 100644
View file @
6bf91940
# 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
,
),
]
authentication/models.py
View file @
6bf91940
...
...
@@ -8,6 +8,7 @@ from dietela_quiz.models import DietProfile
from
.managers
import
CustomUserManager
class
CustomUser
(
AbstractBaseUser
,
PermissionsMixin
):
name
=
models
.
CharField
(
max_length
=
100
)
email
=
models
.
EmailField
(
_
(
'email address'
),
unique
=
True
)
is_staff
=
models
.
BooleanField
(
default
=
False
)
is_active
=
models
.
BooleanField
(
default
=
True
)
...
...
authentication/serializers.py
View file @
6bf91940
...
...
@@ -6,5 +6,5 @@ class CustomUserDetailsSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
CustomUser
fields
=
(
'email'
,)
read_only_fields
=
(
'email'
,)
fields
=
(
'id'
,
'name'
,
'email'
,)
read_only_fields
=
(
'id'
,
'email'
,)
authentication/tests.py
View file @
6bf91940
...
...
@@ -56,16 +56,16 @@ class UserModelTests(APITestCase):
problem_to_solve
=
2
,
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_custom_user
=
CustomUser
.
objects
.
count
()
def
test_create_user
(
self
):
user
=
CustomUser
.
objects
.
create_user
(
email
=
'email2@email.com'
,
password
=
'tes'
,
diet_profile
=
self
.
diet_profile_1
,)
user
=
CustomUser
.
objects
.
create_user
(
name
=
'tes'
,
email
=
'email2@email.com'
,
password
=
'tes'
,
diet_profile
=
self
.
diet_profile_1
,)
self
.
assertEqual
(
str
(
user
),
'email2@email.com'
)
self
.
assertEqual
(
user
.
email
,
'email2@email.com'
)
self
.
assertTrue
(
user
.
is_active
)
...
...
@@ -105,6 +105,7 @@ class UserModelTests(APITestCase):
def
test_post_registration_user_succeed
(
self
):
data
=
{
'name'
:
'tes'
,
'email'
:
'abc123@gmail.com'
,
'password1'
:
'2828abab'
,
'password2'
:
'2828abab'
,
...
...
@@ -128,6 +129,7 @@ class UserModelTests(APITestCase):
def
test_post_registration_user_failed_because_different_password
(
self
):
data
=
{
'name'
:
'tes'
,
'email'
:
'abc123@gmail.com'
,
'password1'
:
'2828abaab'
,
'password2'
:
'2828abab'
,
...
...
@@ -139,6 +141,7 @@ class UserModelTests(APITestCase):
def
test_post_registration_user_failed_because_email_already_registered
(
self
):
data
=
{
'name'
:
'tes'
,
'email'
:
self
.
custom_user_1
.
email
,
'password1'
:
'2828abaab'
,
'password2'
:
'2828abaab'
,
...
...
@@ -192,6 +195,8 @@ class UserModelTests(APITestCase):
self
.
assertIn
(
'access_token'
,
json_response
)
self
.
assertIn
(
'refresh_token'
,
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
)
def
test_post_login_user_failed_because_non_existing_email
(
self
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment