remove trailing slash requirement in api v1
This commit is contained in:
parent
e2a2e3e117
commit
aa0bb9fd0d
8 changed files with 52 additions and 46 deletions
|
@ -18,7 +18,7 @@ class FileViewSet(viewsets.ModelViewSet):
|
|||
lookup_field = 'hash'
|
||||
|
||||
|
||||
router = routers.SimpleRouter()
|
||||
router = routers.SimpleRouter(trailing_slash=False)
|
||||
router.register(r'files', FileViewSet, basename='files')
|
||||
router.register(r'file', FileViewSet, basename='files')
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class FileTestCase(TestCase):
|
|||
def test_list_files(self):
|
||||
import base64
|
||||
item = File.objects.create(data=base64.b64encode(b"foo").decode('utf-8'))
|
||||
response = client.get('/api/1/files/')
|
||||
response = client.get('/api/1/files')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json()[0]['hash'], item.hash)
|
||||
self.assertEqual(len(response.json()[0]['hash']), 64)
|
||||
|
@ -24,7 +24,7 @@ class FileTestCase(TestCase):
|
|||
def test_one_file(self):
|
||||
import base64
|
||||
item = File.objects.create(data=base64.b64encode(b"foo").decode('utf-8'))
|
||||
response = client.get(f'/api/1/file/{item.hash}/')
|
||||
response = client.get(f'/api/1/file/{item.hash}')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json()['hash'], item.hash)
|
||||
self.assertEqual(len(response.json()['hash']), 64)
|
||||
|
@ -33,7 +33,7 @@ class FileTestCase(TestCase):
|
|||
import base64
|
||||
Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='2')
|
||||
response = client.post('/api/1/file/', {'data': base64.b64encode(b"foo").decode('utf-8')}, content_type='application/json')
|
||||
response = client.post('/api/1/file', {'data': base64.b64encode(b"foo").decode('utf-8')}, content_type='application/json')
|
||||
self.assertEqual(response.status_code, 201)
|
||||
self.assertEqual(len(response.json()['hash']), 64)
|
||||
|
||||
|
@ -43,5 +43,5 @@ class FileTestCase(TestCase):
|
|||
File.objects.create(item=item, data=base64.b64encode(b"foo").decode('utf-8'))
|
||||
file = File.objects.create(item=item, data=base64.b64encode(b"bar").decode('utf-8'))
|
||||
self.assertEqual(len(File.objects.all()), 2)
|
||||
response = client.delete(f'/api/1/file/{file.hash}/')
|
||||
response = client.delete(f'/api/1/file/{file.hash}')
|
||||
self.assertEqual(response.status_code, 204)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue