Skip to content

Commit e4979d2

Browse files
committed
cp dines
1 parent c0d0130 commit e4979d2

2 files changed

Lines changed: 522 additions & 0 deletions

File tree

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
"""Asynchronous SDK smoke tests for Gateway Config operations."""
2+
3+
from __future__ import annotations
4+
5+
import pytest
6+
7+
from runloop_api_client.sdk import AsyncRunloopSDK
8+
from tests.smoketests.utils import unique_name
9+
10+
pytestmark = [pytest.mark.smoketest, pytest.mark.asyncio]
11+
12+
THIRTY_SECOND_TIMEOUT = 30
13+
14+
15+
class TestAsyncGatewayConfigLifecycle:
16+
"""Test basic async gateway config lifecycle operations."""
17+
18+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
19+
async def test_gateway_config_create(self, async_sdk_client: AsyncRunloopSDK) -> None:
20+
"""Test creating a gateway config."""
21+
name = unique_name("sdk-async-gateway-config")
22+
gateway_config = await async_sdk_client.gateway_config.create(
23+
name=name,
24+
endpoint="https://api.example.com",
25+
auth_mechanism={"type": "bearer"},
26+
description="SDK async smoke test gateway config",
27+
)
28+
29+
try:
30+
assert gateway_config is not None
31+
assert gateway_config.id is not None
32+
assert len(gateway_config.id) > 0
33+
finally:
34+
await gateway_config.delete()
35+
36+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
37+
async def test_gateway_config_get_info(self, async_sdk_client: AsyncRunloopSDK) -> None:
38+
"""Test retrieving gateway config information."""
39+
name = unique_name("sdk-async-gateway-config-info")
40+
gateway_config = await async_sdk_client.gateway_config.create(
41+
name=name,
42+
endpoint="https://api.example.com",
43+
auth_mechanism={"type": "bearer"},
44+
description="Async test gateway config for get_info",
45+
)
46+
47+
try:
48+
info = await gateway_config.get_info()
49+
50+
assert info.id == gateway_config.id
51+
assert info.name == name
52+
assert info.endpoint == "https://api.example.com"
53+
assert info.description == "Async test gateway config for get_info"
54+
assert info.auth_mechanism is not None
55+
assert info.auth_mechanism.type == "bearer"
56+
finally:
57+
await gateway_config.delete()
58+
59+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
60+
async def test_gateway_config_update(self, async_sdk_client: AsyncRunloopSDK) -> None:
61+
"""Test updating a gateway config."""
62+
gateway_config = await async_sdk_client.gateway_config.create(
63+
name=unique_name("sdk-async-gateway-config-update"),
64+
endpoint="https://api.example.com",
65+
auth_mechanism={"type": "bearer"},
66+
description="Original async description",
67+
)
68+
69+
try:
70+
# Update the gateway config
71+
updated_name = unique_name("sdk-async-gateway-config-updated")
72+
result = await gateway_config.update(
73+
name=updated_name,
74+
description="Updated async description",
75+
)
76+
77+
assert result is not None
78+
assert result.name == updated_name
79+
assert result.description == "Updated async description"
80+
81+
# Verify update persisted
82+
info = await gateway_config.get_info()
83+
assert info.name == updated_name
84+
assert info.description == "Updated async description"
85+
finally:
86+
await gateway_config.delete()
87+
88+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
89+
async def test_gateway_config_update_endpoint(self, async_sdk_client: AsyncRunloopSDK) -> None:
90+
"""Test updating gateway config endpoint."""
91+
gateway_config = await async_sdk_client.gateway_config.create(
92+
name=unique_name("sdk-async-gateway-config-endpoint"),
93+
endpoint="https://api.example.com",
94+
auth_mechanism={"type": "bearer"},
95+
)
96+
97+
try:
98+
result = await gateway_config.update(
99+
endpoint="https://api.updated-example.com",
100+
)
101+
102+
assert result.endpoint == "https://api.updated-example.com"
103+
104+
# Verify update persisted
105+
info = await gateway_config.get_info()
106+
assert info.endpoint == "https://api.updated-example.com"
107+
finally:
108+
await gateway_config.delete()
109+
110+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
111+
async def test_gateway_config_update_auth_mechanism(self, async_sdk_client: AsyncRunloopSDK) -> None:
112+
"""Test updating gateway config auth mechanism."""
113+
gateway_config = await async_sdk_client.gateway_config.create(
114+
name=unique_name("sdk-async-gateway-config-auth"),
115+
endpoint="https://api.example.com",
116+
auth_mechanism={"type": "bearer"},
117+
)
118+
119+
try:
120+
result = await gateway_config.update(
121+
auth_mechanism={"type": "header", "key": "x-api-key"},
122+
)
123+
124+
assert result.auth_mechanism.type == "header"
125+
assert result.auth_mechanism.key == "x-api-key"
126+
127+
# Verify update persisted
128+
info = await gateway_config.get_info()
129+
assert info.auth_mechanism.type == "header"
130+
assert info.auth_mechanism.key == "x-api-key"
131+
finally:
132+
await gateway_config.delete()
133+
134+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
135+
async def test_gateway_config_delete(self, async_sdk_client: AsyncRunloopSDK) -> None:
136+
"""Test deleting a gateway config."""
137+
gateway_config = await async_sdk_client.gateway_config.create(
138+
name=unique_name("sdk-async-gateway-config-delete"),
139+
endpoint="https://api.example.com",
140+
auth_mechanism={"type": "bearer"},
141+
)
142+
143+
result = await gateway_config.delete()
144+
145+
assert result is not None
146+
147+
148+
class TestAsyncGatewayConfigAuthMechanisms:
149+
"""Test different async gateway config auth mechanism types."""
150+
151+
@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."""
154+
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"},
158+
)
159+
160+
try:
161+
info = await gateway_config.get_info()
162+
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"
198+
finally:
199+
await gateway_config.delete()
200+
201+
202+
class TestAsyncGatewayConfigListing:
203+
"""Test async gateway config listing and retrieval operations."""
204+
205+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
206+
async def test_list_gateway_configs(self, async_sdk_client: AsyncRunloopSDK) -> None:
207+
"""Test listing gateway configs."""
208+
configs = await async_sdk_client.gateway_config.list(limit=10)
209+
210+
assert isinstance(configs, list)
211+
# List might be empty or have system configs, that's okay
212+
assert len(configs) >= 0
213+
214+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
215+
async def test_get_gateway_config_by_id(self, async_sdk_client: AsyncRunloopSDK) -> None:
216+
"""Test retrieving gateway config by ID."""
217+
# Create a gateway config
218+
created = await async_sdk_client.gateway_config.create(
219+
name=unique_name("sdk-async-gateway-config-retrieve"),
220+
endpoint="https://api.retrieve-test.com",
221+
auth_mechanism={"type": "bearer"},
222+
)
223+
224+
try:
225+
# Retrieve it by ID
226+
retrieved = async_sdk_client.gateway_config.from_id(created.id)
227+
assert retrieved.id == created.id
228+
229+
# Verify it's the same gateway config
230+
info = await retrieved.get_info()
231+
assert info.id == created.id
232+
finally:
233+
await created.delete()
234+
235+
@pytest.mark.timeout(THIRTY_SECOND_TIMEOUT)
236+
async def test_list_gateway_configs_with_limit(self, async_sdk_client: AsyncRunloopSDK) -> None:
237+
"""Test listing gateway configs with a limit."""
238+
# Create two gateway configs
239+
config1 = await async_sdk_client.gateway_config.create(
240+
name=unique_name("sdk-async-gateway-config-list-1"),
241+
endpoint="https://api.list-test-1.com",
242+
auth_mechanism={"type": "bearer"},
243+
)
244+
config2 = await async_sdk_client.gateway_config.create(
245+
name=unique_name("sdk-async-gateway-config-list-2"),
246+
endpoint="https://api.list-test-2.com",
247+
auth_mechanism={"type": "bearer"},
248+
)
249+
250+
try:
251+
# List with limit
252+
configs = await async_sdk_client.gateway_config.list(limit=100)
253+
254+
assert isinstance(configs, list)
255+
# Should find our gateway configs
256+
config_ids = [c.id for c in configs]
257+
assert config1.id in config_ids
258+
assert config2.id in config_ids
259+
finally:
260+
await config1.delete()
261+
await config2.delete()

0 commit comments

Comments
 (0)