mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2018 from SchrodingersGat/file-upload-fix
Fix for file upload bug
This commit is contained in:
commit
75152fab0e
@ -10,6 +10,8 @@ import os
|
|||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import ValidationError as DjangoValidationError
|
from django.core.exceptions import ValidationError as DjangoValidationError
|
||||||
@ -94,9 +96,14 @@ class InvenTreeModelSerializer(serializers.ModelSerializer):
|
|||||||
|
|
||||||
# If instance is None, we are creating a new instance
|
# If instance is None, we are creating a new instance
|
||||||
if instance is None and data is not empty:
|
if instance is None and data is not empty:
|
||||||
|
|
||||||
# Required to side-step immutability of a QueryDict
|
if data is None:
|
||||||
data = data.copy()
|
data = OrderedDict()
|
||||||
|
else:
|
||||||
|
new_data = OrderedDict()
|
||||||
|
new_data.update(data)
|
||||||
|
|
||||||
|
data = new_data
|
||||||
|
|
||||||
# Add missing fields which have default values
|
# Add missing fields which have default values
|
||||||
ModelClass = self.Meta.model
|
ModelClass = self.Meta.model
|
||||||
|
BIN
InvenTree/stock/fixtures/test_image.bmp
Normal file
BIN
InvenTree/stock/fixtures/test_image.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 MiB |
@ -5,6 +5,8 @@ Unit testing for the Stock API
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@ -666,3 +668,37 @@ class StockTestResultTest(StockAPITestCase):
|
|||||||
test = response.data[0]
|
test = response.data[0]
|
||||||
self.assertEqual(test['value'], '150kPa')
|
self.assertEqual(test['value'], '150kPa')
|
||||||
self.assertEqual(test['user'], self.user.pk)
|
self.assertEqual(test['user'], self.user.pk)
|
||||||
|
|
||||||
|
def test_post_bitmap(self):
|
||||||
|
"""
|
||||||
|
2021-08-25
|
||||||
|
|
||||||
|
For some (unknown) reason, prior to fix https://github.com/inventree/InvenTree/pull/2018
|
||||||
|
uploading a bitmap image would result in a failure.
|
||||||
|
|
||||||
|
This test has been added to ensure that there is no regression.
|
||||||
|
|
||||||
|
As a bonus this also tests the file-upload component
|
||||||
|
"""
|
||||||
|
|
||||||
|
here = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
image_file = os.path.join(here, 'fixtures', 'test_image.bmp')
|
||||||
|
|
||||||
|
with open(image_file, 'rb') as bitmap:
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'stock_item': 105,
|
||||||
|
'test': 'Checked Steam Valve',
|
||||||
|
'result': False,
|
||||||
|
'value': '150kPa',
|
||||||
|
'notes': 'I guess there was just too much pressure?',
|
||||||
|
"attachment": bitmap,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(self.get_url(), data)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, 201)
|
||||||
|
|
||||||
|
# Check that an attachment has been uploaded
|
||||||
|
self.assertIsNotNone(response.data['attachment'])
|
||||||
|
Loading…
Reference in New Issue
Block a user