mirror of
https://github.com/fastapi/sqlmodel.git
synced 2025-12-19 04:58:50 +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 unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Deadpond",
|
||||
"age": None,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 1,
|
||||
},
|
||||
],
|
||||
[
|
||||
"Hero's team:",
|
||||
{"name": "Z-Force", "headquarters": "Sister Margaret’s Bar", "id": 1},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.code_structure.tutorial001_py310 import app, database
|
||||
|
||||
database.sqlite_url = "sqlite://"
|
||||
database.engine = create_engine(database.sqlite_url)
|
||||
app.engine = database.engine
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
app.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,38 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py39
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Deadpond",
|
||||
"age": None,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 1,
|
||||
},
|
||||
],
|
||||
[
|
||||
"Hero's team:",
|
||||
{"name": "Z-Force", "headquarters": "Sister Margaret’s Bar", "id": 1},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py39
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.code_structure.tutorial001_py39 import app, database
|
||||
|
||||
database.sqlite_url = "sqlite://"
|
||||
database.engine = create_engine(database.sqlite_url)
|
||||
app.engine = database.engine
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
app.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,38 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Deadpond",
|
||||
"age": None,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 1,
|
||||
},
|
||||
],
|
||||
[
|
||||
"Hero's team:",
|
||||
{"name": "Z-Force", "headquarters": "Sister Margaret’s Bar", "id": 1},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.code_structure.tutorial002_py310 import app, database
|
||||
|
||||
database.sqlite_url = "sqlite://"
|
||||
database.engine = create_engine(database.sqlite_url)
|
||||
app.engine = database.engine
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
app.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,38 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py39
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Deadpond",
|
||||
"age": None,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 1,
|
||||
},
|
||||
],
|
||||
[
|
||||
"Hero's team:",
|
||||
{"name": "Z-Force", "headquarters": "Sister Margaret’s Bar", "id": 1},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py39
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.code_structure.tutorial002_py39 import app, database
|
||||
|
||||
database.sqlite_url = "sqlite://"
|
||||
database.engine = create_engine(database.sqlite_url)
|
||||
app.engine = database.engine
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
app.main()
|
||||
assert calls == expected_calls
|
||||
Reference in New Issue
Block a user