]> git.ipfire.org Git - thirdparty/fastapi/sqlmodel.git/blob
d3cd5ae1019800a7250deb95b1e758b5bbbe13f8
[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 "name": "Deadpond",
16 "age": None,
17 "team_id": 1,
18 "id": 1,
19 "secret_name": "Dive Wilson",
20 },
21 ],
22 [
23 "Created hero:",
24 {
25 "name": "Rusty-Man",
26 "age": 48,
27 "team_id": 2,
28 "id": 2,
29 "secret_name": "Tommy Sharp",
30 },
31 ],
32 [
33 "Created hero:",
34 {
35 "name": "Spider-Boy",
36 "age": None,
37 "team_id": None,
38 "id": 3,
39 "secret_name": "Pedro Parqueador",
40 },
41 ],
42 ]
43
44
45 def test_tutorial(clear_sqlmodel):
46 from docs_src.tutorial.relationship_attributes.define_relationship_attributes import (
47 tutorial001 as mod,
48 )
49
50 mod.sqlite_url = "sqlite://"
51 mod.engine = create_engine(mod.sqlite_url)
52 calls = []
53
54 new_print = get_testing_print_function(calls)
55
56 with patch("builtins.print", new=new_print):
57 mod.main()
58 assert calls == expected_calls