From cb1298847e4fafbf6cd1b4f7b7b4833ca867ae0a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 14 Apr 2020 01:18:57 +1000 Subject: [PATCH] Load barcode plugins and throw test data at them --- InvenTree/InvenTree/api.py | 30 ++++++++++++++++++++++++++---- InvenTree/InvenTree/test_api.py | 4 ++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/InvenTree/InvenTree/api.py b/InvenTree/InvenTree/api.py index e242f07e0f..6cdfbf0397 100644 --- a/InvenTree/InvenTree/api.py +++ b/InvenTree/InvenTree/api.py @@ -6,10 +6,14 @@ Main JSON interface views from __future__ import unicode_literals from django.http import JsonResponse +from rest_framework.response import Response +from rest_framework.views import APIView from .views import AjaxView from .version import inventreeVersion, inventreeInstanceName +from plugins import plugins as inventree_plugins + class InfoView(AjaxView): """ Simple JSON endpoint for InvenTree information. @@ -27,15 +31,33 @@ class InfoView(AjaxView): return JsonResponse(data) -class BarcodeScanView(AjaxView): +class BarcodeScanView(APIView): """ Endpoint for handling barcode scan requests. + + Barcode data are decoded by the client application, + and sent to this endpoint (as a JSON object) for validation. + + A barcode could follow the internal InvenTree barcode format, + or it could match to a third-party barcode format (e.g. Digikey). + """ - def get(self, request, *args, **kwargs): - + def post(self, request, *args, **kwargs): + data = { 'barcode': 'Hello world', } - return JsonResponse(data) + plugins = inventree_plugins.load_barcode_plugins() + + for plugin in plugins: + print("Testing plugin:", plugin.PLUGIN_NAME) + if plugin().validate_barcode(request.data): + print("success!") + + return Response({ + 'success': 'OK', + 'data': data, + 'post': request.data, + }) diff --git a/InvenTree/InvenTree/test_api.py b/InvenTree/InvenTree/test_api.py index b7dbed8c76..5b13663897 100644 --- a/InvenTree/InvenTree/test_api.py +++ b/InvenTree/InvenTree/test_api.py @@ -83,5 +83,5 @@ class APITests(APITestCase): self.assertEqual(response.status_code, status.HTTP_200_OK) def test_barcode(self): - - url = reverse('api-barcode-view') \ No newline at end of file + # TODO - Complete this + pass