[tests] Port first test to async #23
This commit is contained in:
parent
64715f5aa5
commit
48e3b6f6bc
|
@ -66,6 +66,7 @@ commands =
|
||||||
deps =
|
deps =
|
||||||
pytest
|
pytest
|
||||||
pytest-asyncio
|
pytest-asyncio
|
||||||
|
trio
|
||||||
commands =
|
commands =
|
||||||
pytest tests
|
pytest tests
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ from urllib.parse import urlparse
|
||||||
|
|
||||||
from fastapi import FastAPI, status
|
from fastapi import FastAPI, status
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
from httpx import AsyncClient
|
||||||
from pytest import fixture
|
from pytest import fixture
|
||||||
|
|
||||||
from kibicara import email
|
from kibicara import email
|
||||||
|
@ -24,6 +25,15 @@ def client():
|
||||||
return TestClient(app)
|
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")
|
@fixture(scope="module")
|
||||||
def monkeymodule():
|
def monkeymodule():
|
||||||
from _pytest.monkeypatch import MonkeyPatch
|
from _pytest.monkeypatch import MonkeyPatch
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
# SPDX-License-Identifier: 0BSD
|
# SPDX-License-Identifier: 0BSD
|
||||||
|
|
||||||
from fastapi import status
|
from fastapi import status
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
def test_hoods_unauthorized(client):
|
@pytest.mark.anyio
|
||||||
response = client.get("/api/admin/hoods/")
|
async def test_hoods_unauthorized(asyncclient):
|
||||||
|
response = await asyncclient.get("/api/admin/hoods/")
|
||||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
|
|
||||||
|
|
||||||
|
|
2
setup.sh
2
setup.sh
|
@ -6,4 +6,4 @@ ln -sf ../../git-hooks/commit-msg .git/hooks/commit-msg
|
||||||
|
|
||||||
# create virtualenv
|
# create virtualenv
|
||||||
virtualenv -p $(which python3.10) backend/.venv
|
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
|
||||||
|
|
Loading…
Reference in a new issue