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
74cd5f54
Commit
74cd5f54
authored
Jun 03, 2021
by
Muhammad Rafif Elfazri
Browse files
[CHORES] Change request body add/update images key to images[]
parent
4b9ececa
Changes
2
Hide whitespace changes
Inline
Side-by-side
informasi_fasilitas/test_views_kegiatan.py
View file @
74cd5f54
...
...
@@ -51,9 +51,9 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
image2
=
SimpleUploadedFile
(
"test2.jpg"
,
content
=
open
(
image_path2
,
'rb'
).
read
(),
content_type
=
'image/jpeg'
)
self
.
kegiatan_images
=
{
'images'
:
[
image1
,
image2
]}
self
.
kegiatan_images
=
{
'images
[]
'
:
[
image1
,
image2
]}
self
.
foto
=
None
for
image
in
self
.
kegiatan_images
[
"images"
]:
for
image
in
self
.
kegiatan_images
[
"images
[]
"
]:
foto
=
FotoKegiatan
.
objects
.
create
(
kegiatan
=
self
.
kegiatan
,
foto
=
image
)
self
.
foto
=
foto
image
.
seek
(
0
)
...
...
@@ -286,7 +286,7 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
'time_start'
:
self
.
kegiatan_time_start
,
'time_end'
:
self
.
kegiatan_time_end
})
send_data
.
pop
(
"images"
)
send_data
.
pop
(
"images
[]
"
)
expected_json
.
update
(
send_data
)
self
.
assertEqual
(
response
.
status_code
,
HTTPStatus
.
ACCEPTED
)
self
.
assertDictEqual
(
data
,
expected_json
)
...
...
@@ -321,14 +321,14 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
counter
+=
1
def
test_can_add_foto_kegiatan
(
self
):
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images"
][
0
]}
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
]}
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images
[]
"
][
0
]}
url
=
reverse
(
'add-foto-kegiatan'
,
kwargs
=
{
'place_id'
:
"IDSNKCM"
,
'kegiatan_id'
:
222
,
...
...
@@ -339,7 +339,7 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
self
.
assertEqual
(
len
(
kegiatan_fotos
),
2
)
def
test_can_put_update_foto_kegiatan
(
self
):
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images"
][
0
]}
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
()
...
...
@@ -347,7 +347,7 @@ class KegiatanRelatedViewTest(InformasiFasilitasViewTest):
self
.
assertNotEqual
(
self
.
foto
.
foto
,
output
.
get
(
"foto"
))
def
test_failed_put_update_foto_kegiatan
(
self
):
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images"
][
0
]}
data
=
{
"foto"
:
self
.
kegiatan_images
[
"images
[]
"
][
0
]}
url
=
reverse
(
'update-foto-kegiatan'
,
kwargs
=
{
'place_id'
:
"IDSNKCM"
,
'kegiatan_id'
:
222
,
...
...
informasi_fasilitas/views_kegiatan.py
View file @
74cd5f54
...
...
@@ -55,12 +55,12 @@ def add_kegiatan(request, place_id):
user
=
request
.
user
data
=
request
.
data
.
dict
()
data
.
update
({
"user"
:
user
.
id
,
"lokasi"
:
lokasi
.
id
})
data
.
pop
(
"images"
,
[])
data
.
pop
(
"images
[]
"
,
[])
serializer
=
KegiatanSerializer
(
data
=
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
kegiatan
=
serializer
.
save
()
serializer
=
_add_foto_kegiatan
(
kegiatan
,
request
.
data
.
getlist
(
"images"
))
serializer
=
_add_foto_kegiatan
(
kegiatan
,
request
.
data
.
getlist
(
"images
[]
"
))
return
JsonResponse
(
_clean_json_kegiatan
(
serializer
.
data
),
status
=
HTTPStatus
.
CREATED
)
except
Lokasi
.
DoesNotExist
:
...
...
@@ -74,11 +74,11 @@ def update_kegiatan(request, place_id, id):
try
:
kegiatan
=
Kegiatan
.
objects
.
get
(
lokasi__place_id
=
place_id
,
id
=
id
)
data
=
request
.
data
.
dict
()
data
.
pop
(
"images"
,
[])
data
.
pop
(
"images
[]
"
,
[])
serializer
=
KegiatanSerializer
(
kegiatan
,
data
=
data
,
partial
=
True
)
serializer
.
is_valid
(
raise_exception
=
True
)
kegiatan
=
serializer
.
save
()
serializer
=
_add_foto_kegiatan
(
kegiatan
,
request
.
data
.
getlist
(
"images"
))
serializer
=
_add_foto_kegiatan
(
kegiatan
,
request
.
data
.
getlist
(
"images
[]
"
))
return
JsonResponse
(
_clean_json_kegiatan
(
serializer
.
data
),
status
=
HTTPStatus
.
ACCEPTED
)
except
Kegiatan
.
DoesNotExist
:
...
...
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