diff --git a/InvenTree/barcodes/tests.py b/InvenTree/barcodes/tests.py index 33b171d666..fd46438c9b 100644 --- a/InvenTree/barcodes/tests.py +++ b/InvenTree/barcodes/tests.py @@ -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}')