mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
unittests fdor ApiCallMixin
This commit is contained in:
parent
c699ced34a
commit
31d587a9b1
@ -8,7 +8,7 @@ from django.contrib.auth import get_user_model
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from plugin import IntegrationPluginBase
|
from plugin import IntegrationPluginBase
|
||||||
from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin
|
from plugin.mixins import AppMixin, SettingsMixin, UrlsMixin, NavigationMixin, APICallMixin
|
||||||
from plugin.urls import PLUGIN_BASE
|
from plugin.urls import PLUGIN_BASE
|
||||||
|
|
||||||
|
|
||||||
@ -142,6 +142,50 @@ class NavigationMixinTest(BaseMixinDefinition, TestCase):
|
|||||||
self.assertEqual(self.nothing_mixin.navigation_name, '')
|
self.assertEqual(self.nothing_mixin.navigation_name, '')
|
||||||
|
|
||||||
|
|
||||||
|
class APICallMixinTest(BaseMixinDefinition, TestCase):
|
||||||
|
MIXIN_HUMAN_NAME = 'API calls'
|
||||||
|
MIXIN_NAME = 'api_call'
|
||||||
|
MIXIN_ENABLE_CHECK = 'has_api_call'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
class MixinCls(APICallMixin, SettingsMixin, IntegrationPluginBase):
|
||||||
|
PLUGIN_NAME = "Sample API Caller"
|
||||||
|
|
||||||
|
SETTINGS = {
|
||||||
|
'API_TOKEN': {
|
||||||
|
'name': 'API Token',
|
||||||
|
'protected': True,
|
||||||
|
},
|
||||||
|
'API_URL': {
|
||||||
|
'name': 'External URL',
|
||||||
|
'description': 'Where is your API located?',
|
||||||
|
'default': 'reqres.in',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
API_URL_SETTING = 'API_URL'
|
||||||
|
API_TOKEN_SETTING = 'API_TOKEN'
|
||||||
|
|
||||||
|
def get_external_url(self):
|
||||||
|
'''
|
||||||
|
returns data from the sample endpoint
|
||||||
|
'''
|
||||||
|
return self.api_call('api/users/2')
|
||||||
|
self.mixin = MixinCls()
|
||||||
|
def test_function(self):
|
||||||
|
# api_url
|
||||||
|
self.assertEqual('https://reqres.in', self.mixin.api_url)
|
||||||
|
|
||||||
|
# api_headers
|
||||||
|
headers = self.mixin.api_headers
|
||||||
|
self.assertEqual(headers, {'Bearer': '', 'Content-Type': 'application/json'})
|
||||||
|
|
||||||
|
# api_build_url_args
|
||||||
|
# api_call
|
||||||
|
result = self.mixin.get_external_url()
|
||||||
|
self.assertTrue(result)
|
||||||
|
self.assertIn('data', result,)
|
||||||
|
|
||||||
|
|
||||||
class IntegrationPluginBaseTests(TestCase):
|
class IntegrationPluginBaseTests(TestCase):
|
||||||
""" Tests for IntegrationPluginBase """
|
""" Tests for IntegrationPluginBase """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user