2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

backport reqres token fix to 0.17.x (#9685)

backports the fix from https://github.com/inventree/InvenTree/pull/9585
This commit is contained in:
Matthias Mair
2025-05-21 07:43:59 +02:00
committed by GitHub
parent 7959b6e597
commit 9b759d2689
2 changed files with 15 additions and 2 deletions

View File

@ -209,7 +209,11 @@ class APICallMixinTest(BaseMixinDefinition, TestCase):
NAME = 'Sample API Caller' NAME = 'Sample API Caller'
SETTINGS = { SETTINGS = {
'API_TOKEN': {'name': 'API Token', 'protected': True}, 'API_TOKEN': {
'name': 'API Token',
'protected': True,
'default': 'reqres-free-v1',
},
'API_URL': { 'API_URL': {
'name': 'External URL', 'name': 'External URL',
'description': 'Where is your API located?', 'description': 'Where is your API located?',
@ -219,6 +223,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase):
API_URL_SETTING = 'API_URL' API_URL_SETTING = 'API_URL'
API_TOKEN_SETTING = 'API_TOKEN' API_TOKEN_SETTING = 'API_TOKEN'
API_TOKEN = 'x-api-key'
@property @property
def api_url(self): def api_url(self):
@ -289,6 +294,8 @@ class APICallMixinTest(BaseMixinDefinition, TestCase):
self.assertTrue(result) self.assertTrue(result)
self.assertEqual(result.reason, 'OK') self.assertEqual(result.reason, 'OK')
# Set API TOKEN
self.mixin.set_setting('API_TOKEN', 'reqres-free-v1')
# api_call with post and data # api_call with post and data
result = self.mixin.api_call( result = self.mixin.api_call(
'https://reqres.in/api/users/', 'https://reqres.in/api/users/',
@ -298,6 +305,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase):
) )
self.assertTrue(result) self.assertTrue(result)
self.assertNotIn('error', result)
self.assertEqual(result['name'], 'morpheus') self.assertEqual(result['name'], 'morpheus')
# api_call with endpoint with leading slash # api_call with endpoint with leading slash

View File

@ -10,7 +10,11 @@ class SampleApiCallerPlugin(APICallMixin, SettingsMixin, InvenTreePlugin):
NAME = 'Sample API Caller' NAME = 'Sample API Caller'
SETTINGS = { SETTINGS = {
'API_TOKEN': {'name': 'API Token', 'protected': True}, 'API_TOKEN': {
'name': 'API Token',
'protected': True,
'default': 'reqres-free-v1',
},
'API_URL': { 'API_URL': {
'name': 'External URL', 'name': 'External URL',
'description': 'Where is your API located?', 'description': 'Where is your API located?',
@ -19,6 +23,7 @@ class SampleApiCallerPlugin(APICallMixin, SettingsMixin, InvenTreePlugin):
} }
API_URL_SETTING = 'API_URL' API_URL_SETTING = 'API_URL'
API_TOKEN_SETTING = 'API_TOKEN' API_TOKEN_SETTING = 'API_TOKEN'
API_TOKEN = 'x-api-key'
def get_external_url(self): def get_external_url(self):
"""Returns data from the sample endpoint.""" """Returns data from the sample endpoint."""