11from types import MethodType
2- from unittest . mock import PropertyMock , patch
2+ from typing import Generator
33
44from httpx import Request , codes
55from pyfakefs .fake_filesystem_unittest import Patcher
66from pytest import mark
77from pytest_httpx import HTTPXMock
88
9- from firebolt .client .auth import Auth
10- from firebolt .utils .token_storage import TokenSecureStorage
9+ from firebolt .client .auth import Auth , ClientCredentials
10+ from firebolt .utils .cache import _firebolt_cache
11+ from tests .unit .test_cache_helpers import get_cached_token
1112from tests .unit .util import execute_generator_requests
1213
1314
@@ -89,6 +90,7 @@ def test_auth_token_storage(
8990 client_id : str ,
9091 client_secret : str ,
9192 access_token : str ,
93+ enable_cache : Generator ,
9294) -> None :
9395 # Mock auth flow
9496 def set_token (token : str ) -> callable :
@@ -101,29 +103,28 @@ def inner(self):
101103
102104 url = "https://host"
103105 httpx_mock .add_response (status_code = codes .OK , url = url )
104- with Patcher (), patch (
105- "firebolt.client.auth.base.Auth._token_storage" ,
106- new_callable = PropertyMock ,
107- return_value = TokenSecureStorage (client_id , client_secret ),
108- ):
109- auth = Auth (use_token_cache = True )
106+
107+ # Test with caching enabled
108+ with Patcher ():
109+ auth = ClientCredentials (client_id , client_secret , use_token_cache = True )
110110 # Get token
111111 auth .get_new_token_generator = MethodType (set_token (access_token ), auth )
112112 execute_generator_requests (auth .auth_flow (Request ("GET" , url )))
113113
114- st = TokenSecureStorage (client_id , client_secret )
115- assert st .get_cached_token () == access_token , "Invalid token value cached"
114+ # Verify token was cached using the new cache system
115+ cached_token = get_cached_token (client_id , client_secret , None )
116+ assert cached_token == access_token , "Invalid token value cached"
117+
118+ # Clear cache before second test
119+ _firebolt_cache .clear ()
116120
117- with Patcher (), patch (
118- "firebolt.client.auth.base.Auth._token_storage" ,
119- new_callable = PropertyMock ,
120- return_value = TokenSecureStorage (client_id , client_secret ),
121- ):
122- auth = Auth (use_token_cache = False )
121+ # Test with caching disabled
122+ with Patcher ():
123+ auth = ClientCredentials (client_id , client_secret , use_token_cache = False )
123124 # Get token
124125 auth .get_new_token_generator = MethodType (set_token (access_token ), auth )
125126 execute_generator_requests (auth .auth_flow (Request ("GET" , url )))
126- st = TokenSecureStorage ( client_id , client_secret )
127- assert (
128- st . get_cached_token () is None
129- ) , "Token cached even though caching is disabled"
127+
128+ # Verify token was not cached
129+ cached_token = get_cached_token (client_id , client_secret , None )
130+ assert cached_token is None , "Token cached even though caching is disabled"
0 commit comments