barcode / InvenTreePugin test errors

This commit is contained in:
Matthias 2022-03-12 03:09:37 +01:00
parent 3a2b52ae53
commit a4737a1a2f
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -214,3 +214,48 @@ class BarcodeAPITest(APITestCase):
self.assertIn('error', data)
self.assertNotIn('success', data)
class TestInvenTreeBarcode(APITestCase):
fixtures = [
'category',
'part',
'location',
'stock'
]
def setUp(self):
# Create a user for auth
user = get_user_model()
user.objects.create_user('testuser', 'test@testing.com', 'password')
self.client.login(username='testuser', password='password')
def test_errors(self):
"""
Test that a barcode can be associated with a StockItem
"""
def test_assert_error(barcode_data):
response = self.client.post(
reverse('api-barcode-link'), format='json',
data={
'barcode': barcode_data,
'stockitem': 522
}
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIn('error', response.data)
# test with already existing stock
test_assert_error('{"stockitem": 522}')
# test with already existing stock location
test_assert_error('{"stocklocation": 7}')
# test with already existing part location
test_assert_error('{"part": 10004}')
# test with hash
test_assert_error('{"blbla": 10004}')