add api test

This commit is contained in:
Matthias 2021-11-21 01:57:46 +01:00
parent cecee032d7
commit 046ee7df06
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
2 changed files with 56 additions and 0 deletions

View File

@ -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

View File

@ -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