mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Prevent assigning of empty barcode data (#3851)
* Prevent assigning of empty barcode data * Make similar check for barcode scan endpoint * Fixes for unit tests
This commit is contained in:
parent
824a44a486
commit
13cfadaf29
@ -48,8 +48,10 @@ class BarcodeScan(APIView):
|
||||
"""
|
||||
data = request.data
|
||||
|
||||
if 'barcode' not in data:
|
||||
raise ValidationError({'barcode': _('Must provide barcode_data parameter')})
|
||||
barcode_data = data.get('barcode', None)
|
||||
|
||||
if not barcode_data:
|
||||
raise ValidationError({'barcode': _('Missing barcode data')})
|
||||
|
||||
# Ensure that the default barcode handlers are run first
|
||||
plugins = [
|
||||
@ -57,7 +59,6 @@ class BarcodeScan(APIView):
|
||||
InvenTreeExternalBarcodePlugin(),
|
||||
] + registry.with_mixin('barcode')
|
||||
|
||||
barcode_data = data.get('barcode')
|
||||
barcode_hash = hash_barcode(barcode_data)
|
||||
|
||||
# Look for a barcode plugin which knows how to deal with this barcode
|
||||
@ -106,10 +107,10 @@ class BarcodeAssign(APIView):
|
||||
|
||||
data = request.data
|
||||
|
||||
if 'barcode' not in data:
|
||||
raise ValidationError({'barcode': _('Must provide barcode_data parameter')})
|
||||
barcode_data = data.get('barcode', None)
|
||||
|
||||
barcode_data = data['barcode']
|
||||
if not barcode_data:
|
||||
raise ValidationError({'barcode': _('Missing barcode data')})
|
||||
|
||||
# Here we only check against 'InvenTree' plugins
|
||||
plugins = [
|
||||
|
@ -55,7 +55,8 @@ class BarcodeAPITest(InvenTreeAPITestCase):
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
data = response.data
|
||||
self.assertIn('error', data)
|
||||
self.assertIn('barcode', data)
|
||||
self.assertIn('Missing barcode data', str(response.data['barcode']))
|
||||
|
||||
def test_find_part(self):
|
||||
"""Test that we can lookup a part based on ID."""
|
||||
|
Loading…
Reference in New Issue
Block a user