Fakultas Ilmu Komputer UI

Commit 99952ed6 authored by Muhammad Rafif Elfazri's avatar Muhammad Rafif Elfazri
Browse files

Merge branch 'dev-rafif' into 'PBI-12-info_kegiatan'

Change Request Body "images" to "image[]"

See merge request !65
parents 25feed1a 29507535
Pipeline #81045 passed with stages
in 6 minutes and 42 seconds
......@@ -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,
......
......@@ -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:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment