📝 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,50 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Deadpond:",
|
||||
{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"},
|
||||
],
|
||||
[
|
||||
"Deadpond teams:",
|
||||
[
|
||||
{"id": 1, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Rusty-Man:",
|
||||
{"id": 2, "secret_name": "Tommy Sharp", "age": 48, "name": "Rusty-Man"},
|
||||
],
|
||||
[
|
||||
"Rusty-Man Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
[
|
||||
"Spider-Boy:",
|
||||
{"id": 3, "secret_name": "Pedro Parqueador", "age": None, "name": "Spider-Boy"},
|
||||
],
|
||||
[
|
||||
"Spider-Boy Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.many_to_many 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,50 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py39
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Deadpond:",
|
||||
{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"},
|
||||
],
|
||||
[
|
||||
"Deadpond teams:",
|
||||
[
|
||||
{"id": 1, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Rusty-Man:",
|
||||
{"id": 2, "secret_name": "Tommy Sharp", "age": 48, "name": "Rusty-Man"},
|
||||
],
|
||||
[
|
||||
"Rusty-Man Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
[
|
||||
"Spider-Boy:",
|
||||
{"id": 3, "secret_name": "Pedro Parqueador", "age": None, "name": "Spider-Boy"},
|
||||
],
|
||||
[
|
||||
"Spider-Boy Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py39
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.many_to_many import tutorial001_py39 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,77 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Deadpond:",
|
||||
{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"},
|
||||
],
|
||||
[
|
||||
"Deadpond teams:",
|
||||
[
|
||||
{"id": 1, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Rusty-Man:",
|
||||
{"id": 2, "secret_name": "Tommy Sharp", "age": 48, "name": "Rusty-Man"},
|
||||
],
|
||||
[
|
||||
"Rusty-Man Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
[
|
||||
"Spider-Boy:",
|
||||
{"id": 3, "secret_name": "Pedro Parqueador", "age": None, "name": "Spider-Boy"},
|
||||
],
|
||||
[
|
||||
"Spider-Boy Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
[
|
||||
"Updated Spider-Boy's Teams:",
|
||||
[
|
||||
{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
{"id": 1, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Z-Force heroes:",
|
||||
[
|
||||
{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"},
|
||||
{
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"age": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Reverted Z-Force's heroes:",
|
||||
[{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"}],
|
||||
],
|
||||
[
|
||||
"Reverted Spider-Boy's teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.many_to_many 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,77 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py39
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Deadpond:",
|
||||
{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"},
|
||||
],
|
||||
[
|
||||
"Deadpond teams:",
|
||||
[
|
||||
{"id": 1, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Rusty-Man:",
|
||||
{"id": 2, "secret_name": "Tommy Sharp", "age": 48, "name": "Rusty-Man"},
|
||||
],
|
||||
[
|
||||
"Rusty-Man Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
[
|
||||
"Spider-Boy:",
|
||||
{"id": 3, "secret_name": "Pedro Parqueador", "age": None, "name": "Spider-Boy"},
|
||||
],
|
||||
[
|
||||
"Spider-Boy Teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
[
|
||||
"Updated Spider-Boy's Teams:",
|
||||
[
|
||||
{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"},
|
||||
{"id": 1, "name": "Z-Force", "headquarters": "Sister Margaret’s Bar"},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Z-Force heroes:",
|
||||
[
|
||||
{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"},
|
||||
{
|
||||
"id": 3,
|
||||
"secret_name": "Pedro Parqueador",
|
||||
"age": None,
|
||||
"name": "Spider-Boy",
|
||||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Reverted Z-Force's heroes:",
|
||||
[{"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"}],
|
||||
],
|
||||
[
|
||||
"Reverted Spider-Boy's teams:",
|
||||
[{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}],
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py39
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.many_to_many import tutorial002_py39 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,73 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py310
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Z-Force hero:",
|
||||
{"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
|
||||
"is training:",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"Preventers hero:",
|
||||
{"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
|
||||
"is training:",
|
||||
True,
|
||||
],
|
||||
[
|
||||
"Preventers hero:",
|
||||
{"name": "Spider-Boy", "secret_name": "Pedro Parqueador", "id": 2, "age": None},
|
||||
"is training:",
|
||||
True,
|
||||
],
|
||||
[
|
||||
"Preventers hero:",
|
||||
{"name": "Rusty-Man", "secret_name": "Tommy Sharp", "id": 3, "age": 48},
|
||||
"is training:",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"Updated Spider-Boy's Teams:",
|
||||
[
|
||||
{"team_id": 2, "is_training": True, "hero_id": 2},
|
||||
{"team_id": 1, "is_training": True, "hero_id": 2},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Z-Force heroes:",
|
||||
[
|
||||
{"team_id": 1, "is_training": False, "hero_id": 1},
|
||||
{"team_id": 1, "is_training": True, "hero_id": 2},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Spider-Boy team:",
|
||||
{"headquarters": "Sharp Tower", "id": 2, "name": "Preventers"},
|
||||
"is training:",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"Spider-Boy team:",
|
||||
{"headquarters": "Sister Margaret’s Bar", "id": 1, "name": "Z-Force"},
|
||||
"is training:",
|
||||
True,
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py310
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.many_to_many 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,73 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from sqlmodel import create_engine
|
||||
|
||||
from ...conftest import get_testing_print_function, needs_py39
|
||||
|
||||
expected_calls = [
|
||||
[
|
||||
"Z-Force hero:",
|
||||
{"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
|
||||
"is training:",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"Preventers hero:",
|
||||
{"name": "Deadpond", "secret_name": "Dive Wilson", "id": 1, "age": None},
|
||||
"is training:",
|
||||
True,
|
||||
],
|
||||
[
|
||||
"Preventers hero:",
|
||||
{"name": "Spider-Boy", "secret_name": "Pedro Parqueador", "id": 2, "age": None},
|
||||
"is training:",
|
||||
True,
|
||||
],
|
||||
[
|
||||
"Preventers hero:",
|
||||
{"name": "Rusty-Man", "secret_name": "Tommy Sharp", "id": 3, "age": 48},
|
||||
"is training:",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"Updated Spider-Boy's Teams:",
|
||||
[
|
||||
{"team_id": 2, "is_training": True, "hero_id": 2},
|
||||
{"team_id": 1, "is_training": True, "hero_id": 2},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Z-Force heroes:",
|
||||
[
|
||||
{"team_id": 1, "is_training": False, "hero_id": 1},
|
||||
{"team_id": 1, "is_training": True, "hero_id": 2},
|
||||
],
|
||||
],
|
||||
[
|
||||
"Spider-Boy team:",
|
||||
{"headquarters": "Sharp Tower", "id": 2, "name": "Preventers"},
|
||||
"is training:",
|
||||
False,
|
||||
],
|
||||
[
|
||||
"Spider-Boy team:",
|
||||
{"headquarters": "Sister Margaret’s Bar", "id": 1, "name": "Z-Force"},
|
||||
"is training:",
|
||||
True,
|
||||
],
|
||||
]
|
||||
|
||||
|
||||
@needs_py39
|
||||
def test_tutorial(clear_sqlmodel):
|
||||
from docs_src.tutorial.many_to_many import tutorial003_py39 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