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