Coverage for tests/test_tutorial/test_relationship_attributes/test_read_relationships/test_tutorial002.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 1lghijk

2 

3from sqlmodel import create_engine 1lghijk

4 

5from ....conftest import get_testing_print_function 1lghijk

6 

7expected_calls = [ 1ghijk

8 [ 

9 "Created hero:", 

10 { 

11 "age": None, 

12 "id": 1, 

13 "secret_name": "Dive Wilson", 

14 "team_id": 1, 

15 "name": "Deadpond", 

16 }, 

17 ], 

18 [ 

19 "Created hero:", 

20 { 

21 "age": 48, 

22 "id": 2, 

23 "secret_name": "Tommy Sharp", 

24 "team_id": 2, 

25 "name": "Rusty-Man", 

26 }, 

27 ], 

28 [ 

29 "Created hero:", 

30 { 

31 "age": None, 

32 "id": 3, 

33 "secret_name": "Pedro Parqueador", 

34 "team_id": None, 

35 "name": "Spider-Boy", 

36 }, 

37 ], 

38 [ 

39 "Updated hero:", 

40 { 

41 "age": None, 

42 "id": 3, 

43 "secret_name": "Pedro Parqueador", 

44 "team_id": 2, 

45 "name": "Spider-Boy", 

46 }, 

47 ], 

48 [ 

49 "Team Wakaland:", 

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

51 ], 

52 [ 

53 "Preventers new hero:", 

54 { 

55 "age": 32, 

56 "id": 6, 

57 "secret_name": "Natalia Roman-on", 

58 "team_id": 2, 

59 "name": "Tarantula", 

60 }, 

61 ], 

62 [ 

63 "Preventers new hero:", 

64 { 

65 "age": 36, 

66 "id": 7, 

67 "secret_name": "Steve Weird", 

68 "team_id": 2, 

69 "name": "Dr. Weird", 

70 }, 

71 ], 

72 [ 

73 "Preventers new hero:", 

74 { 

75 "age": 93, 

76 "id": 8, 

77 "secret_name": "Esteban Rogelios", 

78 "team_id": 2, 

79 "name": "Captain North America", 

80 }, 

81 ], 

82 [ 

83 "Preventers heroes:", 

84 [ 

85 { 

86 "age": 48, 

87 "id": 2, 

88 "secret_name": "Tommy Sharp", 

89 "team_id": 2, 

90 "name": "Rusty-Man", 

91 }, 

92 { 

93 "age": None, 

94 "id": 3, 

95 "secret_name": "Pedro Parqueador", 

96 "team_id": 2, 

97 "name": "Spider-Boy", 

98 }, 

99 { 

100 "age": 32, 

101 "id": 6, 

102 "secret_name": "Natalia Roman-on", 

103 "team_id": 2, 

104 "name": "Tarantula", 

105 }, 

106 { 

107 "age": 36, 

108 "id": 7, 

109 "secret_name": "Steve Weird", 

110 "team_id": 2, 

111 "name": "Dr. Weird", 

112 }, 

113 { 

114 "age": 93, 

115 "id": 8, 

116 "secret_name": "Esteban Rogelios", 

117 "team_id": 2, 

118 "name": "Captain North America", 

119 }, 

120 ], 

121 ], 

122 [ 

123 "Spider-Boy without team:", 

124 { 

125 "age": None, 

126 "id": 3, 

127 "secret_name": "Pedro Parqueador", 

128 "team_id": None, 

129 "name": "Spider-Boy", 

130 }, 

131 ], 

132] 

133 

134 

135def test_tutorial(clear_sqlmodel): 1lghijk

136 from docs_src.tutorial.relationship_attributes.read_relationships import ( 1abcdef

137 tutorial002 as mod, 

138 ) 

139 

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

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

142 calls = [] 1abcdef

143 

144 new_print = get_testing_print_function(calls) 1abcdef

145 

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

147 mod.main() 1abcdef

148 assert calls == expected_calls 1abcdef