Skip to content

Commit 8ec1f0f

Browse files
committed
test: consolidate auth mechanism smoketests
Consolidate redundant auth mechanism tests into parameterized tests: - Replace 3 separate test methods with 1 parameterized test per file - Remove duplicate test_gateway_config_with_authorization_header - Maintain equivalent test coverage with less code duplication Addresses reviewer feedback on PR #736. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent e4979d2 commit 8ec1f0f

File tree

2 files changed

+34
-80
lines changed

2 files changed

+34
-80
lines changed

tests/smoketests/sdk/test_async_gateway_config.py

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -149,52 +149,29 @@ class TestAsyncGatewayConfigAuthMechanisms:
149149
"""Test different async gateway config auth mechanism types."""
150150

151151
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
152-
async def test_gateway_config_with_bearer_auth(self, async_sdk_client: AsyncRunloopSDK) -> None:
153-
"""Test creating a gateway config with bearer auth."""
152+
@pytest.mark.parametrize(
153+
"auth_mechanism,expected_type,expected_key",
154+
[
155+
({"type": "bearer"}, "bearer", None),
156+
({"type": "header", "key": "x-api-key"}, "header", "x-api-key"),
157+
],
158+
)
159+
async def test_gateway_config_auth_mechanisms(
160+
self, async_sdk_client: AsyncRunloopSDK, auth_mechanism: dict, expected_type: str, expected_key: str | None
161+
) -> None:
162+
"""Test creating gateway configs with different auth mechanisms."""
154163
gateway_config = await async_sdk_client.gateway_config.create(
155-
name=unique_name("sdk-async-gateway-bearer"),
156-
endpoint="https://api.bearer-test.com",
157-
auth_mechanism={"type": "bearer"},
164+
name=unique_name(f"sdk-async-gateway-{expected_type}"),
165+
endpoint=f"https://api.{expected_type}-test.com",
166+
auth_mechanism=auth_mechanism,
158167
)
159168

160169
try:
161170
info = await gateway_config.get_info()
162171
assert info.auth_mechanism is not None
163-
assert info.auth_mechanism.type == "bearer"
164-
finally:
165-
await gateway_config.delete()
166-
167-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
168-
async def test_gateway_config_with_header_auth(self, async_sdk_client: AsyncRunloopSDK) -> None:
169-
"""Test creating a gateway config with header auth."""
170-
gateway_config = await async_sdk_client.gateway_config.create(
171-
name=unique_name("sdk-async-gateway-header"),
172-
endpoint="https://api.header-test.com",
173-
auth_mechanism={"type": "header", "key": "x-api-key"},
174-
)
175-
176-
try:
177-
info = await gateway_config.get_info()
178-
assert info.auth_mechanism is not None
179-
assert info.auth_mechanism.type == "header"
180-
assert info.auth_mechanism.key == "x-api-key"
181-
finally:
182-
await gateway_config.delete()
183-
184-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
185-
async def test_gateway_config_with_authorization_header(self, async_sdk_client: AsyncRunloopSDK) -> None:
186-
"""Test creating a gateway config with Authorization header."""
187-
gateway_config = await async_sdk_client.gateway_config.create(
188-
name=unique_name("sdk-async-gateway-auth-header"),
189-
endpoint="https://api.auth-header-test.com",
190-
auth_mechanism={"type": "header", "key": "Authorization"},
191-
)
192-
193-
try:
194-
info = await gateway_config.get_info()
195-
assert info.auth_mechanism is not None
196-
assert info.auth_mechanism.type == "header"
197-
assert info.auth_mechanism.key == "Authorization"
172+
assert info.auth_mechanism.type == expected_type
173+
if expected_key is not None:
174+
assert info.auth_mechanism.key == expected_key
198175
finally:
199176
await gateway_config.delete()
200177

tests/smoketests/sdk/test_gateway_config.py

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -149,52 +149,29 @@ class TestGatewayConfigAuthMechanisms:
149149
"""Test different gateway config auth mechanism types."""
150150

151151
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
152-
def test_gateway_config_with_bearer_auth(self, sdk_client: RunloopSDK) -> None:
153-
"""Test creating a gateway config with bearer auth."""
152+
@pytest.mark.parametrize(
153+
"auth_mechanism,expected_type,expected_key",
154+
[
155+
({"type": "bearer"}, "bearer", None),
156+
({"type": "header", "key": "x-api-key"}, "header", "x-api-key"),
157+
],
158+
)
159+
def test_gateway_config_auth_mechanisms(
160+
self, sdk_client: RunloopSDK, auth_mechanism: dict, expected_type: str, expected_key: str | None
161+
) -> None:
162+
"""Test creating gateway configs with different auth mechanisms."""
154163
gateway_config = sdk_client.gateway_config.create(
155-
name=unique_name("sdk-gateway-bearer"),
156-
endpoint="https://api.bearer-test.com",
157-
auth_mechanism={"type": "bearer"},
164+
name=unique_name(f"sdk-gateway-{expected_type}"),
165+
endpoint=f"https://api.{expected_type}-test.com",
166+
auth_mechanism=auth_mechanism,
158167
)
159168

160169
try:
161170
info = gateway_config.get_info()
162171
assert info.auth_mechanism is not None
163-
assert info.auth_mechanism.type == "bearer"
164-
finally:
165-
gateway_config.delete()
166-
167-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
168-
def test_gateway_config_with_header_auth(self, sdk_client: RunloopSDK) -> None:
169-
"""Test creating a gateway config with header auth."""
170-
gateway_config = sdk_client.gateway_config.create(
171-
name=unique_name("sdk-gateway-header"),
172-
endpoint="https://api.header-test.com",
173-
auth_mechanism={"type": "header", "key": "x-api-key"},
174-
)
175-
176-
try:
177-
info = gateway_config.get_info()
178-
assert info.auth_mechanism is not None
179-
assert info.auth_mechanism.type == "header"
180-
assert info.auth_mechanism.key == "x-api-key"
181-
finally:
182-
gateway_config.delete()
183-
184-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
185-
def test_gateway_config_with_authorization_header(self, sdk_client: RunloopSDK) -> None:
186-
"""Test creating a gateway config with Authorization header."""
187-
gateway_config = sdk_client.gateway_config.create(
188-
name=unique_name("sdk-gateway-auth-header"),
189-
endpoint="https://api.auth-header-test.com",
190-
auth_mechanism={"type": "header", "key": "Authorization"},
191-
)
192-
193-
try:
194-
info = gateway_config.get_info()
195-
assert info.auth_mechanism is not None
196-
assert info.auth_mechanism.type == "header"
197-
assert info.auth_mechanism.key == "Authorization"
172+
assert info.auth_mechanism.type == expected_type
173+
if expected_key is not None:
174+
assert info.auth_mechanism.key == expected_key
198175
finally:
199176
gateway_config.delete()
200177

0 commit comments

Comments
 (0)