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
146d6fe9
Commit
146d6fe9
authored
May 20, 2020
by
Saul Andre
Browse files
[GREEN] minimal code for passing test
parent
3b69b65f
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/templates/comments.html
0 → 100644
View file @
146d6fe9
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<title>
Document
</title>
</head>
<body>
comments
</body>
</html>
\ No newline at end of file
app/tests.py
View file @
146d6fe9
...
...
@@ -15,7 +15,7 @@ from .models import Category, Comment, Materi, Like, ViewStatistics, DownloadSta
from
.views
import
(
DaftarKatalog
,
DashboardKontributorView
,
DetailMateri
,
ProfilKontributorView
,
SuksesLoginAdminView
,
SuksesLoginKontributorView
,
SuntingProfilView
,
ProfilAdminView
)
ProfilAdminView
,
CommentsView
)
from
app.views
import
UploadMateriHTML
,
UploadMateriView
from
authentication.models
import
User
...
...
@@ -167,10 +167,14 @@ class ViewCommentsTest(TestCase):
"email"
:
"kontributor@gov.id"
,
"password"
:
"passwordtest"
}
self
.
matt_damon_credential
=
{
"email"
:
"mattdamon@gov.id"
,
"password"
:
"passwordtest"
}
self
.
contributor
=
get_user_model
().
objects
.
create_user
(
**
self
.
contributor_credential
,
name
=
"Kontributor"
,
is_contributor
=
True
)
self
.
mattDamon
=
get_user_model
().
objects
.
create_user
(
**
self
.
contributor
_credential
,
name
=
"Matt Damon"
,
is_contributor
=
True
)
**
self
.
matt_damon
_credential
,
name
=
"Matt Damon"
,
is_contributor
=
True
)
self
.
cover
=
SimpleUploadedFile
(
"Cherprang_Areekul40_nJM9dGt.jpg"
,
b
"Test file"
)
self
.
content
=
SimpleUploadedFile
(
"Bahan_PA_RKK.pdf"
,
b
"Test file"
)
...
...
@@ -179,23 +183,27 @@ class ViewCommentsTest(TestCase):
status
=
"APPROVE"
,
cover
=
self
.
cover
,
content
=
self
.
content
).
save
()
self
.
materi1
=
Materi
.
objects
.
first
()
self
.
commentByKontributor
=
Comment
(
username
=
'saul'
,
materi
=
self
.
materi1
,
user
=
self
.
contributor
)
self
.
commentByMatt
=
Comment
(
username
=
'saul'
,
comment
=
"this is Matt Damon"
materi
=
self
.
materi1
,
user
=
self
.
mattDamon
)
self
.
url
=
'/comments/'
self
.
commentByMatt
=
Comment
(
username
=
'saul'
,
comment
=
"this is Matt Damon"
,
materi
=
self
.
materi1
,
user
=
self
.
mattDamon
)
self
.
url
=
'/kontributor/'
+
str
(
self
.
contributor
.
id
)
+
'/comments/'
def
test_comments_url_exist
(
self
):
response
=
self
.
client
.
get
(
url
)
self
.
client
.
login
(
**
self
.
contributor_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertNotEqual
(
response
.
status_code
,
404
)
def
test_comments_using_comments_template
(
self
):
response
=
self
.
client
.
get
(
url
)
self
.
assertTemplateUsed
(
response
,
'app/comments.html'
)
self
.
client
.
login
(
**
self
.
contributor_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertTemplateUsed
(
response
,
'comments.html'
)
def
test_comments_using_comments_func
(
self
):
self
.
client
.
login
(
**
self
.
contributor_credential
)
found
=
resolve
(
self
.
url
)
self
.
assertEqual
(
found
.
func
.
__name__
,
DetailMateri
.
as_view
().
__name__
)
self
.
assertEqual
(
found
.
func
.
__name__
,
CommentsView
.
as_view
().
__name__
)
def
test_comments_page_render_comments
(
self
):
self
.
client
.
login
(
**
self
.
contributor_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertContains
(
response
,
"comments"
)
self
.
assertNotContains
(
response
,
'bukan comment'
)
...
...
app/urls.py
View file @
146d6fe9
...
...
@@ -4,7 +4,7 @@ from app import views
from
app.views
import
(
DashboardKontributorView
,
ProfilKontributorView
,
SuksesLoginAdminView
,
SuksesLoginKontributorView
,
SuntingProfilView
,
UploadMateriHTML
,
UploadMateriView
,
ProfilAdminView
)
ProfilAdminView
,
CommentsView
)
urlpatterns
=
[
path
(
""
,
views
.
DaftarKatalog
.
as_view
(),
name
=
"daftar_katalog"
),
...
...
@@ -23,4 +23,5 @@ urlpatterns = [
path
(
"sukses-admin/"
,
SuksesLoginAdminView
.
as_view
(),
name
=
"sukses-admin"
),
re_path
(
r
"^.*\.html"
,
views
.
pages
,
name
=
"pages"
),
path
(
"profil-admin/"
,
ProfilAdminView
.
as_view
(),
name
=
"profil-admin"
),
path
(
'kontributor/<int:pk_user>/comments/'
,
CommentsView
.
as_view
(),
name
=
'comments'
),
]
app/views.py
View file @
146d6fe9
...
...
@@ -112,7 +112,6 @@ class DetailMateri(TemplateView):
materi
=
get_object_or_404
(
Materi
,
pk
=
kwargs
[
"pk"
])
user_obj
=
request
.
user
if
request
.
user
.
is_authenticated
else
None
print
(
user_obj
)
comment
=
Comment
.
objects
.
create
(
comment
=
commentText
,
username
=
self
.
get_user_name
(
request
),
materi
=
materi
,
user
=
user_obj
)
comment
.
save
()
...
...
@@ -365,6 +364,21 @@ class SuksesLoginAdminView(TemplateView):
return
self
.
render_to_response
(
context
)
class
CommentsView
(
TemplateView
):
template_name
=
"comments.html"
def
dispatch
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
is_contributor
:
raise
PermissionDenied
(
request
)
return
super
(
CommentsView
,
self
).
dispatch
(
request
,
*
args
,
**
kwargs
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
CommentsView
,
self
).
get_context_data
(
**
kwargs
)
return
context
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
context
=
self
.
get_context_data
(
**
kwargs
)
return
self
.
render_to_response
(
context
=
context
)
def
pages
(
request
):
context
=
{}
...
...
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