tests.py
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from rest_framework.test import APITestCase
from django.urls import reverse
from rest_framework import status
from restful.models import File
class FileListTestCase(APITestCase):
def setUp(self):
self.tearDown()
def tearDown(self):
pass
def test_upload(self):
url = reverse('file-list')
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)