📝 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,17 @@
|
||||
from sqlalchemy import inspect
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import needs_py310
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial001(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.create_tables import tutorial001_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
mod.main()
|
||||
insp: Inspector = inspect(mod.engine)
|
||||
assert insp.has_table(str(mod.Hero.__tablename__))
|
||||
assert insp.has_table(str(mod.Team.__tablename__))
|
||||
@@ -0,0 +1,73 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Updated hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": 1,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
[
|
||||
"No longer Preventer:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.delete import tutorial001_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,53 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial001(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.insert import tutorial001_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,92 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
"Team:",
|
||||
{"id": 2, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
],
|
||||
[
|
||||
"Hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
"Team:",
|
||||
{"id": 1, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial001(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.select import tutorial001_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial002(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.select import tutorial002_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,89 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
"Team:",
|
||||
{"id": 2, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
],
|
||||
[
|
||||
"Hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
"Team:",
|
||||
{"id": 1, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
],
|
||||
[
|
||||
"Hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
"Team:",
|
||||
None,
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.select import tutorial003_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,63 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Preventer Hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.select import tutorial004_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,65 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Preventer Hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
"Team:",
|
||||
{"id": 1, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.select import tutorial005_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
@@ -0,0 +1,63 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ....conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 1,
|
||||
"secret_name": "Dive Wilson",
|
||||
"team_id": 2,
|
||||
"name": "Deadpond",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": 48,
|
||||
"id": 2,
|
||||
"secret_name": "Tommy Sharp",
|
||||
"team_id": 1,
|
||||
"name": "Rusty-Man",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Created hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
[
|
||||
"Updated hero:",
|
||||
{
|
||||
"age": None,
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"team_id": 1,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.connect.update import tutorial001_py310 as mod
|
||||
|
||||
mod.sqlite_url = "sqlite://"
|
||||
mod.engine = create_engine(mod.sqlite_url)
|
||||
calls = []
|
||||
|
||||
new_print = get_testing_print_function(calls)
|
||||
|
||||
with patch("builtins.print", new=new_print):
|
||||
mod.main()
|
||||
assert calls == expected_calls
|
||||
Reference in New Issue
Block a user