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

13 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 00:02 +0000

1from unittest.mock import patch 1jefghi

2 

3from sqlmodel import create_engine 1jefghi

4 

5from tests.conftest import get_testing_print_function, needs_py39 1jefghi

6 

7 

8@needs_py39 1jefghi

9def test_tutorial(clear_sqlmodel): 1efghi

10 from docs_src.tutorial.relationship_attributes.cascade_delete_relationships import ( 1abcd

11 tutorial005_py39 as mod, 

12 ) 

13 

14 mod.sqlite_url = "sqlite://" 1abcd

15 mod.engine = create_engine(mod.sqlite_url) 1abcd

16 calls = [] 1abcd

17 

18 new_print = get_testing_print_function(calls) 1abcd

19 

20 with patch("builtins.print", new=new_print): 1abcd

21 mod.main() 1abcd

22 assert calls == [ 1abcd

23 [ 

24 "Created hero:", 

25 { 

26 "name": "Deadpond", 

27 "secret_name": "Dive Wilson", 

28 "team_id": 1, 

29 "id": 1, 

30 "age": None, 

31 }, 

32 ], 

33 [ 

34 "Created hero:", 

35 { 

36 "name": "Rusty-Man", 

37 "secret_name": "Tommy Sharp", 

38 "team_id": 2, 

39 "id": 2, 

40 "age": 48, 

41 }, 

42 ], 

43 [ 

44 "Created hero:", 

45 { 

46 "name": "Spider-Boy", 

47 "secret_name": "Pedro Parqueador", 

48 "team_id": None, 

49 "id": 3, 

50 "age": None, 

51 }, 

52 ], 

53 [ 

54 "Updated hero:", 

55 { 

56 "name": "Spider-Boy", 

57 "secret_name": "Pedro Parqueador", 

58 "team_id": 2, 

59 "id": 3, 

60 "age": None, 

61 }, 

62 ], 

63 [ 

64 "Team Wakaland:", 

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

66 ], 

67 [ 

68 "Team with removed heroes:", 

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

70 ], 

71 [ 

72 "Deleted team:", 

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

74 ], 

75 [ 

76 "Black Lion has no team:", 

77 { 

78 "name": "Black Lion", 

79 "secret_name": "Trevor Challa", 

80 "team_id": None, 

81 "id": 4, 

82 "age": 35, 

83 }, 

84 ], 

85 [ 

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

87 { 

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

89 "secret_name": "Sure-E", 

90 "team_id": None, 

91 "id": 5, 

92 "age": None, 

93 }, 

94 ], 

95 ]