Skip to content

Commit e92fade

Browse files
fix: update imports and improve error handling in tests
1 parent c767308 commit e92fade

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

tests/test_api_client.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
from freezegun import freeze_time
2121
from pytest_httpx import HTTPXMock
2222

23-
from auth0_api_python.api_client import ApiClient
23+
from auth0_api_python.api_client import MAX_ARRAY_VALUES_PER_KEY, ApiClient
2424
from auth0_api_python.config import ApiClientOptions
2525
from auth0_api_python.errors import (
2626
ApiError,
27+
ConfigurationError,
28+
DomainsResolverError,
2729
GetAccessTokenForConnectionError,
2830
GetTokenByExchangeProfileError,
2931
InvalidAuthSchemeError,
@@ -52,7 +54,7 @@ async def test_init_missing_args():
5254
"""
5355
Test that providing no audience or domain raises an error.
5456
"""
55-
from auth0_api_python.errors import ConfigurationError
57+
5658

5759
# Empty domain now raises ConfigurationError (not MissingRequiredArgumentError)
5860
with pytest.raises(ConfigurationError):
@@ -2206,7 +2208,7 @@ async def test_get_token_by_exchange_profile_extra_params_denylist(httpx_mock: H
22062208
@pytest.mark.asyncio
22072209
async def test_extra_array_exact_limit_passes(mock_discovery, api_client_confidential, httpx_mock):
22082210
"""Test that array with exactly MAX_ARRAY_VALUES_PER_KEY passes."""
2209-
from auth0_api_python.api_client import MAX_ARRAY_VALUES_PER_KEY
2211+
22102212

22112213
httpx_mock.add_response(
22122214
method="POST",
@@ -2230,7 +2232,7 @@ async def test_extra_array_exact_limit_passes(mock_discovery, api_client_confide
22302232
@pytest.mark.asyncio
22312233
async def test_extra_array_limit(mock_discovery, api_client_confidential):
22322234
"""Test that array size limit is enforced (DoS protection)."""
2233-
from auth0_api_python.api_client import MAX_ARRAY_VALUES_PER_KEY
2235+
22342236

22352237
# Create array exceeding limit
22362238
big = list(map(str, range(MAX_ARRAY_VALUES_PER_KEY + 1)))
@@ -2618,7 +2620,6 @@ async def test_token_response_parsing(
26182620
assert result["access_token"] == "t"
26192621

26202622
# Verify expires_at calculation (deterministic with frozen time)
2621-
import time
26222623
expected_expires_at = int(time.time()) + expected_expires_in
26232624
assert result["expires_at"] == expected_expires_at
26242625
else:
@@ -2784,7 +2785,7 @@ async def test_get_token_by_exchange_profile_custom_timeout_honored(httpx_mock:
27842785
@pytest.mark.asyncio
27852786
async def test_mcd_init_missing_domain_and_domains():
27862787
"""Test that providing neither domain nor domains raises ConfigurationError."""
2787-
from auth0_api_python.errors import ConfigurationError
2788+
27882789

27892790
with pytest.raises(ConfigurationError) as err:
27902791
_ = ApiClient(ApiClientOptions(audience="my-audience"))
@@ -2842,7 +2843,7 @@ async def test_mcd_init_with_both_domain_and_domains():
28422843
@pytest.mark.asyncio
28432844
async def test_mcd_init_with_empty_domains_list():
28442845
"""Test that empty domains list raises ConfigurationError."""
2845-
from auth0_api_python.errors import ConfigurationError
2846+
28462847

28472848
with pytest.raises(ConfigurationError) as err:
28482849
_ = ApiClient(ApiClientOptions(
@@ -2871,7 +2872,7 @@ def my_resolver(context: dict) -> list[str]:
28712872
@pytest.mark.asyncio
28722873
async def test_mcd_init_with_invalid_domains_type():
28732874
"""Test that invalid domains type raises ConfigurationError."""
2874-
from auth0_api_python.errors import ConfigurationError
2875+
28752876

28762877
with pytest.raises(ConfigurationError) as err:
28772878
_ = ApiClient(ApiClientOptions(
@@ -2945,7 +2946,7 @@ def my_resolver(context: dict) -> list[str]:
29452946
@pytest.mark.asyncio
29462947
async def test_mcd_resolve_allowed_domains_resolver_error():
29472948
"""Test that resolver errors are wrapped in DomainsResolverError."""
2948-
from auth0_api_python.errors import DomainsResolverError
2949+
29492950

29502951
def failing_resolver(context: dict) -> list[str]:
29512952
raise ValueError("Database connection failed")
@@ -2965,7 +2966,7 @@ def failing_resolver(context: dict) -> list[str]:
29652966
@pytest.mark.asyncio
29662967
async def test_mcd_resolve_allowed_domains_resolver_invalid_return_type():
29672968
"""Test that resolver must return a list."""
2968-
from auth0_api_python.errors import DomainsResolverError
2969+
29692970

29702971
def bad_resolver(context: dict) -> str:
29712972
return "tenant1.auth0.com" # Should return list, not string
@@ -2984,7 +2985,7 @@ def bad_resolver(context: dict) -> str:
29842985
@pytest.mark.asyncio
29852986
async def test_mcd_resolve_allowed_domains_resolver_empty_list():
29862987
"""Test that resolver cannot return empty list."""
2987-
from auth0_api_python.errors import DomainsResolverError
2988+
29882989

29892990
def empty_resolver(context: dict) -> list[str]:
29902991
return []
@@ -3045,9 +3046,6 @@ async def test_mcd_resolve_allowed_domains_single_domain_mode():
30453046
@pytest.mark.asyncio
30463047
async def test_mcd_verify_rejects_symmetric_algorithm():
30473048
"""Test that verify_access_token rejects tokens with symmetric algorithms (HS256)."""
3048-
import base64
3049-
import json
3050-
30513049
# Create a token with HS256 algorithm in header (without actually signing it)
30523050
header = {"alg": "HS256", "typ": "JWT", "kid": "test-key"}
30533051
payload = {

0 commit comments

Comments
 (0)