Skip to content

Commit c606152

Browse files
authored
fix: tests failing because of unavailable endpoint (#45)
* fix: tests failing because of unavailable endpoint * fix: tests * fix: fmt
1 parent 1cc895e commit c606152

File tree

10 files changed

+111
-73
lines changed

10 files changed

+111
-73
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_dlq.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ async def assertion() -> None:
4242
@pytest.mark.asyncio
4343
async def test_dlq_get_and_delete_async(async_client: AsyncQStash) -> None:
4444
res = await async_client.message.publish_json(
45-
url="http://httpstat.us/404",
45+
method="GET",
46+
url="https://mock.httpstatus.io/404",
4647
retries=0,
4748
)
4849

@@ -56,7 +57,8 @@ async def test_dlq_get_and_delete_many_async(async_client: AsyncQStash) -> None:
5657
msg_ids = []
5758
for _ in range(5):
5859
res = await async_client.message.publish_json(
59-
url="http://httpstat.us/404",
60+
method="GET",
61+
url="https://mock.httpstatus.io/404",
6062
retries=0,
6163
)
6264

@@ -69,7 +71,8 @@ async def test_dlq_get_and_delete_many_async(async_client: AsyncQStash) -> None:
6971
@pytest.mark.asyncio
7072
async def test_dlq_filter_async(async_client: AsyncQStash) -> None:
7173
res = await async_client.message.publish_json(
72-
url="http://httpstat.us/404",
74+
method="GET",
75+
url="https://mock.httpstatus.io/404",
7376
retries=0,
7477
)
7578

tests/asyncio/test_message.py

Lines changed: 29 additions & 20 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,8 +282,8 @@ 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"},
278-
{"url": "https://httpstat.us/201"},
285+
{"url": "https://mock.httpstatus.io/200"},
286+
{"url": "https://mock.httpstatus.io/201"},
279287
],
280288
)
281289

@@ -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: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ 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"},
15-
{"url": "https://httpstat.us/201"},
14+
{"url": "https://mock.httpstatus.io/200"},
15+
{"url": "https://mock.httpstatus.io/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")
22-
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/201")
21+
assert any(
22+
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/200"
23+
)
24+
assert any(
25+
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/201"
26+
)
2327

2428
url_groups = await async_client.url_group.list()
2529
assert any(True for ug in url_groups if ug.name == name)
@@ -28,14 +32,16 @@ async def test_url_group_async(async_client: AsyncQStash) -> None:
2832
url_group=name,
2933
endpoints=[
3034
{
31-
"url": "https://httpstat.us/201",
35+
"url": "https://mock.httpstatus.io/201",
3236
}
3337
],
3438
)
3539

3640
url_group = await async_client.url_group.get(name)
3741
assert url_group.name == name
38-
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/200")
42+
assert any(
43+
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/200"
44+
)
3945
assert not any(
40-
True for e in url_group.endpoints if e.url == "https://httpstat.us/201"
46+
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/201"
4147
)

tests/test_dlq.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def assertion() -> None:
3737

3838
def test_dlq_get_and_delete(client: QStash) -> None:
3939
res = client.message.publish_json(
40-
url="http://httpstat.us/404",
40+
method="GET",
41+
url="https://mock.httpstatus.io/404",
4142
retries=0,
4243
retry_delay="7000 * retried",
4344
)
@@ -51,7 +52,8 @@ def test_dlq_get_and_delete_many(client: QStash) -> None:
5152
msg_ids = []
5253
for _ in range(5):
5354
res = client.message.publish_json(
54-
url="http://httpstat.us/404",
55+
method="GET",
56+
url="https://mock.httpstatus.io/404",
5557
retries=0,
5658
retry_delay="7000 * retried",
5759
)
@@ -64,7 +66,8 @@ def test_dlq_get_and_delete_many(client: QStash) -> None:
6466

6567
def test_dlq_filter(client: QStash) -> None:
6668
res = client.message.publish_json(
67-
url="http://httpstat.us/404",
69+
method="GET",
70+
url="https://mock.httpstatus.io/404",
6871
retries=0,
6972
retry_delay="7000 * retried",
7073
)

0 commit comments

Comments
 (0)