Coverage for tests / test_tutorial / test_relationship_attributes / test_delete_records_relationship / test_tutorial005.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-01-06 21:09 +0000

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlmodel import create_engine 1abcdefghi

6 

7from ....conftest import PrintMock, needs_py310 1abcdefghi

8 

9 

10@pytest.fixture( 1abcdefghi

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial005_py39"), 

14 pytest.param("tutorial005_py310", marks=needs_py310), 

15 ], 

16) 

17def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi

18 mod = importlib.import_module( 1abcdefghi

19 f"docs_src.tutorial.relationship_attributes.cascade_delete_relationships.{request.param}" 

20 ) 

21 mod.sqlite_url = "sqlite://" 1abcdefghi

22 mod.engine = create_engine(mod.sqlite_url) 1abcdefghi

23 return mod 1abcdefghi

24 

25 

26def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghi

27 mod.main() 1jklmnopqr

28 assert print_mock.calls == [ 1jklmnopqr

29 [ 

30 "Created hero:", 

31 { 

32 "name": "Deadpond", 

33 "secret_name": "Dive Wilson", 

34 "team_id": 1, 

35 "id": 1, 

36 "age": None, 

37 }, 

38 ], 

39 [ 

40 "Created hero:", 

41 { 

42 "name": "Rusty-Man", 

43 "secret_name": "Tommy Sharp", 

44 "team_id": 2, 

45 "id": 2, 

46 "age": 48, 

47 }, 

48 ], 

49 [ 

50 "Created hero:", 

51 { 

52 "name": "Spider-Boy", 

53 "secret_name": "Pedro Parqueador", 

54 "team_id": None, 

55 "id": 3, 

56 "age": None, 

57 }, 

58 ], 

59 [ 

60 "Updated hero:", 

61 { 

62 "name": "Spider-Boy", 

63 "secret_name": "Pedro Parqueador", 

64 "team_id": 2, 

65 "id": 3, 

66 "age": None, 

67 }, 

68 ], 

69 [ 

70 "Team Wakaland:", 

71 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"}, 

72 ], 

73 [ 

74 "Team with removed heroes:", 

75 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"}, 

76 ], 

77 [ 

78 "Deleted team:", 

79 {"id": 3, "headquarters": "Wakaland Capital City", "name": "Wakaland"}, 

80 ], 

81 [ 

82 "Black Lion has no team:", 

83 { 

84 "name": "Black Lion", 

85 "secret_name": "Trevor Challa", 

86 "team_id": None, 

87 "id": 4, 

88 "age": 35, 

89 }, 

90 ], 

91 [ 

92 "Princess Sure-E has no team:", 

93 { 

94 "name": "Princess Sure-E", 

95 "secret_name": "Sure-E", 

96 "team_id": None, 

97 "id": 5, 

98 "age": None, 

99 }, 

100 ], 

101 ]