minhtrannhat 979e504c0d
Fix(backend): Updated authenticated Ctxmanager
- After Quart update, we can't test if an user is authenticated anymore
  with only `quart` but we also have to rely on
  `quart_auth.authenticated_client`. All tests passed after changes
  were made.
2023-07-16 23:25:37 -04:00

56 lines
2.0 KiB
Python

from quart import Quart
from quart_auth import authenticated_client
async def test_post_todo(app: Quart) -> None:
test_client = app.test_client()
async with authenticated_client(test_client, auth_id=1): # type: ignore
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()
async with authenticated_client(test_client, auth_id=1): # type: ignore
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()
async with authenticated_client(test_client, auth_id=1): # type: ignore
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()
async with authenticated_client(test_client, auth_id=1): # type: ignore
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