Skip to content

Commit d6ce334

Browse files
committed
cp dines
1 parent 6537713 commit d6ce334

2 files changed

Lines changed: 52 additions & 306 deletions

File tree

tests/smoketests/sdk/test_async_gateway_config.py

Lines changed: 26 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
from runloop_api_client.sdk import AsyncRunloopSDK
88
from tests.smoketests.utils import unique_name
9-
from runloop_api_client.types.gateway_config_create_params import AuthMechanism
109

1110
pytestmark = [pytest.mark.smoketest, pytest.mark.asyncio]
1211

1312
THIRTY_SECOND_TIMEOUT = 30
1413

1514

1615
class TestAsyncGatewayConfigLifecycle:
17-
"""Test basic async gateway config lifecycle operations."""
16+
"""Test async gateway config lifecycle operations."""
1817

1918
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
20-
async def test_gateway_config_create(self, async_sdk_client: AsyncRunloopSDK) -> None:
21-
"""Test creating a gateway config."""
19+
async def test_gateway_config_full_lifecycle(self, async_sdk_client: AsyncRunloopSDK) -> None:
20+
"""Test complete gateway config lifecycle: create, get_info, update, delete."""
21+
# Create
2222
name = unique_name("sdk-async-gateway-config")
2323
gateway_config = await async_sdk_client.gateway_config.create(
2424
name=name,
@@ -31,188 +31,57 @@ async def test_gateway_config_create(self, async_sdk_client: AsyncRunloopSDK) ->
3131
assert gateway_config is not None
3232
assert gateway_config.id is not None
3333
assert len(gateway_config.id) > 0
34-
finally:
35-
await gateway_config.delete()
3634

37-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
38-
async def test_gateway_config_get_info(self, async_sdk_client: AsyncRunloopSDK) -> None:
39-
"""Test retrieving gateway config information."""
40-
name = unique_name("sdk-async-gateway-config-info")
41-
gateway_config = await async_sdk_client.gateway_config.create(
42-
name=name,
43-
endpoint="https://api.example.com",
44-
auth_mechanism={"type": "bearer"},
45-
description="Async test gateway config for get_info",
46-
)
47-
48-
try:
35+
# Get info
4936
info = await gateway_config.get_info()
50-
5137
assert info.id == gateway_config.id
5238
assert info.name == name
5339
assert info.endpoint == "https://api.example.com"
54-
assert info.description == "Async test gateway config for get_info"
40+
assert info.description == "SDK async smoke test gateway config"
5541
assert info.auth_mechanism is not None
5642
assert info.auth_mechanism.type == "bearer"
57-
finally:
58-
await gateway_config.delete()
5943

60-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
61-
async def test_gateway_config_update(self, async_sdk_client: AsyncRunloopSDK) -> None:
62-
"""Test updating a gateway config."""
63-
gateway_config = await async_sdk_client.gateway_config.create(
64-
name=unique_name("sdk-async-gateway-config-update"),
65-
endpoint="https://api.example.com",
66-
auth_mechanism={"type": "bearer"},
67-
description="Original async description",
68-
)
69-
70-
try:
71-
# Update the gateway config
44+
# Update name and description
7245
updated_name = unique_name("sdk-async-gateway-config-updated")
7346
result = await gateway_config.update(
7447
name=updated_name,
7548
description="Updated async description",
7649
)
77-
78-
assert result is not None
7950
assert result.name == updated_name
8051
assert result.description == "Updated async description"
8152

82-
# Verify update persisted
83-
info = await gateway_config.get_info()
84-
assert info.name == updated_name
85-
assert info.description == "Updated async description"
86-
finally:
87-
await gateway_config.delete()
88-
89-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
90-
async def test_gateway_config_update_endpoint(self, async_sdk_client: AsyncRunloopSDK) -> None:
91-
"""Test updating gateway config endpoint."""
92-
gateway_config = await async_sdk_client.gateway_config.create(
93-
name=unique_name("sdk-async-gateway-config-endpoint"),
94-
endpoint="https://api.example.com",
95-
auth_mechanism={"type": "bearer"},
96-
)
97-
98-
try:
53+
# Update endpoint
9954
result = await gateway_config.update(
10055
endpoint="https://api.updated-example.com",
10156
)
102-
10357
assert result.endpoint == "https://api.updated-example.com"
10458

105-
# Verify update persisted
106-
info = await gateway_config.get_info()
107-
assert info.endpoint == "https://api.updated-example.com"
108-
finally:
109-
await gateway_config.delete()
110-
111-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
112-
async def test_gateway_config_update_auth_mechanism(self, async_sdk_client: AsyncRunloopSDK) -> None:
113-
"""Test updating gateway config auth mechanism."""
114-
gateway_config = await async_sdk_client.gateway_config.create(
115-
name=unique_name("sdk-async-gateway-config-auth"),
116-
endpoint="https://api.example.com",
117-
auth_mechanism={"type": "bearer"},
118-
)
119-
120-
try:
59+
# Update auth mechanism
12160
result = await gateway_config.update(
12261
auth_mechanism={"type": "header", "key": "x-api-key"},
12362
)
124-
12563
assert result.auth_mechanism.type == "header"
12664
assert result.auth_mechanism.key == "x-api-key"
12765

128-
# Verify update persisted
66+
# Verify all updates persisted
12967
info = await gateway_config.get_info()
68+
assert info.name == updated_name
69+
assert info.description == "Updated async description"
70+
assert info.endpoint == "https://api.updated-example.com"
13071
assert info.auth_mechanism.type == "header"
13172
assert info.auth_mechanism.key == "x-api-key"
13273
finally:
133-
await gateway_config.delete()
134-
135-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
136-
async def test_gateway_config_delete(self, async_sdk_client: AsyncRunloopSDK) -> None:
137-
"""Test deleting a gateway config."""
138-
gateway_config = await async_sdk_client.gateway_config.create(
139-
name=unique_name("sdk-async-gateway-config-delete"),
140-
endpoint="https://api.example.com",
141-
auth_mechanism={"type": "bearer"},
142-
)
143-
144-
result = await gateway_config.delete()
145-
146-
assert result is not None
147-
148-
149-
class TestAsyncGatewayConfigAuthMechanisms:
150-
"""Test different async gateway config auth mechanism types."""
151-
152-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
153-
@pytest.mark.parametrize(
154-
"auth_mechanism,expected_type,expected_key",
155-
[
156-
({"type": "bearer"}, "bearer", None),
157-
({"type": "header", "key": "x-api-key"}, "header", "x-api-key"),
158-
],
159-
)
160-
async def test_gateway_config_auth_mechanisms(
161-
self, async_sdk_client: AsyncRunloopSDK, auth_mechanism: AuthMechanism, expected_type: str, expected_key: str | None
162-
) -> None:
163-
"""Test creating gateway configs with different auth mechanisms."""
164-
gateway_config = await async_sdk_client.gateway_config.create(
165-
name=unique_name(f"sdk-async-gateway-{expected_type}"),
166-
endpoint=f"https://api.{expected_type}-test.com",
167-
auth_mechanism=auth_mechanism,
168-
)
169-
170-
try:
171-
info = await gateway_config.get_info()
172-
assert info.auth_mechanism is not None
173-
assert info.auth_mechanism.type == expected_type
174-
if expected_key is not None:
175-
assert info.auth_mechanism.key == expected_key
176-
finally:
177-
await gateway_config.delete()
74+
# Delete
75+
result = await gateway_config.delete()
76+
assert result is not None
17877

17978

18079
class TestAsyncGatewayConfigListing:
18180
"""Test async gateway config listing and retrieval operations."""
18281

18382
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
184-
async def test_list_gateway_configs(self, async_sdk_client: AsyncRunloopSDK) -> None:
185-
"""Test listing gateway configs."""
186-
configs = await async_sdk_client.gateway_config.list(limit=10)
187-
188-
assert isinstance(configs, list)
189-
# List might be empty or have system configs, that's okay
190-
assert len(configs) >= 0
191-
192-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
193-
async def test_get_gateway_config_by_id(self, async_sdk_client: AsyncRunloopSDK) -> None:
194-
"""Test retrieving gateway config by ID."""
195-
# Create a gateway config
196-
created = await async_sdk_client.gateway_config.create(
197-
name=unique_name("sdk-async-gateway-config-retrieve"),
198-
endpoint="https://api.retrieve-test.com",
199-
auth_mechanism={"type": "bearer"},
200-
)
201-
202-
try:
203-
# Retrieve it by ID
204-
retrieved = async_sdk_client.gateway_config.from_id(created.id)
205-
assert retrieved.id == created.id
206-
207-
# Verify it's the same gateway config
208-
info = await retrieved.get_info()
209-
assert info.id == created.id
210-
finally:
211-
await created.delete()
212-
213-
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
214-
async def test_list_gateway_configs_with_limit(self, async_sdk_client: AsyncRunloopSDK) -> None:
215-
"""Test listing gateway configs with a limit."""
83+
async def test_gateway_config_list_and_retrieve(self, async_sdk_client: AsyncRunloopSDK) -> None:
84+
"""Test listing gateway configs and retrieving by ID."""
21685
# Create two gateway configs
21786
config1 = await async_sdk_client.gateway_config.create(
21887
name=unique_name("sdk-async-gateway-config-list-1"),
@@ -222,18 +91,22 @@ async def test_list_gateway_configs_with_limit(self, async_sdk_client: AsyncRunl
22291
config2 = await async_sdk_client.gateway_config.create(
22392
name=unique_name("sdk-async-gateway-config-list-2"),
22493
endpoint="https://api.list-test-2.com",
225-
auth_mechanism={"type": "bearer"},
94+
auth_mechanism={"type": "header", "key": "x-api-key"},
22695
)
22796

22897
try:
229-
# List with limit
98+
# List gateway configs
23099
configs = await async_sdk_client.gateway_config.list(limit=100)
231-
232100
assert isinstance(configs, list)
233-
# Should find our gateway configs
234101
config_ids = [c.id for c in configs]
235102
assert config1.id in config_ids
236103
assert config2.id in config_ids
104+
105+
# Retrieve by ID
106+
retrieved = async_sdk_client.gateway_config.from_id(config1.id)
107+
assert retrieved.id == config1.id
108+
info = await retrieved.get_info()
109+
assert info.id == config1.id
237110
finally:
238111
await config1.delete()
239112
await config2.delete()

0 commit comments

Comments
 (0)