]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/blob
b68bc6237db8e508de85c163ec2022654bf15d22
[thirdparty/fastapi/sqlmodel.git] /
1 from unittest.mock import patch
2
3 from sqlmodel import create_engine
4
5 from ....conftest import get_testing_print_function, needs_py39
6
7
8 @needs_py39
9 def test_tutorial(clear_sqlmodel):
10 from docs_src.tutorial.relationship_attributes.cascade_delete_relationships import (
11 tutorial003_py39 as mod,
12 )
13
14 mod.sqlite_url = "sqlite://"
15 mod.engine = create_engine(mod.sqlite_url)
16 calls = []
17
18 new_print = get_testing_print_function(calls)
19
20 with patch("builtins.print", new=new_print):
21 mod.main()
22 assert calls == [
23 [
24 "Created hero:",
25 {
26 "age": None,
27 "id": 1,
28 "name": "Deadpond",
29 "secret_name": "Dive Wilson",
30 "team_id": 1,
31 },
32 ],
33 [
34 "Created hero:",
35 {
36 "age": 48,
37 "id": 2,
38 "name": "Rusty-Man",
39 "secret_name": "Tommy Sharp",
40 "team_id": 2,
41 },
42 ],
43 [
44 "Created hero:",
45 {
46 "age": None,
47 "id": 3,
48 "name": "Spider-Boy",
49 "secret_name": "Pedro Parqueador",
50 "team_id": None,
51 },
52 ],
53 [
54 "Updated hero:",
55 {
56 "age": None,
57 "id": 3,
58 "name": "Spider-Boy",
59 "secret_name": "Pedro Parqueador",
60 "team_id": 2,
61 },
62 ],
63 [
64 "Team Wakaland:",
65 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"},
66 ],
67 [
68 "Deleted team:",
69 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"},
70 ],
71 [
72 "Black Lion has no team:",
73 {
74 "age": 35,
75 "id": 4,
76 "name": "Black Lion",
77 "secret_name": "Trevor Challa",
78 "team_id": None,
79 },
80 ],
81 [
82 "Princess Sure-E has no team:",
83 {
84 "age": None,
85 "id": 5,
86 "name": "Princess Sure-E",
87 "secret_name": "Sure-E",
88 "team_id": None,
89 },
90 ],
91 ]