]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/blob
afb379e27923916e8c77e7646e92acc13e6c1dba
[thirdparty/fastapi/sqlmodel.git] /
1 from typing import Any, Dict, List, Union
2 from unittest.mock import patch
3
4 from sqlalchemy import inspect
5 from sqlalchemy.engine.reflection import Inspector
6 from sqlmodel import create_engine
7 from sqlmodel.pool import StaticPool
8
9 from ....conftest import get_testing_print_function
10
11 expected_calls = [
12 [
13 "Created hero:",
14 {
15 "age": None,
16 "id": 1,
17 "secret_name": "Dive Wilson",
18 "team_id": 1,
19 "name": "Deadpond",
20 },
21 ],
22 [
23 "Created hero:",
24 {
25 "age": 48,
26 "id": 2,
27 "secret_name": "Tommy Sharp",
28 "team_id": 2,
29 "name": "Rusty-Man",
30 },
31 ],
32 [
33 "Created hero:",
34 {
35 "age": None,
36 "id": 3,
37 "secret_name": "Pedro Parqueador",
38 "team_id": None,
39 "name": "Spider-Boy",
40 },
41 ],
42 [
43 "Updated hero:",
44 {
45 "age": None,
46 "id": 3,
47 "secret_name": "Pedro Parqueador",
48 "team_id": 2,
49 "name": "Spider-Boy",
50 },
51 ],
52 [
53 "Team Wakaland:",
54 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"},
55 ],
56 [
57 "Preventers new hero:",
58 {
59 "age": 32,
60 "id": 6,
61 "secret_name": "Natalia Roman-on",
62 "team_id": 2,
63 "name": "Tarantula",
64 },
65 ],
66 [
67 "Preventers new hero:",
68 {
69 "age": 36,
70 "id": 7,
71 "secret_name": "Steve Weird",
72 "team_id": 2,
73 "name": "Dr. Weird",
74 },
75 ],
76 [
77 "Preventers new hero:",
78 {
79 "age": 93,
80 "id": 8,
81 "secret_name": "Esteban Rogelios",
82 "team_id": 2,
83 "name": "Captain North America",
84 },
85 ],
86 ]
87
88
89 def test_tutorial(clear_sqlmodel):
90 from docs_src.tutorial.relationship_attributes.create_and_update_relationships import (
91 tutorial001 as mod,
92 )
93
94 mod.sqlite_url = "sqlite://"
95 mod.engine = create_engine(mod.sqlite_url)
96 calls = []
97
98 new_print = get_testing_print_function(calls)
99
100 with patch("builtins.print", new=new_print):
101 mod.main()
102 assert calls == expected_calls