From 91012d2788401560df9109a52a0c2b3829cb5607 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 17 Apr 2020 08:40:37 +1000 Subject: [PATCH 1/2] Delete unused import --- InvenTree/plugins/barcode/barcode.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/InvenTree/plugins/barcode/barcode.py b/InvenTree/plugins/barcode/barcode.py index f8bd82f744..b8084171fd 100644 --- a/InvenTree/plugins/barcode/barcode.py +++ b/InvenTree/plugins/barcode/barcode.py @@ -2,8 +2,6 @@ import hashlib -from rest_framework.renderers import JSONRenderer - from stock.serializers import StockItemSerializer, LocationSerializer from part.serializers import PartSerializer From 75fed2ebdde022aed4b4ba0851edc5e0afe7f6f0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 17 Apr 2020 08:40:59 +1000 Subject: [PATCH 2/2] Unit testing for barcode API endpoint --- InvenTree/InvenTree/test_api.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/test_api.py b/InvenTree/InvenTree/test_api.py index 5b13663897..e75a111e5d 100644 --- a/InvenTree/InvenTree/test_api.py +++ b/InvenTree/InvenTree/test_api.py @@ -27,6 +27,18 @@ class APITests(APITestCase): User = get_user_model() User.objects.create_user(self.username, 'user@email.com', self.password) + def get_token(self): + token_url = reverse('api-token') + + # POST to retreive a token + response = self.client.post(token_url, format='json', data={'username': self.username, 'password': self.password}) + + token = response.data['token'] + + self.client.credentials(HTTP_AUTHORIZATION='Token ' + token) + + self.token = token + def test_info_view(self): """ Test that we can read the 'info-view' endpoint. @@ -83,5 +95,22 @@ class APITests(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) def test_barcode(self): - # TODO - Complete this - pass + """ Test the barcode endpoint """ + + url = reverse('api-barcode-plugin') + + self.get_token() + + data = { + 'barcode': { + 'asdlaksdfalsdkfsa;fdlkasd;' + }, + } + + response = self.client.post(url, format='json', data=data) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + + self.assertIn('error', response.data) + self.assertIn('barcode_data', response.data) + self.assertEqual(response.data['error'], 'Unknown barcode format')