fix embedded file upload
This commit is contained in:
parent
aa0bb9fd0d
commit
27589a09bd
4 changed files with 76 additions and 19 deletions
|
@ -22,12 +22,13 @@ class ItemTestCase(TestCase):
|
|||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
response = client.get(f'/api/1/{self.event.slug}/item')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json(), [{'uid': 1, 'description': '1', 'box': 'BOX', 'cid': self.box.cid, 'file': None}])
|
||||
self.assertEqual(response.json(),
|
||||
[{'uid': 1, 'description': '1', 'box': 'BOX', 'cid': self.box.cid, 'file': None}])
|
||||
|
||||
def test_members_with_file(self):
|
||||
import base64
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
file = File.objects.create(item=item, data=base64.b64encode(b"foo").decode('utf-8'))
|
||||
file = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8'))
|
||||
response = client.get(f'/api/1/{self.event.slug}/item')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json(),
|
||||
|
@ -44,19 +45,35 @@ class ItemTestCase(TestCase):
|
|||
def test_create_item(self):
|
||||
response = client.post(f'/api/1/{self.event.slug}/item', {'cid': self.box.cid, 'description': '1'})
|
||||
self.assertEqual(response.status_code, 201)
|
||||
self.assertEqual(response.json(), {'uid': 1, 'description': '1', 'box': 'BOX', 'cid': self.box.cid, 'file': None})
|
||||
self.assertEqual(response.json(),
|
||||
{'uid': 1, 'description': '1', 'box': 'BOX', 'cid': self.box.cid, 'file': None})
|
||||
self.assertEqual(len(Item.objects.all()), 1)
|
||||
self.assertEqual(Item.objects.all()[0].uid, 1)
|
||||
self.assertEqual(Item.objects.all()[0].description, '1')
|
||||
self.assertEqual(Item.objects.all()[0].container.cid, self.box.cid)
|
||||
|
||||
#def test_create_item_fail(self):
|
||||
# response = client.post(f'/api/1/{self.event.slug}/item/', {'cid': self.box.cid})
|
||||
# self.assertEqual(response.status_code, 500)
|
||||
def test_create_item_with_file(self):
|
||||
import base64
|
||||
response = client.post(f'/api/1/{self.event.slug}/item',
|
||||
{'cid': self.box.cid, 'description': '1',
|
||||
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode(
|
||||
'utf-8')}, content_type='application/json')
|
||||
self.assertEqual(response.status_code, 201)
|
||||
self.assertEqual(response.json()['uid'], 1)
|
||||
self.assertEqual(response.json()['description'], '1')
|
||||
self.assertEqual(response.json()['box'], 'BOX')
|
||||
self.assertEqual(response.json()['cid'], self.box.cid)
|
||||
self.assertEqual(len(response.json()['file']), 64)
|
||||
self.assertEqual(len(Item.objects.all()), 1)
|
||||
self.assertEqual(Item.objects.all()[0].uid, 1)
|
||||
self.assertEqual(Item.objects.all()[0].description, '1')
|
||||
self.assertEqual(Item.objects.all()[0].container.cid, self.box.cid)
|
||||
self.assertEqual(len(File.objects.all()), 1)
|
||||
|
||||
def test_update_item(self):
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
response = client.put(f'/api/1/{self.event.slug}/item/{item.uid}', {'description': '2'}, content_type='application/json')
|
||||
response = client.put(f'/api/1/{self.event.slug}/item/{item.uid}', {'description': '2'},
|
||||
content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json(),
|
||||
{'uid': 1, 'description': '2', 'box': 'BOX', 'cid': self.box.cid, 'file': None})
|
||||
|
@ -65,6 +82,25 @@ class ItemTestCase(TestCase):
|
|||
self.assertEqual(Item.objects.all()[0].description, '2')
|
||||
self.assertEqual(Item.objects.all()[0].container.cid, self.box.cid)
|
||||
|
||||
def test_update_item_with_file(self):
|
||||
import base64
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
response = client.put(f'/api/1/{self.event.slug}/item/{item.uid}',
|
||||
{'description': '2',
|
||||
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8')},
|
||||
content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json()['uid'], 1)
|
||||
self.assertEqual(response.json()['description'], '2')
|
||||
self.assertEqual(response.json()['box'], 'BOX')
|
||||
self.assertEqual(response.json()['cid'], self.box.cid)
|
||||
self.assertEqual(len(response.json()['file']), 64)
|
||||
self.assertEqual(len(Item.objects.all()), 1)
|
||||
self.assertEqual(Item.objects.all()[0].uid, 1)
|
||||
self.assertEqual(Item.objects.all()[0].description, '2')
|
||||
self.assertEqual(Item.objects.all()[0].container.cid, self.box.cid)
|
||||
self.assertEqual(len(File.objects.all()), 1)
|
||||
|
||||
def test_delete_item(self):
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
Item.objects.create(container=self.box, event=self.event, description='2')
|
||||
|
@ -95,4 +131,3 @@ class ItemTestCase(TestCase):
|
|||
def test_item_nonexistent(self):
|
||||
response = client.get(f'/api/1/NOEVENT/item')
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue