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
5fe1f20c
Commit
5fe1f20c
authored
May 24, 2020
by
Jonathan Christopher Jakub
Browse files
[REFACTOR] Refactor tests to reuse same assertion series
parent
220a4c5e
Pipeline
#47734
passed with stages
in 3 minutes and 22 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/custom_auth/tests/test_units/test_custom_login.py
View file @
5fe1f20c
...
...
@@ -5,6 +5,7 @@ from django.contrib.auth.models import User
class
CustomAuthTest
(
APITestCase
):
@
classmethod
def
setUpTestData
(
cls
):
cls
.
URL
=
"/auth/token/"
...
...
@@ -14,35 +15,38 @@ class CustomAuthTest(APITestCase):
user
.
save
()
cls
.
user
=
user
def
_test_success
(
self
,
data
):
response
=
self
.
client
.
post
(
path
=
self
.
URL
,
data
=
data
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertTrue
(
Token
.
objects
.
filter
(
user
=
self
.
user
).
exists
())
def
_test_fails
(
self
,
data
):
response
=
self
.
client
.
post
(
path
=
self
.
URL
,
data
=
data
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_login_success_with_case_insensitive_username
(
self
):
data
=
{
"username"
:
"JoNaThAn"
,
"password"
:
"justpass"
,
}
response
=
self
.
client
.
post
(
path
=
self
.
URL
,
data
=
data
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertTrue
(
Token
.
objects
.
filter
(
user
=
self
.
user
).
exists
())
self
.
_test_success
(
data
)
def
test_login_success_with_exact_username
(
self
):
data
=
{
"username"
:
"jonathan"
,
"password"
:
"justpass"
,
}
response
=
self
.
client
.
post
(
path
=
self
.
URL
,
data
=
data
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertTrue
(
Token
.
objects
.
filter
(
user
=
self
.
user
).
exists
())
self
.
_test_success
(
data
)
def
test_login_fails_with_incomplete_credentials
(
self
):
data
=
{
"username"
:
"JoNaThAn"
,
}
response
=
self
.
client
.
post
(
path
=
self
.
URL
,
data
=
data
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
_test_fails
(
data
)
def
test_login_fails_with_wrong_credentials
(
self
):
data
=
{
"username"
:
"jonathanjojo"
,
"password"
:
"cantpass"
,
}
response
=
self
.
client
.
post
(
path
=
self
.
URL
,
data
=
data
,
format
=
"json"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
_test_fails
(
data
)
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