mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
add api test
This commit is contained in:
parent
cecee032d7
commit
046ee7df06
@ -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
|
||||
|
55
InvenTree/plugin/test_api.py
Normal file
55
InvenTree/plugin/test_api.py
Normal 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
|
Loading…
Reference in New Issue
Block a user