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-06-10 09:40 +0000

1import importlib 1abcdefgh

2from types import ModuleType 1abcdefgh

3 

4import pytest 1abcdefgh

5from sqlmodel import create_engine 1abcdefgh

6 

7from ....conftest import PrintMock 1abcdefgh

8 

9 

10@pytest.fixture( 1abcdefgh

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial005_py310"), 

14 ], 

15) 

16def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh

17 mod = importlib.import_module( 1abcdefgh

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

19 ) 

20 mod.sqlite_url = "sqlite://" 1abcdefgh

21 mod.engine = create_engine(mod.sqlite_url) 1abcdefgh

22 return mod 1abcdefgh

23 

24 

25def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefgh

26 mod.main() 1ijklmnop

27 assert print_mock.calls == [ 1ijklmnop

28 [ 

29 "Created hero:", 

30 { 

31 "name": "Deadpond", 

32 "secret_name": "Dive Wilson", 

33 "team_id": 1, 

34 "id": 1, 

35 "age": None, 

36 }, 

37 ], 

38 [ 

39 "Created hero:", 

40 { 

41 "name": "Rusty-Man", 

42 "secret_name": "Tommy Sharp", 

43 "team_id": 2, 

44 "id": 2, 

45 "age": 48, 

46 }, 

47 ], 

48 [ 

49 "Created hero:", 

50 { 

51 "name": "Spider-Boy", 

52 "secret_name": "Pedro Parqueador", 

53 "team_id": None, 

54 "id": 3, 

55 "age": None, 

56 }, 

57 ], 

58 [ 

59 "Updated hero:", 

60 { 

61 "name": "Spider-Boy", 

62 "secret_name": "Pedro Parqueador", 

63 "team_id": 2, 

64 "id": 3, 

65 "age": None, 

66 }, 

67 ], 

68 [ 

69 "Team Wakaland:", 

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

71 ], 

72 [ 

73 "Team with removed heroes:", 

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

75 ], 

76 [ 

77 "Deleted team:", 

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

79 ], 

80 [ 

81 "Black Lion has no team:", 

82 { 

83 "name": "Black Lion", 

84 "secret_name": "Trevor Challa", 

85 "team_id": None, 

86 "id": 4, 

87 "age": 35, 

88 }, 

89 ], 

90 [ 

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

92 { 

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

94 "secret_name": "Sure-E", 

95 "team_id": None, 

96 "id": 5, 

97 "age": None, 

98 }, 

99 ], 

100 ]