Skip to content

Commit

Permalink
Add asyncio schedules test
Browse files Browse the repository at this point in the history
  • Loading branch information
MeshanKhosla committed Jan 11, 2024
1 parent 80b7d87 commit 88eba62
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
49 changes: 49 additions & 0 deletions tests/asyncio/test_schedules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
import asyncio
from upstash_qstash.asyncio import Client
from qstash_token import QSTASH_TOKEN


@pytest.fixture
def client():
return Client(QSTASH_TOKEN)


@pytest.mark.asyncio
async def test_schedule_lifecycle(client):
sched = client.schedules()
create_res = await sched.create(
{
"cron": "* * * * *",
"destination": "https://example.com",
"body": {"ex_key": "ex_value"},
"headers": {
"content-type": "application/json",
},
}
)

sched_id = create_res["scheduleId"]
assert sched_id is not None

print("Waiting 1 seconds for schedule to be delivered")
await asyncio.sleep(1)

print("Checking if schedule is delivered")
get_res = await sched.get(sched_id)
assert get_res["scheduleId"] == sched_id
assert get_res["cron"] == "* * * * *"

print("Checking if schedule is in list")
list_res = await sched.list()
assert any(s["scheduleId"] == sched_id for s in list_res)

print("Deleting schedule")
await sched.delete(sched_id)

print("Waiting 1 second for schedule to be deleted")
await asyncio.sleep(1)

print("Checking if schedule is deleted")
list_res = await sched.list()
assert not any(s["scheduleId"] == sched_id for s in list_res)
1 change: 0 additions & 1 deletion tests/test_schedules.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pytest
import dotenv
import time
from upstash_qstash import Client
from qstash_token import QSTASH_TOKEN
Expand Down

0 comments on commit 88eba62

Please sign in to comment.