Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
QSTASH_TOKEN = os.environ["QSTASH_TOKEN"]
QSTASH_CURRENT_SIGNING_KEY = os.environ["QSTASH_CURRENT_SIGNING_KEY"]
QSTASH_NEXT_SIGNING_KEY = os.environ["QSTASH_NEXT_SIGNING_KEY"]
OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY") or ""


def assert_eventually(
Expand Down
9 changes: 6 additions & 3 deletions tests/asyncio/test_dlq.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ async def assertion() -> None:
@pytest.mark.asyncio
async def test_dlq_get_and_delete_async(async_client: AsyncQStash) -> None:
res = await async_client.message.publish_json(
url="http://httpstat.us/404",
method="GET",
url="https://mock.httpstatus.io/404",
retries=0,
)

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

Expand All @@ -69,7 +71,8 @@ async def test_dlq_get_and_delete_many_async(async_client: AsyncQStash) -> None:
@pytest.mark.asyncio
async def test_dlq_filter_async(async_client: AsyncQStash) -> None:
res = await async_client.message.publish_json(
url="http://httpstat.us/404",
method="GET",
url="https://mock.httpstatus.io/404",
retries=0,
)

Expand Down
49 changes: 29 additions & 20 deletions tests/asyncio/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ async def assertion() -> None:
async def test_publish_to_url_async(async_client: AsyncQStash) -> None:
res = await async_client.message.publish(
body="test-body",
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
headers={
"test-header": "test-value",
},
Expand All @@ -60,7 +61,8 @@ async def test_publish_to_url_async(async_client: AsyncQStash) -> None:
async def test_publish_to_url_json_async(async_client: AsyncQStash) -> None:
res = await async_client.message.publish_json(
body={"ex_key": "ex_value"},
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
headers={
"test-header": "test-value",
},
Expand All @@ -76,13 +78,15 @@ async def test_publish_to_url_json_async(async_client: AsyncQStash) -> None:
async def test_disallow_multiple_destinations_async(async_client: AsyncQStash) -> None:
with pytest.raises(QStashError):
await async_client.message.publish_json(
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
url_group="test-url-group",
)

with pytest.raises(QStashError):
await async_client.message.publish_json(
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
api={"name": "llm", "provider": openai(OPENAI_API_KEY)},
)

Expand All @@ -101,7 +105,8 @@ async def test_batch_async(async_client: AsyncQStash) -> None:
messages.append(
BatchRequest(
body=f"hi {i}",
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
retries=0,
headers={
f"test-header-{i}": f"test-value-{i}",
Expand All @@ -127,7 +132,8 @@ async def test_batch_json_async(async_client: AsyncQStash) -> None:
messages.append(
BatchJsonRequest(
body={"hi": i},
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
retries=0,
headers={
f"test-header-{i}": f"test-value-{i}",
Expand Down Expand Up @@ -157,7 +163,7 @@ async def test_publish_to_api_llm_async(async_client: AsyncQStash) -> None:
}
],
},
callback="https://httpstat.us/200",
callback="https://mock.httpstatus.io/200",
)

assert isinstance(res, PublishResponse)
Expand All @@ -181,7 +187,7 @@ async def test_batch_api_llm_async(async_client: AsyncQStash) -> None:
}
],
},
"callback": "https://httpstat.us/200",
"callback": "https://mock.httpstatus.io/200",
},
]
)
Expand All @@ -205,7 +211,8 @@ async def test_enqueue_async(
res = await async_client.message.enqueue(
queue=name,
body="test-body",
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
headers={
"test-header": "test-value",
},
Expand All @@ -227,7 +234,8 @@ async def test_enqueue_json_async(
res = await async_client.message.enqueue_json(
queue=name,
body={"test": "body"},
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
headers={
"test-header": "test-value",
},
Expand Down Expand Up @@ -258,7 +266,7 @@ async def test_enqueue_api_llm_async(
],
},
api={"name": "llm", "provider": openai(OPENAI_API_KEY)},
callback="https://httpstat.us/200",
callback="https://mock.httpstatus.io/200",
)

assert isinstance(res, EnqueueResponse)
Expand All @@ -274,8 +282,8 @@ async def test_publish_to_url_group_async(async_client: AsyncQStash) -> None:
await async_client.url_group.upsert_endpoints(
url_group=name,
endpoints=[
{"url": "https://httpstat.us/200"},
{"url": "https://httpstat.us/201"},
{"url": "https://mock.httpstatus.io/200"},
{"url": "https://mock.httpstatus.io/201"},
],
)

Expand All @@ -295,7 +303,8 @@ async def test_publish_to_url_group_async(async_client: AsyncQStash) -> None:
async def test_timeout_async(async_client: AsyncQStash) -> None:
res = await async_client.message.publish_json(
body={"ex_key": "ex_value"},
url="https://httpstat.us/200",
method="GET",
url="https://mock.httpstatus.io/200",
timeout=90,
)

Expand Down Expand Up @@ -364,7 +373,7 @@ async def test_publish_to_api_llm_custom_provider_async(
}
],
},
callback="https://httpstat.us/200",
callback="https://mock.httpstatus.io/200",
)

assert isinstance(res, PublishResponse)
Expand Down Expand Up @@ -393,7 +402,7 @@ async def test_enqueue_api_llm_custom_provider_async(
],
},
api={"name": "llm", "provider": openai(OPENAI_API_KEY)},
callback="https://httpstat.us/200",
callback="https://mock.httpstatus.io/200",
)

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

Expand All @@ -430,17 +439,17 @@ async def test_batch_with_flow_control_async(
[
BatchJsonRequest(
body={"ex_key": "ex_value"},
url="https://httpstat.us/200?sleep=30000",
url="https://mock.httpstatus.io/200?sleep=30000",
flow_control=FlowControl(key="flow-key-1", rate=1),
),
BatchJsonRequest(
body={"ex_key": "ex_value"},
url="https://httpstat.us/200?sleep=30000",
url="https://mock.httpstatus.io/200?sleep=30000",
flow_control=FlowControl(key="flow-key-2", rate=23, period="1h30m3s"),
),
BatchJsonRequest(
body={"ex_key": "ex_value"},
url="https://httpstat.us/200?sleep=30000",
url="https://mock.httpstatus.io/200?sleep=30000",
flow_control=FlowControl(key="flow-key-3", parallelism=5),
),
]
Expand Down
8 changes: 4 additions & 4 deletions tests/asyncio/test_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async def test_schedule_lifecycle_async(
) -> None:
schedule_id = await async_client.schedule.create_json(
cron="1 1 1 1 1",
destination="https://httpstat.us/200",
destination="https://mock.httpstatus.io/200",
body={"ex_key": "ex_value"},
)

Expand Down Expand Up @@ -41,7 +41,7 @@ async def test_schedule_pause_resume_async(
) -> None:
schedule_id = await async_client.schedule.create_json(
cron="1 1 1 1 1",
destination="https://httpstat.us/200",
destination="https://mock.httpstatus.io/200",
body={"ex_key": "ex_value"},
)

Expand Down Expand Up @@ -72,7 +72,7 @@ async def test_schedule_with_flow_control_async(
) -> None:
schedule_id = await async_client.schedule.create_json(
cron="1 1 1 1 1",
destination="https://httpstat.us/200",
destination="https://mock.httpstatus.io/200",
body={"ex_key": "ex_value"},
flow_control=FlowControl(key="flow-key", parallelism=2),
)
Expand All @@ -95,7 +95,7 @@ async def test_schedule_enqueue_async(
) -> None:
schedule_id = await async_client.schedule.create_json(
cron="1 1 1 1 1",
destination="https://httpstat.us/200",
destination="https://mock.httpstatus.io/200",
body={"key": "value"},
queue="schedule-queue",
)
Expand Down
20 changes: 13 additions & 7 deletions tests/asyncio/test_url_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ async def test_url_group_async(async_client: AsyncQStash) -> None:
await async_client.url_group.upsert_endpoints(
url_group=name,
endpoints=[
{"url": "https://httpstat.us/200"},
{"url": "https://httpstat.us/201"},
{"url": "https://mock.httpstatus.io/200"},
{"url": "https://mock.httpstatus.io/201"},
],
)

url_group = await async_client.url_group.get(name)
assert url_group.name == name
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/200")
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/201")
assert any(
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/200"
)
assert any(
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/201"
)

url_groups = await async_client.url_group.list()
assert any(True for ug in url_groups if ug.name == name)
Expand All @@ -28,14 +32,16 @@ async def test_url_group_async(async_client: AsyncQStash) -> None:
url_group=name,
endpoints=[
{
"url": "https://httpstat.us/201",
"url": "https://mock.httpstatus.io/201",
}
],
)

url_group = await async_client.url_group.get(name)
assert url_group.name == name
assert any(True for e in url_group.endpoints if e.url == "https://httpstat.us/200")
assert any(
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/200"
)
assert not any(
True for e in url_group.endpoints if e.url == "https://httpstat.us/201"
True for e in url_group.endpoints if e.url == "https://mock.httpstatus.io/201"
)
9 changes: 6 additions & 3 deletions tests/test_dlq.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def assertion() -> None:

def test_dlq_get_and_delete(client: QStash) -> None:
res = client.message.publish_json(
url="http://httpstat.us/404",
method="GET",
url="https://mock.httpstatus.io/404",
retries=0,
retry_delay="7000 * retried",
)
Expand All @@ -51,7 +52,8 @@ def test_dlq_get_and_delete_many(client: QStash) -> None:
msg_ids = []
for _ in range(5):
res = client.message.publish_json(
url="http://httpstat.us/404",
method="GET",
url="https://mock.httpstatus.io/404",
retries=0,
retry_delay="7000 * retried",
)
Expand All @@ -64,7 +66,8 @@ def test_dlq_get_and_delete_many(client: QStash) -> None:

def test_dlq_filter(client: QStash) -> None:
res = client.message.publish_json(
url="http://httpstat.us/404",
method="GET",
url="https://mock.httpstatus.io/404",
retries=0,
retry_delay="7000 * retried",
)
Expand Down
Loading
Loading