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
PPL Sosial
bisago
bisago-be
Commits
2dee9919
Commit
2dee9919
authored
Jun 01, 2021
by
Muhammad Rafif Elfazri
Browse files
[RED] Add test for add(single) and update FotoKegiatan
parent
d55fc4d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
informasi_fasilitas/test_views_kegiatan.py
View file @
2dee9919
...
...
@@ -31,6 +31,7 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
'place_id'
:
self
.
lokasi
.
place_id
,
'kegiatan_id'
:
self
.
kegiatan
.
id
,
}
self
.
kwargs_search_kegiatan
=
{
'query'
:
'mock'
,
}
self
.
kwargs_search_kegiatan_fail
=
{
'query'
:
'this shouldnt exist'
,
}
...
...
@@ -51,26 +52,43 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
content_type
=
'image/jpeg'
)
self
.
kegiatan_images
=
{
'images'
:
[
image1
,
image2
]}
self
.
foto
=
None
for
image
in
self
.
kegiatan_images
[
"images"
]:
FotoKegiatan
.
objects
.
create
(
kegiatan
=
self
.
kegiatan
,
foto
=
image
)
foto
=
FotoKegiatan
.
objects
.
create
(
kegiatan
=
self
.
kegiatan
,
foto
=
image
)
self
.
foto
=
foto
image
.
seek
(
0
)
self
.
kwargs_update_foto_kegiatan
=
{
'place_id'
:
self
.
lokasi
.
place_id
,
'kegiatan_id'
:
self
.
kegiatan
.
id
,
'id'
:
self
.
foto
.
id
,
}
self
.
get_list_kegiatan_url
=
\
reverse
(
'list-kegiatan'
,
kwargs
=
self
.
kwargs_place_id
)
self
.
get_detail_kegiatan_url
=
\
reverse
(
'detail-kegiatan'
,
kwargs
=
self
.
kwargs_add_or_update_kegiatan
)
self
.
get_nearest_kegiatan_url
=
\
reverse
(
'nearest-kegiatan'
)
self
.
add_kegiatan_url
=
\
reverse
(
'add-kegiatan'
,
kwargs
=
self
.
kwargs_place_id
)
self
.
update_kegiatan_url
=
reverse
(
'update-kegiatan'
,
kwargs
=
self
.
kwargs_add_or_update_kegiatan
)
self
.
search_kegiatan_url
=
reverse
(
'search-kegiatan'
,
kwargs
=
self
.
kwargs_search_kegiatan
)
self
.
search_kegiatan_fail_url
=
reverse
(
'search-kegiatan'
,
kwargs
=
self
.
kwargs_search_kegiatan_fail
)
self
.
list_foto_kegiatan_url
=
\
reverse
(
'list-foto-kegiatan'
,
kwargs
=
self
.
kwargs_get_foto_kegiatan
)
self
.
add_foto_kegiatan_url
=
\
reverse
(
'add-foto-kegiatan'
,
kwargs
=
self
.
kwargs_get_foto_kegiatan
)
self
.
update_foto_kegiatan_url
=
\
reverse
(
'update-foto-kegiatan'
,
kwargs
=
self
.
kwargs_update_foto_kegiatan
)
self
.
list_kegiatan_by_latest_added_url
=
\
reverse
(
'list-kegiatan-by-latest-added'
,
kwargs
=
self
.
kwargs_list_kegiatan_in_order
)
self
.
list_kegiatan_by_name_url
=
\
...
...
@@ -302,6 +320,42 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
self
.
assertEqual
(
item
[
"kegiatan"
],
self
.
kegiatan
.
id
)
counter
+=
1
def
test_can_add_foto_kegiatan
(
self
):
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images"
][
0
]}
response
=
self
.
client
.
post
(
self
.
add_foto_kegiatan_url
,
data
=
data
)
self
.
assertEqual
(
response
.
status_code
,
HTTPStatus
.
CREATED
)
kegiatan_fotos
=
FotoKegiatan
.
objects
.
all
()
self
.
assertEqual
(
len
(
kegiatan_fotos
),
3
)
def
test_failed_add_foto_kegiatan
(
self
):
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images"
][
0
]}
url
=
reverse
(
'add-foto-kegiatan'
,
kwargs
=
{
'place_id'
:
"IDSNKCM"
,
'kegiatan_id'
:
222
,
})
response
=
self
.
client
.
post
(
url
,
data
=
data
)
self
.
assertEqual
(
response
.
status_code
,
HTTPStatus
.
NOT_FOUND
)
kegiatan_fotos
=
FotoKegiatan
.
objects
.
all
()
self
.
assertEqual
(
len
(
kegiatan_fotos
),
2
)
def
test_can_put_update_foto_kegiatan
(
self
):
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images"
][
0
]}
response
=
self
.
client
.
put
(
self
.
update_foto_kegiatan_url
,
data
=
data
)
self
.
assertEqual
(
response
.
status_code
,
HTTPStatus
.
ACCEPTED
)
output
=
response
.
json
()
self
.
assertIsNotNone
(
output
.
get
(
"foto"
))
self
.
assertNotEqual
(
self
.
foto
.
foto
,
output
.
get
(
"foto"
))
def
test_failed_put_update_foto_kegiatan
(
self
):
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images"
][
0
]}
url
=
reverse
(
'update-foto-kegiatan'
,
kwargs
=
{
'place_id'
:
"IDSNKCM"
,
'kegiatan_id'
:
222
,
'id'
:
444
,
})
response
=
self
.
client
.
put
(
url
,
data
=
data
)
self
.
assertEqual
(
response
.
status_code
,
HTTPStatus
.
NOT_FOUND
)
def
test_can_search_kegiatan
(
self
):
response
=
Client
().
get
(
self
.
search_kegiatan_url
)
self
.
assertEqual
(
response
.
status_code
,
HTTPStatus
.
OK
)
...
...
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