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
PMPL
Class Project
DIGIPUS
Commits
a660b8bd
Commit
a660b8bd
authored
Oct 08, 2020
by
Steven Kusuman
Browse files
[112] Bugfix: Login
parent
1c36659c
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/tests.py
View file @
a660b8bd
...
...
@@ -1066,7 +1066,7 @@ class GenerateDummyCommandTest(TestCase):
for
num_of_materi
in
self
.
material_numbers
:
call_command
(
"generatedummy"
,
num_of_materi
,
stdout
=
self
.
stdout
)
self
.
assertIn
(
f
"Successfully created
{
num_of_materi
}
materi
\n
"
,
f
"Successfully created
{
num_of_materi
}
materi"
,
self
.
stdout
.
getvalue
()
)
...
...
@@ -1090,7 +1090,7 @@ class RemoveDummyCommandTest(TestCase):
call_command
(
"removedummy"
,
stdout
=
stdout
)
self
.
assert
Equal
(
"Successfully remove all dummy object
\n
"
,
stdout
.
getvalue
())
self
.
assert
In
(
"Successfully remove all dummy object"
,
stdout
.
getvalue
())
self
.
assertEqual
(
User
.
objects
.
count
(),
0
)
self
.
assertEqual
(
Category
.
objects
.
count
(),
0
)
self
.
assertEqual
(
Materi
.
objects
.
count
(),
0
)
...
...
authentication/tests.py
View file @
a660b8bd
...
...
@@ -74,7 +74,7 @@ class UserModelTest(TestCase):
class
LoginPageContributorTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
admin
=
User
.
objects
.
create_contributor
(
email
=
"kontributor@gov.id"
,
self
.
kontributor
=
User
.
objects
.
create_contributor
(
email
=
"kontributor@gov.id"
,
password
=
"kontributor"
)
self
.
url
=
"/login/"
self
.
view
=
Login
...
...
@@ -86,34 +86,34 @@ class LoginPageContributorTest(TestCase):
"wrong_email_or_password"
:
"Email atau Password anda salah."
,
}
def
test_login_
admin
_view
(
self
):
def
test_login_
kontributor
_view
(
self
):
found
=
resolve
(
self
.
url
)
self
.
assertEqual
(
found
.
func
.
__name__
,
self
.
view
.
as_view
().
__name__
)
def
test_login_
admin
_template
(
self
):
def
test_login_
kontributor
_template
(
self
):
# Test
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertTemplateUsed
(
response
,
self
.
template_name
)
def
test_login_
admin
_url
(
self
):
def
test_login_
kontributor
_url
(
self
):
# Test
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_login_
admin
_title
(
self
):
def
test_login_
kontributor
_title
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
# Positive tests
self
.
assertContains
(
response
,
"Halo, kontributor"
)
def
test_login_
admin
_form_field
(
self
):
def
test_login_
kontributor
_form_field
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
# Positive tests
self
.
assertContains
(
response
,
"Email"
)
self
.
assertContains
(
response
,
"Kata Sandi"
)
def
test_
admin
_login_missing_email_or_password
(
self
):
def
test_
kontributor
_login_missing_email_or_password
(
self
):
response
=
self
.
client
.
post
(
self
.
url
,
{
"email"
:
"kontributor@gov.id"
})
self
.
assertIn
(
"error_message"
,
response
.
context_data
)
self
.
assertIn
(
self
.
error_message
[
"empty_email_or_password"
],
...
...
@@ -123,7 +123,7 @@ class LoginPageContributorTest(TestCase):
self
.
assertIn
(
self
.
error_message
[
"empty_email_or_password"
],
response
.
context_data
[
"error_message"
])
def
test_
admin
_login_wrong_email_or_password
(
self
):
def
test_
kontributor
_login_wrong_email_or_password
(
self
):
# Wrong password
response
=
self
.
client
.
post
(
self
.
url
,
{
"email"
:
"kontributor@gov.id"
,
"pass"
:
"kontributor1"
})
...
...
@@ -143,7 +143,7 @@ class LoginPageContributorTest(TestCase):
self
.
assertIn
(
self
.
error_message
[
"wrong_email_or_password"
],
response
.
context_data
[
"error_message"
])
def
test_
admin
_login
(
self
):
def
test_
kontributor
_login
(
self
):
# 302 meaning successful login and redirected
expected_redirect_url
=
"/sukses-kontributor/"
response
=
self
.
client
.
post
(
...
...
@@ -151,6 +151,19 @@ class LoginPageContributorTest(TestCase):
self
.
assertEqual
(
302
,
response
.
status_code
)
self
.
assertEqual
(
response
.
url
,
expected_redirect_url
)
def
test_kontributor_visit_login_after_auth
(
self
):
# 302 meaning successful login and redirected
expected_redirect_url
=
"/sukses-kontributor/"
response
=
self
.
client
.
post
(
self
.
url
,
self
.
login_credential
)
self
.
assertEqual
(
302
,
response
.
status_code
)
self
.
assertEqual
(
response
.
url
,
expected_redirect_url
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
302
,
response
.
status_code
)
self
.
assertEqual
(
response
.
url
,
expected_redirect_url
)
class
LoginPageAdminTest
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -230,3 +243,17 @@ class LoginPageAdminTest(TestCase):
self
.
url
,
self
.
login_credential
)
self
.
assertEqual
(
302
,
response
.
status_code
)
self
.
assertEqual
(
response
.
url
,
expected_redirect_url
)
def
test_admin_visit_login_after_auth
(
self
):
# 302 meaning successful login and redirected
expected_redirect_url
=
"/sukses-admin/"
response
=
self
.
client
.
post
(
self
.
url
,
self
.
login_credential
)
self
.
assertEqual
(
302
,
response
.
status_code
)
self
.
assertEqual
(
response
.
url
,
expected_redirect_url
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
302
,
response
.
status_code
)
self
.
assertEqual
(
response
.
url
,
expected_redirect_url
)
authentication/views.py
View file @
a660b8bd
...
...
@@ -4,6 +4,16 @@ from django.views.generic import TemplateView
class
Login
(
TemplateView
):
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
request
.
user
.
is_authenticated
:
if
request
.
user
.
is_admin
:
redirect_to
=
"/sukses-admin/"
elif
request
.
user
.
is_contributor
:
redirect_to
=
"/sukses-kontributor/"
return
HttpResponseRedirect
(
redirect_to
)
return
super
(
Login
,
self
).
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get_template_names
(
self
):
if
self
.
request
.
path
==
"/login_admin/"
:
template_name
=
"login_admin.html"
...
...
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