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
3b69b65f
Commit
3b69b65f
authored
May 19, 2020
by
Saul Andre
Browse files
[RED] Creating test case for comments page kontributor view
parent
eb12dc44
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/tests.py
View file @
3b69b65f
...
...
@@ -159,7 +159,53 @@ class DetailMateriTest(TestCase):
self
.
client
.
get
(
deleteURL
)
self
.
assertEqual
(
Comment
.
objects
.
all
().
filter
(
comment
=
"This is new comment by Anonymous"
).
count
(),
0
)
class
ViewCommentsTest
(
TestCase
):
def
setUp
(
self
):
self
.
client
=
Client
()
self
.
contributor_credential
=
{
"email"
:
"kontributor@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
.
cover
=
SimpleUploadedFile
(
"Cherprang_Areekul40_nJM9dGt.jpg"
,
b
"Test file"
)
self
.
content
=
SimpleUploadedFile
(
"Bahan_PA_RKK.pdf"
,
b
"Test file"
)
Materi
(
title
=
"Materi 1"
,
author
=
"Agas"
,
uploader
=
self
.
contributor
,
publisher
=
"Kelas SC"
,
descriptions
=
"Deskripsi Materi 1"
,
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/'
def
test_comments_url_exist
(
self
):
response
=
self
.
client
.
get
(
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'
)
def
test_comments_using_comments_func
(
self
):
found
=
resolve
(
self
.
url
)
self
.
assertEqual
(
found
.
func
.
__name__
,
DetailMateri
.
as_view
().
__name__
)
def
test_comments_page_render_comments
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertContains
(
response
,
"comments"
)
self
.
assertNotContains
(
response
,
'bukan comment'
)
def
test_comments_page_only_render_specific_user_comments
(
self
):
self
.
client
.
login
(
**
self
.
contributor_credential
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertContains
(
response
,
"comments"
)
self
.
assertNotContains
(
response
,
"this is Matt Damon"
)
class
TemplateLoaderTest
(
TestCase
):
def
test_template_loader_url_exist
(
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