From f666772f387ccd3362f5193f7526b6609210117b Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 22 Dec 2022 10:51:51 +1100 Subject: [PATCH] Use GITHUB_TOKEN for API unit test (#4094) * Use GITHUB_TOKEN for API unit test (cherry picked from commit c988b09d76b7c4521707a097006386fcd3c26dcf) * Fix CI test * Make use of URL which does not have rate limiting --- InvenTree/plugin/base/integration/test_mixins.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/InvenTree/plugin/base/integration/test_mixins.py b/InvenTree/plugin/base/integration/test_mixins.py index d48b0ddc30..c2361c731b 100644 --- a/InvenTree/plugin/base/integration/test_mixins.py +++ b/InvenTree/plugin/base/integration/test_mixins.py @@ -1,5 +1,7 @@ """Unit tests for base mixins for plugins.""" +import os + from django.conf import settings from django.test import TestCase from django.urls import include, re_path, reverse @@ -203,6 +205,13 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): self.mixin = MixinCls() + # If running in github workflow, make use of GITHUB_TOKEN + if settings.TESTING: + token = os.getenv('GITHUB_TOKEN', None) + + if token: + self.mixin.set_setting('API_TOKEN', token) + class WrongCLS(APICallMixin, InvenTreePlugin): pass @@ -222,7 +231,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): # api_headers headers = self.mixin.api_headers - self.assertEqual(headers, {'Bearer': '', 'Content-Type': 'application/json'}) + self.assertEqual(headers['Content-Type'], 'application/json') def test_args(self): """Test that building up args work.""" @@ -252,7 +261,7 @@ class APICallMixinTest(BaseMixinDefinition, TestCase): self.assertEqual(result.reason, 'OK') # api_call with full url - result = self.mixin.api_call('orgs/inventree') + result = self.mixin.api_call('rate_limit') self.assertTrue(result) # api_call with post and data