[tests] Port first test to async #23

pull/25/head
missytake 2023-04-01 14:18:24 +02:00
parent 64715f5aa5
commit 48e3b6f6bc
4 changed files with 16 additions and 3 deletions

View File

@ -66,6 +66,7 @@ commands =
deps =
pytest
pytest-asyncio
trio
commands =
pytest tests

View File

@ -8,6 +8,7 @@ from urllib.parse import urlparse
from fastapi import FastAPI, status
from fastapi.testclient import TestClient
from httpx import AsyncClient
from pytest import fixture
from kibicara import email
@ -24,6 +25,15 @@ def client():
return TestClient(app)
@fixture(scope="module")
def asyncclient():
Mapping.drop_all()
Mapping.create_all()
app = FastAPI()
app.include_router(router, prefix="/api")
return AsyncClient(app=app, base_url="http://test")
@fixture(scope="module")
def monkeymodule():
from _pytest.monkeypatch import MonkeyPatch

View File

@ -3,10 +3,12 @@
# SPDX-License-Identifier: 0BSD
from fastapi import status
import pytest
def test_hoods_unauthorized(client):
response = client.get("/api/admin/hoods/")
@pytest.mark.anyio
async def test_hoods_unauthorized(asyncclient):
response = await asyncclient.get("/api/admin/hoods/")
assert response.status_code == status.HTTP_401_UNAUTHORIZED

View File

@ -6,4 +6,4 @@ ln -sf ../../git-hooks/commit-msg .git/hooks/commit-msg
# create virtualenv
virtualenv -p $(which python3.10) backend/.venv
backend/.venv/bin/pip install tox black pytest pytest-aiohttp
backend/.venv/bin/pip install tox black pytest pytest-aiohttp trio