Fakultas Ilmu Komputer UI

Commit bdceef52 authored by Adib Yusril Wafi's avatar Adib Yusril Wafi
Browse files

Merge branch '1606837991-73' into 'master'

1606837991 - #73

See merge request !34
parents 130405b7 a0f9bd9d
Pipeline #22366 passed with stages
in 13 minutes and 26 seconds
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2019-10-06 11:55
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0017_vacancy_amount'),
('core', '0019_merge_20191006_0852'),
('core', '0014_auto_20191004_1340'),
]
operations = [
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2019-10-08 14:45
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0020_merge_20191006_1855'),
('core', '0034_merge_20191008_1907'),
]
operations = [
]
......@@ -256,3 +256,50 @@ class FeedbacksTests(APITestCase):
response = self.client.delete(feedbacks_url)
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
@requests_mock.Mocker()
def test_feedbacks_update_with_exist_data_and_with_data_id(self, m):
self.login(m)
# test_feedbacks_update_with_exist_data_and_with_data_id
new_feedback = Feedback(title="a title", content="a content")
new_feedback.save()
feedback_id = new_feedback.id
feedbacks_url = '/api/feedbacks/' + str(feedback_id) + '/'
response = self.client.put(feedbacks_url,
{"content": "updated content", "title": "updated title"})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["title"], "updated title")
self.assertEqual(response.data["content"], "updated content")
self.assertEqual(response.data["detail"], "Feedback with id {} was updated".format(feedback_id))
@requests_mock.Mocker()
def test_feedbacks_update_with_not_exist_data_and_with_data_id(self, m):
self.login(m)
# test_feedbacks_delete_with_not_exist_data_and_with_data_id
new_feedback = Feedback(title="a title", content="a content")
new_feedback.save()
feedback_id = new_feedback.id
new_feedback.delete()
feedbacks_url = '/api/feedbacks/' + str(feedback_id) + '/'
response = self.client.put(feedbacks_url,
{"content": "updated content", "title": "updated title"})
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.data["detail"], "Feedback with id {} doesn't exist".format(feedback_id))
@requests_mock.Mocker()
def test_feedbacks_delete_without_data_id(self, m):
self.login(m)
# test_feedbacks_delete_without_data_id
feedbacks_url = '/api/feedbacks/'
response = self.client.put(feedbacks_url,
{"content": "updated content", "title": "updated title"})
self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED)
......@@ -61,3 +61,26 @@ class FeedbackViewSet(viewsets.GenericViewSet):
message = {"detail": "Feedback with id {} doesn't exist".format(pk)}
print(message)
return Response(message, status=status.HTTP_400_BAD_REQUEST)
def update(self, request, pk):
"""
Update feedback {id}
---
"""
if Feedback.objects.filter(id=pk).count() != 0:
print (request.data)
update_feedback = Feedback.objects.filter(id=pk)
update_feedback.update(title=request.data['title'], content=request.data['content'])
update_feedback = Feedback.objects.get(id=pk)
serialized_update_feedback = FeedbackSerializer(update_feedback, context={'request': request})
serialized_update_feedback_data = serialized_update_feedback.data
message = {"detail": "Feedback with id {} was updated".format(pk)}
message.update(serialized_update_feedback_data)
print(message)
return Response(message, status=status.HTTP_200_OK)
else:
message = {"detail": "Feedback with id {} doesn't exist".format(pk)}
print(message)
return Response(message, status=status.HTTP_400_BAD_REQUEST)
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