diff --git a/InvenTree/plugin/serializers.py b/InvenTree/plugin/serializers.py index 6e19eb2559..e25e253498 100644 --- a/InvenTree/plugin/serializers.py +++ b/InvenTree/plugin/serializers.py @@ -108,6 +108,7 @@ class PluginConfigInstallSerializer(serializers.Serializer): try: result = subprocess.check_output(command, cwd=os.path.dirname(settings.BASE_DIR)) ret['result'] = str(result, 'utf-8') + ret['success'] = True except subprocess.CalledProcessError as error: ret['result'] = str(error.output, 'utf-8') ret['error'] = True diff --git a/InvenTree/plugin/test_api.py b/InvenTree/plugin/test_api.py new file mode 100644 index 0000000000..ee99bbfadd --- /dev/null +++ b/InvenTree/plugin/test_api.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.urls import reverse + +from InvenTree.api_tester import InvenTreeAPITestCase + + +class PluginDetailAPITest(InvenTreeAPITestCase): + """ + Tests the plugin AP I endpoints + """ + + roles = [ + 'admin.add', + 'admin.view', + 'admin.change', + 'admin.delete', + ] + + def setUp(self): + self.MSG_NO_PKG = 'Either packagenmae of url must be provided' + + self.PKG_NAME = 'minimal' + super().setUp() + + def test_plugin_install(self): + """ + Test the plugin install command + """ + url = reverse('api-plugin-install') + + # valid - Pypi + data = self.post(url, { + 'confirm': True, + 'packagename': self.PKG_NAME + }, expected_code=201).data + + self.assertEqual(data['success'], True) + + # invalid tries + # no input + self.post(url, {}, expected_code=400) + + # no package info + data = self.post(url, { + 'confirm': True, + }, expected_code=400).data + self.assertEqual(data['url'][0].title().upper(), self.MSG_NO_PKG.upper()) + self.assertEqual(data['packagename'][0].title().upper(), self.MSG_NO_PKG.upper()) + + # not confirmed + data = self.post(url, { + 'packagename': self.PKG_NAME + }, expected_code=400).data