1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
from unittest.mock import patch
from sqlmodel import create_engine
from ...conftest import get_testing_print_function
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,
],
]
def test_tutorial(clear_sqlmodel):
from docs_src.tutorial.many_to_many import tutorial003 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
|