1414
1515import httpx
1616import pytest
17+ import asyncio
18+ from functools import wraps
1719
1820from tests .utils .client_configuration import ClientConfiguration
1921from tests .utils .list_resource import list_data_to_dicts , list_response_of
2628
2729from jwt import PyJWKClient
2830from unittest .mock import Mock , patch
29- from functools import wraps
3031
3132
3233def _get_test_client_setup (
@@ -310,7 +311,19 @@ def inner(
310311
311312def with_jwks_mock (func ):
312313 @wraps (func )
313- def wrapper (* args , ** kwargs ):
314+ async def async_wrapper (* args , ** kwargs ):
315+ # Create mock JWKS client
316+ mock_jwks = Mock (spec = PyJWKClient )
317+ mock_signing_key = Mock ()
318+ mock_signing_key .key = kwargs ["session_constants" ]["PUBLIC_KEY" ]
319+ mock_jwks .get_signing_key_from_jwt .return_value = mock_signing_key
320+
321+ # Apply the mock
322+ with patch ("workos.session.PyJWKClient" , return_value = mock_jwks ):
323+ return await func (* args , ** kwargs )
324+
325+ @wraps (func )
326+ def sync_wrapper (* args , ** kwargs ):
314327 # Create mock JWKS client
315328 mock_jwks = Mock (spec = PyJWKClient )
316329 mock_signing_key = Mock ()
@@ -321,4 +334,7 @@ def wrapper(*args, **kwargs):
321334 with patch ("workos.session.PyJWKClient" , return_value = mock_jwks ):
322335 return func (* args , ** kwargs )
323336
324- return wrapper
337+ # Return appropriate wrapper based on whether the function is async or not
338+ if asyncio .iscoroutinefunction (func ):
339+ return async_wrapper
340+ return sync_wrapper
0 commit comments