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