mirror of
https://github.com/fastapi/sqlmodel.git
synced 2025-08-15 10:11:34 +08:00
📝 Add source examples for Python 3.9 and 3.10 (#715)
* 📝 Add source examples for Python 3.9 and 3.10 * ✅ Add tests for new source examples for Python 3.9 and 3.10, still needs pytest markers * ✅ Add tests for fastapi examples * ✅ Update tests for FastAPI app testing, for Python 3.9 and 3.10, fixing multi-app testing conflicts * ✅ Require Python 3.9 and 3.10 for tests * ✅ Update tests with missing markers
This commit is contained in:

committed by
GitHub

parent
cce30d7546
commit
d8effcbc5c
@ -0,0 +1,38 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy import Inspector, inspect
|
||||
from sqlmodel import Session, create_engine
|
||||
|
||||
from . import main as app_mod
|
||||
from .test_main import client_fixture, session_fixture
|
||||
|
||||
assert client_fixture, "This keeps the client fixture used below"
|
||||
assert session_fixture, "This keeps the session fixture used by client_fixture"
|
||||
|
||||
|
||||
def test_startup():
|
||||
app_mod.engine = create_engine("sqlite://")
|
||||
app_mod.on_startup()
|
||||
insp: Inspector = inspect(app_mod.engine)
|
||||
assert insp.has_table(str(app_mod.Hero.__tablename__))
|
||||
|
||||
|
||||
def test_get_session():
|
||||
app_mod.engine = create_engine("sqlite://")
|
||||
for session in app_mod.get_session():
|
||||
assert isinstance(session, Session)
|
||||
assert session.bind == app_mod.engine
|
||||
|
||||
|
||||
def test_read_hero_not_found(client: TestClient):
|
||||
response = client.get("/heroes/9000")
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_update_hero_not_found(client: TestClient):
|
||||
response = client.patch("/heroes/9000", json={"name": "Very-Rusty-Man"})
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_delete_hero_not_found(client: TestClient):
|
||||
response = client.delete("/heroes/9000")
|
||||
assert response.status_code == 404
|
Reference in New Issue
Block a user