Coverage for tests / test_tutorial / test_relationship_attributes / test_delete_records_relationship / test_tutorial005.py: 100%
13 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
1import importlib 1abcdefghi
2from types import ModuleType 1abcdefghi
4import pytest 1abcdefghi
5from sqlalchemy import Engine 1abcdefghi
7from ....conftest import PrintMock 1abcdefghi
10@pytest.fixture( 1abcdefghi
11 name="mod",
12 params=[
13 pytest.param("tutorial005_py310"),
14 ],
15)
16def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghi
17 mod = importlib.import_module( 1abcdefghi
18 f"docs_src.tutorial.relationship_attributes.cascade_delete_relationships.{request.param}"
19 )
20 mod.engine = database_engine 1abcdefghi
21 return mod 1abcdefghi
24def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghi
25 mod.main() 1jklmnopqr
26 assert print_mock.calls == [ 1jklmnopqr
27 [
28 "Created hero:",
29 {
30 "name": "Deadpond",
31 "secret_name": "Dive Wilson",
32 "team_id": 1,
33 "id": 1,
34 "age": None,
35 },
36 ],
37 [
38 "Created hero:",
39 {
40 "name": "Rusty-Man",
41 "secret_name": "Tommy Sharp",
42 "team_id": 2,
43 "id": 2,
44 "age": 48,
45 },
46 ],
47 [
48 "Created hero:",
49 {
50 "name": "Spider-Boy",
51 "secret_name": "Pedro Parqueador",
52 "team_id": None,
53 "id": 3,
54 "age": None,
55 },
56 ],
57 [
58 "Updated hero:",
59 {
60 "name": "Spider-Boy",
61 "secret_name": "Pedro Parqueador",
62 "team_id": 2,
63 "id": 3,
64 "age": None,
65 },
66 ],
67 [
68 "Team Wakaland:",
69 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"},
70 ],
71 [
72 "Team with removed heroes:",
73 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"},
74 ],
75 [
76 "Deleted team:",
77 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"},
78 ],
79 [
80 "Black Lion has no team:",
81 {
82 "name": "Black Lion",
83 "secret_name": "Trevor Challa",
84 "team_id": None,
85 "id": 4,
86 "age": 35,
87 },
88 ],
89 [
90 "Princess Sure-E has no team:",
91 {
92 "name": "Princess Sure-E",
93 "secret_name": "Sure-E",
94 "team_id": None,
95 "id": 5,
96 "age": None,
97 },
98 ],
99 ]