From 9b759d2689e8b48c9c749afdb6ded98bc906d42d Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Wed, 21 May 2025 07:43:59 +0200 Subject: [PATCH] backport reqres token fix to 0.17.x (#9685) backports the fix from https://github.com/inventree/InvenTree/pull/9585 --- .../InvenTree/plugin/base/integration/test_mixins.py | 10 +++++++++- .../InvenTree/plugin/samples/integration/api_caller.py | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/backend/InvenTree/plugin/base/integration/test_mixins.py b/src/backend/InvenTree/plugin/base/integration/test_mixins.py index c5cf6aa195..6b1ce091e8 100644 --- a/src/backend/InvenTree/plugin/base/integration/test_mixins.py +++ b/src/backend/InvenTree/plugin/base/integration/test_mixins.py @@ -209,7 +209,11 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): NAME = 'Sample API Caller' SETTINGS = { - 'API_TOKEN': {'name': 'API Token', 'protected': True}, + 'API_TOKEN': { + 'name': 'API Token', + 'protected': True, + 'default': 'reqres-free-v1', + }, 'API_URL': { 'name': 'External URL', 'description': 'Where is your API located?', @@ -219,6 +223,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): API_URL_SETTING = 'API_URL' API_TOKEN_SETTING = 'API_TOKEN' + API_TOKEN = 'x-api-key' @property def api_url(self): @@ -289,6 +294,8 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): self.assertTrue(result) self.assertEqual(result.reason, 'OK') + # Set API TOKEN + self.mixin.set_setting('API_TOKEN', 'reqres-free-v1') # api_call with post and data result = self.mixin.api_call( 'https://reqres.in/api/users/', @@ -298,6 +305,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): ) self.assertTrue(result) + self.assertNotIn('error', result) self.assertEqual(result['name'], 'morpheus') # api_call with endpoint with leading slash diff --git a/src/backend/InvenTree/plugin/samples/integration/api_caller.py b/src/backend/InvenTree/plugin/samples/integration/api_caller.py index ea78f175c5..759a02c88b 100644 --- a/src/backend/InvenTree/plugin/samples/integration/api_caller.py +++ b/src/backend/InvenTree/plugin/samples/integration/api_caller.py @@ -10,7 +10,11 @@ class SampleApiCallerPlugin(APICallMixin, SettingsMixin, InvenTreePlugin): NAME = 'Sample API Caller' SETTINGS = { - 'API_TOKEN': {'name': 'API Token', 'protected': True}, + 'API_TOKEN': { + 'name': 'API Token', + 'protected': True, + 'default': 'reqres-free-v1', + }, 'API_URL': { 'name': 'External URL', 'description': 'Where is your API located?', @@ -19,6 +23,7 @@ class SampleApiCallerPlugin(APICallMixin, SettingsMixin, InvenTreePlugin): } API_URL_SETTING = 'API_URL' API_TOKEN_SETTING = 'API_TOKEN' + API_TOKEN = 'x-api-key' def get_external_url(self): """Returns data from the sample endpoint."""