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
2020
PPL-C
PPTI-Mobile Apps Monitoring Wabah Tuberkolosis
Neza-Backend
Commits
5a9a6f75
Commit
5a9a6f75
authored
May 07, 2020
by
Jonathan Christopher Jakub
Committed by
Dave Nathanael
May 07, 2020
Browse files
Fix: Phone Validator on Accounts
parent
1dcd8cfe
Changes
3
Hide whitespace changes
Inline
Side-by-side
apps/accounts/models.py
View file @
5a9a6f75
import
uuid
from
django.contrib.auth.models
import
User
from
django.db
import
models
from
django.core.validators
import
RegexValidator
from
apps.commons.managers
import
SoftDeleteManager
from
apps.commons.models
import
HistoryEnabledModel
,
HistoryModel
...
...
@@ -32,7 +33,15 @@ class Account(HistoryEnabledModel):
user
=
models
.
OneToOneField
(
User
,
on_delete
=
models
.
CASCADE
)
name
=
models
.
CharField
(
max_length
=
128
)
email
=
models
.
EmailField
(
max_length
=
128
)
phone_number
=
models
.
CharField
(
max_length
=
64
)
phone_number
=
models
.
CharField
(
max_length
=
64
,
validators
=
[
RegexValidator
(
regex
=
r
'^\+?\d{9,15}$'
,
message
=
(
'Phone number has 9-15 digits, allowed to have + prefix'
),
),
]
)
area
=
models
.
CharField
(
max_length
=
128
)
is_admin
=
models
.
BooleanField
(
default
=
False
)
is_verified
=
models
.
BooleanField
(
default
=
False
)
...
...
apps/accounts/tests/factories/accounts.py
View file @
5a9a6f75
...
...
@@ -25,7 +25,7 @@ class AccountFactory(factory.DjangoModelFactory):
user
=
factory
.
SubFactory
(
UserFactory
)
name
=
faker
.
name
()
email
=
faker
.
email
()
phone_number
=
faker
.
phone_number
()
phone_number
=
"+999999999999"
area
=
faker
.
city
()
is_active
=
True
is_verified
=
True
apps/accounts/tests/test_units/test_accounts.py
View file @
5a9a6f75
...
...
@@ -88,7 +88,7 @@ class AccountViewTest(APITestCase):
"username"
:
_account_id
,
"password"
:
"justpass"
,
"email"
:
_account_id
,
"phone_number"
:
self
.
faker
.
phone_number
()
,
"phone_number"
:
"+999999999999"
,
"area"
:
self
.
faker
.
city
(),
"is_admin"
:
True
,
}
...
...
@@ -110,7 +110,7 @@ class AccountViewTest(APITestCase):
"username"
:
_account_id
,
"password"
:
"justpass"
,
"email"
:
_account_id
,
"phone_number"
:
self
.
faker
.
phone_number
()
,
"phone_number"
:
"+999999999999"
,
"area"
:
self
.
faker
.
city
(),
"is_admin"
:
False
,
"is_verified"
:
True
,
...
...
@@ -145,7 +145,7 @@ class AccountViewTest(APITestCase):
"username"
:
"user_1"
,
"password"
:
"justpass"
,
"email"
:
self
.
faker
.
email
(),
"phone_number"
:
self
.
faker
.
phone_number
()
,
"phone_number"
:
"+999999999999"
,
"area"
:
self
.
faker
.
city
(),
"is_admin"
:
False
,
"is_verified"
:
True
,
...
...
@@ -163,21 +163,21 @@ class AccountViewTest(APITestCase):
"email"
:
_account_id
,
"username"
:
_account_id
,
"password"
:
"12345678"
,
"phone_number"
:
self
.
faker
.
phone_number
()
,
"phone_number"
:
"+999999999999"
,
"area"
:
self
.
faker
.
city
(),
"is_admin"
:
False
,
}
response
=
self
.
client
.
post
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_edit_account_success
_by
(
self
):
def
test_edit_account_success
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
officer
.
id
)
+
"/"
data
=
{
"id"
:
str
(
self
.
officer
.
id
),
"name"
:
self
.
faker
.
name
(),
"email"
:
self
.
faker
.
email
(),
"phone_number"
:
self
.
faker
.
phone_number
()
,
"phone_number"
:
"+999999999999"
,
"area"
:
self
.
faker
.
city
(),
"is_admin"
:
False
,
"is_verified"
:
True
,
...
...
@@ -213,13 +213,43 @@ class AccountViewTest(APITestCase):
data
=
{
"id"
:
str
(
self
.
officer
.
id
),
"phone_number"
:
self
.
faker
.
phone_number
()
,
"phone_number"
:
"+999999999999"
,
"area"
:
self
.
faker
.
city
(),
}
response
=
self
.
client
.
put
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_edit_account_fail_with_wrong_email_or_phone_format
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
officer
.
id
)
+
"/"
data
=
{
"id"
:
str
(
self
.
officer
.
id
),
"name"
:
self
.
faker
.
name
(),
"email"
:
self
.
faker
.
email
(),
"phone_number"
:
"+999aaa999"
,
"area"
:
self
.
faker
.
city
(),
"is_admin"
:
False
,
"is_verified"
:
True
,
"is_active"
:
True
,
}
response
=
self
.
client
.
put
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
data
=
{
"id"
:
str
(
self
.
officer
.
id
),
"name"
:
self
.
faker
.
name
(),
"email"
:
"email"
,
"phone_number"
:
"+999999999999"
,
"area"
:
self
.
faker
.
city
(),
"is_admin"
:
False
,
"is_verified"
:
True
,
"is_active"
:
True
,
}
response
=
self
.
client
.
put
(
path
=
url
,
data
=
data
,
format
=
"json"
,)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_delete_success
(
self
):
url
=
self
.
BASE_URL
+
str
(
self
.
officer
.
id
)
+
"/"
...
...
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