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

12 statements  

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

1from unittest.mock import patch 1ghijkl

2 

3from sqlmodel import create_engine 1ghijkl

4 

5from tests.conftest import get_testing_print_function 1ghijkl

6 

7 

8def test_tutorial(clear_sqlmodel): 1ghijkl

9 from docs_src.tutorial.relationship_attributes.cascade_delete_relationships import ( 1abcdef

10 tutorial005 as mod, 

11 ) 

12 

13 mod.sqlite_url = "sqlite://" 1abcdef

14 mod.engine = create_engine(mod.sqlite_url) 1abcdef

15 calls = [] 1abcdef

16 

17 new_print = get_testing_print_function(calls) 1abcdef

18 

19 with patch("builtins.print", new=new_print): 1abcdef

20 mod.main() 1abcdef

21 assert calls == [ 1abcdef

22 [ 

23 "Created hero:", 

24 { 

25 "name": "Deadpond", 

26 "secret_name": "Dive Wilson", 

27 "team_id": 1, 

28 "id": 1, 

29 "age": None, 

30 }, 

31 ], 

32 [ 

33 "Created hero:", 

34 { 

35 "name": "Rusty-Man", 

36 "secret_name": "Tommy Sharp", 

37 "team_id": 2, 

38 "id": 2, 

39 "age": 48, 

40 }, 

41 ], 

42 [ 

43 "Created hero:", 

44 { 

45 "name": "Spider-Boy", 

46 "secret_name": "Pedro Parqueador", 

47 "team_id": None, 

48 "id": 3, 

49 "age": None, 

50 }, 

51 ], 

52 [ 

53 "Updated hero:", 

54 { 

55 "name": "Spider-Boy", 

56 "secret_name": "Pedro Parqueador", 

57 "team_id": 2, 

58 "id": 3, 

59 "age": None, 

60 }, 

61 ], 

62 [ 

63 "Team Wakaland:", 

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

65 ], 

66 [ 

67 "Team with removed heroes:", 

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

69 ], 

70 [ 

71 "Deleted team:", 

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

73 ], 

74 [ 

75 "Black Lion has no team:", 

76 { 

77 "name": "Black Lion", 

78 "secret_name": "Trevor Challa", 

79 "team_id": None, 

80 "id": 4, 

81 "age": 35, 

82 }, 

83 ], 

84 [ 

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

86 { 

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

88 "secret_name": "Sure-E", 

89 "team_id": None, 

90 "id": 5, 

91 "age": None, 

92 }, 

93 ], 

94 ]