Skip to content

Commit 94617a8

Browse files
committed
fix: tests failing because of unavailable endpoint
1 parent 1cc895e commit 94617a8

File tree

8 files changed

+83
-56
lines changed

8 files changed

+83
-56
lines changed

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
QSTASH_TOKEN = os.environ["QSTASH_TOKEN"]
1111
QSTASH_CURRENT_SIGNING_KEY = os.environ["QSTASH_CURRENT_SIGNING_KEY"]
1212
QSTASH_NEXT_SIGNING_KEY = os.environ["QSTASH_NEXT_SIGNING_KEY"]
13-
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
13+
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY") or ""
1414

1515

1616
def assert_eventually(

tests/asyncio/test_message.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ async def assertion() -> None:
4444
async def test_publish_to_url_async(async_client: AsyncQStash) -> None:
4545
res = await async_client.message.publish(
4646
body="test-body",
47-
url="https://httpstat.us/200",
47+
method="GET",
48+
url="https://mock.httpstatus.io/200",
4849
headers={
4950
"test-header": "test-value",
5051
},
@@ -60,7 +61,8 @@ async def test_publish_to_url_async(async_client: AsyncQStash) -> None:
6061
async def test_publish_to_url_json_async(async_client: AsyncQStash) -> None:
6162
res = await async_client.message.publish_json(
6263
body={"ex_key": "ex_value"},
63-
url="https://httpstat.us/200",
64+
method="GET",
65+
url="https://mock.httpstatus.io/200",
6466
headers={
6567
"test-header": "test-value",
6668
},
@@ -76,13 +78,15 @@ async def test_publish_to_url_json_async(async_client: AsyncQStash) -> None:
7678
async def test_disallow_multiple_destinations_async(async_client: AsyncQStash) -> None:
7779
with pytest.raises(QStashError):
7880
await async_client.message.publish_json(
79-
url="https://httpstat.us/200",
81+
method="GET",
82+
url="https://mock.httpstatus.io/200",
8083
url_group="test-url-group",
8184
)
8285

8386
with pytest.raises(QStashError):
8487
await async_client.message.publish_json(
85-
url="https://httpstat.us/200",
88+
method="GET",
89+
url="https://mock.httpstatus.io/200",
8690
api={"name": "llm", "provider": openai(OPENAI_API_KEY)},
8791
)
8892

@@ -101,7 +105,8 @@ async def test_batch_async(async_client: AsyncQStash) -> None:
101105
messages.append(
102106
BatchRequest(
103107
body=f"hi {i}",
104-
url="https://httpstat.us/200",
108+
method="GET",
109+
url="https://mock.httpstatus.io/200",
105110
retries=0,
106111
headers={
107112
f"test-header-{i}": f"test-value-{i}",
@@ -127,7 +132,8 @@ async def test_batch_json_async(async_client: AsyncQStash) -> None:
127132
messages.append(
128133
BatchJsonRequest(
129134
body={"hi": i},
130-
url="https://httpstat.us/200",
135+
method="GET",
136+
url="https://mock.httpstatus.io/200",
131137
retries=0,
132138
headers={
133139
f"test-header-{i}": f"test-value-{i}",
@@ -157,7 +163,7 @@ async def test_publish_to_api_llm_async(async_client: AsyncQStash) -> None:
157163
}
158164
],
159165
},
160-
callback="https://httpstat.us/200",
166+
callback="https://mock.httpstatus.io/200",
161167
)
162168

163169
assert isinstance(res, PublishResponse)
@@ -181,7 +187,7 @@ async def test_batch_api_llm_async(async_client: AsyncQStash) -> None:
181187
}
182188
],
183189
},
184-
"callback": "https://httpstat.us/200",
190+
"callback": "https://mock.httpstatus.io/200",
185191
},
186192
]
187193
)
@@ -205,7 +211,8 @@ async def test_enqueue_async(
205211
res = await async_client.message.enqueue(
206212
queue=name,
207213
body="test-body",
208-
url="https://httpstat.us/200",
214+
method="GET",
215+
url="https://mock.httpstatus.io/200",
209216
headers={
210217
"test-header": "test-value",
211218
},
@@ -227,7 +234,8 @@ async def test_enqueue_json_async(
227234
res = await async_client.message.enqueue_json(
228235
queue=name,
229236
body={"test": "body"},
230-
url="https://httpstat.us/200",
237+
method="GET",
238+
url="https://mock.httpstatus.io/200",
231239
headers={
232240
"test-header": "test-value",
233241
},
@@ -258,7 +266,7 @@ async def test_enqueue_api_llm_async(
258266
],
259267
},
260268
api={"name": "llm", "provider": openai(OPENAI_API_KEY)},
261-
callback="https://httpstat.us/200",
269+
callback="https://mock.httpstatus.io/200",
262270
)
263271

264272
assert isinstance(res, EnqueueResponse)
@@ -274,7 +282,7 @@ async def test_publish_to_url_group_async(async_client: AsyncQStash) -> None:
274282
await async_client.url_group.upsert_endpoints(
275283
url_group=name,
276284
endpoints=[
277-
{"url": "https://httpstat.us/200"},
285+
{"url": "https://mock.httpstatus.io/200"},
278286
{"url": "https://httpstat.us/201"},
279287
],
280288
)
@@ -295,7 +303,8 @@ async def test_publish_to_url_group_async(async_client: AsyncQStash) -> None:
295303
async def test_timeout_async(async_client: AsyncQStash) -> None:
296304
res = await async_client.message.publish_json(
297305
body={"ex_key": "ex_value"},
298-
url="https://httpstat.us/200",
306+
method="GET",
307+
url="https://mock.httpstatus.io/200",
299308
timeout=90,
300309
)
301310

@@ -364,7 +373,7 @@ async def test_publish_to_api_llm_custom_provider_async(
364373
}
365374
],
366375
},
367-
callback="https://httpstat.us/200",
376+
callback="https://mock.httpstatus.io/200",
368377
)
369378

370379
assert isinstance(res, PublishResponse)
@@ -393,7 +402,7 @@ async def test_enqueue_api_llm_custom_provider_async(
393402
],
394403
},
395404
api={"name": "llm", "provider": openai(OPENAI_API_KEY)},
396-
callback="https://httpstat.us/200",
405+
callback="https://mock.httpstatus.io/200",
397406
)
398407

399408
assert isinstance(res, EnqueueResponse)
@@ -407,7 +416,7 @@ async def test_publish_with_flow_control_async(
407416
) -> None:
408417
result = await async_client.message.publish_json(
409418
body={"ex_key": "ex_value"},
410-
url="https://httpstat.us/200?sleep=30000",
419+
url="https://mock.httpstatus.io/200?sleep=30000",
411420
flow_control=FlowControl(key="flow-key", parallelism=3, rate=4, period=2),
412421
)
413422

@@ -430,17 +439,17 @@ async def test_batch_with_flow_control_async(
430439
[
431440
BatchJsonRequest(
432441
body={"ex_key": "ex_value"},
433-
url="https://httpstat.us/200?sleep=30000",
442+
url="https://mock.httpstatus.io/200?sleep=30000",
434443
flow_control=FlowControl(key="flow-key-1", rate=1),
435444
),
436445
BatchJsonRequest(
437446
body={"ex_key": "ex_value"},
438-
url="https://httpstat.us/200?sleep=30000",
447+
url="https://mock.httpstatus.io/200?sleep=30000",
439448
flow_control=FlowControl(key="flow-key-2", rate=23, period="1h30m3s"),
440449
),
441450
BatchJsonRequest(
442451
body={"ex_key": "ex_value"},
443-
url="https://httpstat.us/200?sleep=30000",
452+
url="https://mock.httpstatus.io/200?sleep=30000",
444453
flow_control=FlowControl(key="flow-key-3", parallelism=5),
445454
),
446455
]

tests/asyncio/test_schedules.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def test_schedule_lifecycle_async(
1313
) -> None:
1414
schedule_id = await async_client.schedule.create_json(
1515
cron="1 1 1 1 1",
16-
destination="https://httpstat.us/200",
16+
destination="https://mock.httpstatus.io/200",
1717
body={"ex_key": "ex_value"},
1818
)
1919

@@ -41,7 +41,7 @@ async def test_schedule_pause_resume_async(
4141
) -> None:
4242
schedule_id = await async_client.schedule.create_json(
4343
cron="1 1 1 1 1",
44-
destination="https://httpstat.us/200",
44+
destination="https://mock.httpstatus.io/200",
4545
body={"ex_key": "ex_value"},
4646
)
4747

@@ -72,7 +72,7 @@ async def test_schedule_with_flow_control_async(
7272
) -> None:
7373
schedule_id = await async_client.schedule.create_json(
7474
cron="1 1 1 1 1",
75-
destination="https://httpstat.us/200",
75+
destination="https://mock.httpstatus.io/200",
7676
body={"ex_key": "ex_value"},
7777
flow_control=FlowControl(key="flow-key", parallelism=2),
7878
)
@@ -95,7 +95,7 @@ async def test_schedule_enqueue_async(
9595
) -> None:
9696
schedule_id = await async_client.schedule.create_json(
9797
cron="1 1 1 1 1",
98-
destination="https://httpstat.us/200",
98+
destination="https://mock.httpstatus.io/200",
9999
body={"key": "value"},
100100
queue="schedule-queue",
101101
)

tests/asyncio/test_url_group.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ async def test_url_group_async(async_client: AsyncQStash) -> None:
1111
await async_client.url_group.upsert_endpoints(
1212
url_group=name,
1313
endpoints=[
14-
{"url": "https://httpstat.us/200"},
14+
{"url": "https://mock.httpstatus.io/200"},
1515
{"url": "https://httpstat.us/201"},
1616
],
1717
)
1818

1919
url_group = await async_client.url_group.get(name)
2020
assert url_group.name == name
21-
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/200")
21+
assert any(
22+
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/200"
23+
)
2224
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/201")
2325

2426
url_groups = await async_client.url_group.list()
@@ -35,7 +37,9 @@ async def test_url_group_async(async_client: AsyncQStash) -> None:
3537

3638
url_group = await async_client.url_group.get(name)
3739
assert url_group.name == name
38-
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/200")
40+
assert any(
41+
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/200"
42+
)
3943
assert not any(
4044
True for e in url_group.endpoints if e.url == "https://httpstat.us/201"
4145
)

0 commit comments

Comments
 (0)