2022-12-27 14:14:25 -05:00
|
|
|
from quart import Quart
|
2023-07-16 23:25:37 -04:00
|
|
|
from quart_auth import authenticated_client
|
2022-12-27 14:14:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
async def test_post_todo(app: Quart) -> None:
|
|
|
|
test_client = app.test_client()
|
2023-07-16 23:25:37 -04:00
|
|
|
async with authenticated_client(test_client, auth_id=1): # type: ignore
|
2022-12-27 14:14:25 -05:00
|
|
|
response = await test_client.post(
|
|
|
|
"/todos/",
|
|
|
|
json={"complete": False, "due": None, "task": "Test task"},
|
|
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
|
|
assert (await response.get_json())["id"] > 0
|
|
|
|
|
|
|
|
|
|
|
|
async def test_get_todo(app: Quart) -> None:
|
|
|
|
test_client = app.test_client()
|
2023-07-16 23:25:37 -04:00
|
|
|
async with authenticated_client(test_client, auth_id=1): # type: ignore
|
2022-12-27 14:14:25 -05:00
|
|
|
response = await test_client.get("/todos/1/")
|
|
|
|
assert response.status_code == 200
|
|
|
|
assert (await response.get_json())["task"] == "Test Task"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_put_todo(app: Quart) -> None:
|
|
|
|
test_client = app.test_client()
|
2023-07-16 23:25:37 -04:00
|
|
|
async with authenticated_client(test_client, auth_id=1): # type: ignore
|
2022-12-27 14:14:25 -05:00
|
|
|
response = await test_client.post(
|
|
|
|
"/todos/",
|
|
|
|
json={"complete": False, "due": None, "task": "Test task"},
|
|
|
|
)
|
|
|
|
todo_id = (await response.get_json())["id"]
|
|
|
|
|
|
|
|
response = await test_client.put(
|
|
|
|
f"/todos/{todo_id}/",
|
|
|
|
json={"complete": False, "due": None, "task": "Updated"},
|
|
|
|
)
|
|
|
|
assert (await response.get_json())["task"] == "Updated"
|
|
|
|
|
|
|
|
response = await test_client.get(f"/todos/{todo_id}/")
|
|
|
|
assert (await response.get_json())["task"] == "Updated"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_delete_todo(app: Quart) -> None:
|
|
|
|
test_client = app.test_client()
|
2023-07-16 23:25:37 -04:00
|
|
|
async with authenticated_client(test_client, auth_id=1): # type: ignore
|
2022-12-27 14:14:25 -05:00
|
|
|
response = await test_client.post(
|
|
|
|
"/todos/",
|
|
|
|
json={"complete": False, "due": None, "task": "Test task"},
|
|
|
|
)
|
|
|
|
todo_id = (await response.get_json())["id"]
|
|
|
|
|
|
|
|
await test_client.delete(f"/todos/{todo_id}/")
|
|
|
|
|
|
|
|
response = await test_client.get(f"/todos/{todo_id}/")
|
|
|
|
assert response.status_code == 404
|