Skip to content

Commit 7a66b79

Browse files
authored
Merge pull request #51 from stax-labs/fix/token_caching
fix(token_caching): Adjust API Auth to refresh expired tokens
2 parents a72fb23 + 22d06f4 commit 7a66b79

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

staxapp/api.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ def _headers(cls, custom_headers) -> dict:
2626
@classmethod
2727
def _auth(cls, **kwargs):
2828
if not cls._requests_auth:
29-
cls._requests_auth = Config.get_auth_class().requests_auth(
30-
Config.access_key, Config.secret_key, **kwargs
31-
)
32-
return cls._requests_auth
29+
cls._requests_auth = Config.get_auth_class().requests_auth
30+
return cls._requests_auth(Config.access_key, Config.secret_key, **kwargs)
3331

3432
@staticmethod
3533
def handle_api_response(response):

tests/test_api.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@ class StaxApiTests(unittest.TestCase):
2020

2121
def setUp(self):
2222
self.Api = Api
23-
self.Api._requests_auth = ("username", "password")
23+
self.Api._requests_auth = lambda x, y: (x, y)
2424

2525
def testAuth(self):
26+
27+
Config.access_key = "1"
28+
Config.secret_key = "2"
29+
30+
auth = self.Api._auth()
31+
self.assertEqual(self.Api._requests_auth("1", "2"), auth)
32+
33+
Config.access_key = "3"
34+
Config.secret_key = "4"
35+
2636
auth = self.Api._auth()
27-
self.assertEqual(self.Api._requests_auth, auth)
37+
self.assertEqual(self.Api._requests_auth("3", "4"), auth)
2838

2939
@responses.activate
3040
def testGet(self):

tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StaxClientTests(unittest.TestCase):
2121

2222
def setUp(self):
2323
self.Api = Api
24-
self.Api._requests_auth = ("username", "password")
24+
self.Api._requests_auth = lambda x, y: (x, y)
2525

2626
self.account_client = StaxClient("accounts")
2727
self.workload_client = StaxClient("workloads")

0 commit comments

Comments
 (0)