Coverage for tests/test_tutorial/test_relationship_attributes/test_back_populates/test_tutorial002.py: 100%
13 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
1from unittest.mock import patch 1lghijk
3from sqlmodel import create_engine 1lghijk
5from ....conftest import get_testing_print_function 1lghijk
7expected_calls = [ 1ghijk
8 [
9 "Created hero:",
10 {
11 "age": None,
12 "id": 1,
13 "secret_name": "Dive Wilson",
14 "team_id": 1,
15 "name": "Deadpond",
16 },
17 ],
18 [
19 "Created hero:",
20 {
21 "age": 48,
22 "id": 2,
23 "secret_name": "Tommy Sharp",
24 "team_id": 2,
25 "name": "Rusty-Man",
26 },
27 ],
28 [
29 "Created hero:",
30 {
31 "age": None,
32 "id": 3,
33 "secret_name": "Pedro Parqueador",
34 "team_id": None,
35 "name": "Spider-Boy",
36 },
37 ],
38 [
39 "Updated hero:",
40 {
41 "age": None,
42 "id": 3,
43 "secret_name": "Pedro Parqueador",
44 "team_id": 2,
45 "name": "Spider-Boy",
46 },
47 ],
48 [
49 "Team Wakaland:",
50 {"id": 3, "name": "Wakaland", "headquarters": "Wakaland Capital City"},
51 ],
52 [
53 "Preventers new hero:",
54 {
55 "age": 32,
56 "id": 6,
57 "secret_name": "Natalia Roman-on",
58 "team_id": 2,
59 "name": "Tarantula",
60 },
61 ],
62 [
63 "Preventers new hero:",
64 {
65 "age": 36,
66 "id": 7,
67 "secret_name": "Steve Weird",
68 "team_id": 2,
69 "name": "Dr. Weird",
70 },
71 ],
72 [
73 "Preventers new hero:",
74 {
75 "age": 93,
76 "id": 8,
77 "secret_name": "Esteban Rogelios",
78 "team_id": 2,
79 "name": "Captain North America",
80 },
81 ],
82 [
83 "Preventers heroes:",
84 [
85 {
86 "age": 48,
87 "id": 2,
88 "secret_name": "Tommy Sharp",
89 "team_id": 2,
90 "name": "Rusty-Man",
91 },
92 {
93 "age": None,
94 "id": 3,
95 "secret_name": "Pedro Parqueador",
96 "team_id": 2,
97 "name": "Spider-Boy",
98 },
99 {
100 "age": 32,
101 "id": 6,
102 "secret_name": "Natalia Roman-on",
103 "team_id": 2,
104 "name": "Tarantula",
105 },
106 {
107 "age": 36,
108 "id": 7,
109 "secret_name": "Steve Weird",
110 "team_id": 2,
111 "name": "Dr. Weird",
112 },
113 {
114 "age": 93,
115 "id": 8,
116 "secret_name": "Esteban Rogelios",
117 "team_id": 2,
118 "name": "Captain North America",
119 },
120 ],
121 ],
122 [
123 "Hero Spider-Boy:",
124 {
125 "age": None,
126 "id": 3,
127 "secret_name": "Pedro Parqueador",
128 "team_id": 2,
129 "name": "Spider-Boy",
130 },
131 ],
132 [
133 "Preventers Team:",
134 {"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"},
135 ],
136 [
137 "Preventers Team Heroes:",
138 [
139 {
140 "age": 48,
141 "id": 2,
142 "secret_name": "Tommy Sharp",
143 "team_id": 2,
144 "name": "Rusty-Man",
145 },
146 {
147 "age": None,
148 "id": 3,
149 "secret_name": "Pedro Parqueador",
150 "team_id": 2,
151 "name": "Spider-Boy",
152 },
153 {
154 "age": 32,
155 "id": 6,
156 "secret_name": "Natalia Roman-on",
157 "team_id": 2,
158 "name": "Tarantula",
159 },
160 {
161 "age": 36,
162 "id": 7,
163 "secret_name": "Steve Weird",
164 "team_id": 2,
165 "name": "Dr. Weird",
166 },
167 {
168 "age": 93,
169 "id": 8,
170 "secret_name": "Esteban Rogelios",
171 "team_id": 2,
172 "name": "Captain North America",
173 },
174 ],
175 ],
176 [
177 "Spider-Boy without team:",
178 {
179 "age": None,
180 "id": 3,
181 "secret_name": "Pedro Parqueador",
182 "team_id": 2,
183 "name": "Spider-Boy",
184 },
185 ],
186 [
187 "Preventers Team Heroes again:",
188 [
189 {
190 "age": 48,
191 "id": 2,
192 "secret_name": "Tommy Sharp",
193 "team_id": 2,
194 "name": "Rusty-Man",
195 },
196 {
197 "age": 32,
198 "id": 6,
199 "secret_name": "Natalia Roman-on",
200 "team_id": 2,
201 "name": "Tarantula",
202 },
203 {
204 "age": 36,
205 "id": 7,
206 "secret_name": "Steve Weird",
207 "team_id": 2,
208 "name": "Dr. Weird",
209 },
210 {
211 "age": 93,
212 "id": 8,
213 "secret_name": "Esteban Rogelios",
214 "team_id": 2,
215 "name": "Captain North America",
216 },
217 ],
218 ],
219 ["After committing"],
220 [
221 "Spider-Boy after commit:",
222 {
223 "age": None,
224 "id": 3,
225 "secret_name": "Pedro Parqueador",
226 "team_id": None,
227 "name": "Spider-Boy",
228 },
229 ],
230 [
231 "Preventers Team Heroes after commit:",
232 [
233 {
234 "age": 48,
235 "id": 2,
236 "secret_name": "Tommy Sharp",
237 "team_id": 2,
238 "name": "Rusty-Man",
239 },
240 {
241 "age": 32,
242 "id": 6,
243 "secret_name": "Natalia Roman-on",
244 "team_id": 2,
245 "name": "Tarantula",
246 },
247 {
248 "age": 36,
249 "id": 7,
250 "secret_name": "Steve Weird",
251 "team_id": 2,
252 "name": "Dr. Weird",
253 },
254 {
255 "age": 93,
256 "id": 8,
257 "secret_name": "Esteban Rogelios",
258 "team_id": 2,
259 "name": "Captain North America",
260 },
261 ],
262 ],
263]
266def test_tutorial(clear_sqlmodel): 1lghijk
267 from docs_src.tutorial.relationship_attributes.back_populates import ( 1abcdef
268 tutorial002 as mod,
269 )
271 mod.sqlite_url = "sqlite://" 1abcdef
272 mod.engine = create_engine(mod.sqlite_url) 1abcdef
273 calls = [] 1abcdef
275 new_print = get_testing_print_function(calls) 1abcdef
277 with patch("builtins.print", new=new_print): 1abcdef
278 mod.main() 1abcdef
279 assert calls == expected_calls 1abcdef