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
This commit is contained in:
Oliver 2022-12-22 10:51:51 +11:00 committed by GitHub
parent bae81e8dae
commit f666772f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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