Bump supported fastapi versions (#1110)

* Bump supported fastapi version to <=0.97, change all fastapi tests from starlette client to httpx.AsyncClient

* Add lifecycle manager to fastapi tests

* Fix coverage

* Add python 3.11 to test suite, bump version
This commit is contained in:
collerek
2023-06-18 18:52:06 +02:00
committed by GitHub
parent e72e40dd6c
commit b1ab0de4d4
27 changed files with 733 additions and 587 deletions

View File

@ -4,8 +4,9 @@ import databases
import pytest
import pytest_asyncio
import sqlalchemy
from asgi_lifespan import LifespanManager
from fastapi import FastAPI
from starlette.testclient import TestClient
from httpx import AsyncClient
import ormar
from tests.settings import DATABASE_URL
@ -94,10 +95,11 @@ async def get_book_with_author_by_id(book_id: int):
return book
def test_related_with_defaults(sample_data):
client = TestClient(app)
with client as client:
response = client.get("/books/1")
@pytest.mark.asyncio
async def test_related_with_defaults(sample_data):
client = AsyncClient(app=app, base_url="http://testserver")
async with client as client, LifespanManager(app):
response = await client.get("/books/1")
assert response.json() == {
"author": {"id": 1},
"id": 1,
@ -105,7 +107,7 @@ def test_related_with_defaults(sample_data):
"year": 2021,
}
response = client.get("/books_with_author/1")
response = await client.get("/books_with_author/1")
assert response.json() == {
"author": {
"books": [