mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-05 23:08:48 +00:00
Add unit tests for barcode scanning API
This commit is contained in:
parent
0f48ca6008
commit
9b14a41e83
@ -52,7 +52,7 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
|
|||||||
# If any of the following keys are in the JSON data,
|
# If any of the following keys are in the JSON data,
|
||||||
# let's go ahead and assume that the code is a valid InvenTree one...
|
# let's go ahead and assume that the code is a valid InvenTree one...
|
||||||
|
|
||||||
for key in ['tool', 'version', 'InvenTree', 'stockitem', 'location', 'part']:
|
for key in ['tool', 'version', 'InvenTree', 'stockitem', 'stocklocation', 'part']:
|
||||||
if key in self.data.keys():
|
if key in self.data.keys():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -56,6 +56,66 @@ class BarcodeAPITest(APITestCase):
|
|||||||
self.assertIn('plugin', data)
|
self.assertIn('plugin', data)
|
||||||
self.assertIsNone(data['plugin'])
|
self.assertIsNone(data['plugin'])
|
||||||
|
|
||||||
|
def test_find_part(self):
|
||||||
|
"""
|
||||||
|
Test that we can lookup a part based on ID
|
||||||
|
"""
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
self.scan_url,
|
||||||
|
{
|
||||||
|
'barcode': {
|
||||||
|
'part': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
format='json',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertIn('part', response.data)
|
||||||
|
self.assertIn('barcode_data', response.data)
|
||||||
|
self.assertEqual(response.data['part']['pk'], 1)
|
||||||
|
|
||||||
|
def test_find_stock_item(self):
|
||||||
|
"""
|
||||||
|
Test that we can lookup a stock item based on ID
|
||||||
|
"""
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
self.scan_url,
|
||||||
|
{
|
||||||
|
'barcode': {
|
||||||
|
'stockitem': 1,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
format='json',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertIn('stockitem', response.data)
|
||||||
|
self.assertIn('barcode_data', response.data)
|
||||||
|
self.assertEqual(response.data['stockitem']['pk'], 1)
|
||||||
|
|
||||||
|
def test_find_location(self):
|
||||||
|
"""
|
||||||
|
Test that we can lookup a stock location based on ID
|
||||||
|
"""
|
||||||
|
|
||||||
|
response = self.client.post(
|
||||||
|
self.scan_url,
|
||||||
|
{
|
||||||
|
'barcode': {
|
||||||
|
'stocklocation': 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
format='json'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertIn('stocklocation', response.data)
|
||||||
|
self.assertIn('barcode_data', response.data)
|
||||||
|
self.assertEqual(response.data['stocklocation']['pk'], 1)
|
||||||
|
|
||||||
def test_integer_barcode(self):
|
def test_integer_barcode(self):
|
||||||
|
|
||||||
response = self.postBarcode(self.scan_url, '123456789')
|
response = self.postBarcode(self.scan_url, '123456789')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user