신은섭(Shin Eun Seop)

fix test code

kairos03/2018-1-d.cloud#8
kairos03/2018-1-d.cloud#10
from rest_framework.test import APITestCase
from django.urls import reverse
from rest_framework import status
from restful.models import File
class UploadFileTestCase(APITestCase):
def setup(self):
class FileListTestCase(APITestCase):
def setUp(self):
self.tearDown()
def tearDown(self):
......@@ -15,4 +17,37 @@ class UploadFileTestCase(APITestCase):
data = {'object_key': 'test_object_key'}
response = self.client.post(url, data)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(File.objects.count(), 1)
def test_list(self):
url = reverse('file-list')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
class FileDetailTestCase(APITestCase):
def setUp(self):
self.tearDown()
File.objects.create(object_key='test_object')
def tearDown(self):
File.objects.all().delete()
def test_delete(self):
url = reverse('file-detail', kwargs={'pk' : 1 })
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
def test_update(self):
url = reverse('file-detail', kwargs={'pk' : 1 })
response = self.client.put(url, {"object_key":"test_update"})
self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
def test_retrieve(self):
url = reverse('file-detail', kwargs={'pk' : 1 })
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
\ No newline at end of file
......
......@@ -38,14 +38,14 @@ class FileDetail(APIView):
def get(self, request, pk, format=None):
file = self.get_object(pk)
serializer = FileSerializer(file)
return Response(serializer.data)
return Response(serializer.data, status=status.HTTP_200_OK)
def put(self, request, pk, format=None):
file = self.get_object(pk)
serializer = FileSerializer(file, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.data, status=status.HTTP_204_NO_CONTENT)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk, format=None):
......