Coverage for tests\test_get_gui_projects_constraints_annotation.py: 100.00%

99 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-22 23:23 +0100

1# -*- coding: utf-8 -*- 

2 

3""" 

4* Name: interactive-clustering-gui/tests/test_get_gui_projects_constraints_annotation.py 

5* Description: Unittests for `app` module on the `GET /gui/projects/{project_id}/constraints/{constraint_id}/{constraint_id}` route. 

6* Author: Erwan Schild 

7* Created: 22/02/2022 

8* Licence: CeCILL (https://cecill.info/licences.fr.html) 

9""" 

10 

11# ============================================================================== 

12# IMPORT PYTHON DEPENDENCIES 

13# ============================================================================== 

14 

15import html 

16 

17import pytest 

18 

19from tests.dummies_utils import create_dummy_projects 

20 

21# ============================================================================== 

22# test_ko_not_found 

23# ============================================================================== 

24 

25 

26@pytest.mark.asyncio() 

27async def test_ko_not_found_1(async_client): 

28 """ 

29 Test the `GET /gui/projects/{project_id}/constraints/{constraint_id}` route with not existing project. 

30 

31 Arguments: 

32 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

33 """ 

34 # Assert HTTP client is created. 

35 assert async_client 

36 

37 # Assert route `GET /gui/projects/{project_id}/constraints/{constraint_id}` works. 

38 response_get = await async_client.get(url="/gui/projects/UNKNOWN_PROJECT/constraints/UNKNOWN_CONSTRAINT") 

39 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8")) 

40 # assert response_get.status_code == 404 

41 assert response_get.headers["content-type"] == "text/html; charset=utf-8" 

42 assert "<!-- HEAD -->" in parsed_response_get 

43 assert "<title>Interactive Clustering</title>" in parsed_response_get 

44 assert "<!-- BODY -->" in parsed_response_get 

45 assert "<!-- CONTAINER ERROR -->" in parsed_response_get 

46 assert "Error: 404" in parsed_response_get 

47 assert "The project with id 'UNKNOWN_PROJECT' doesn't exist." in parsed_response_get 

48 

49 

50@pytest.mark.asyncio() 

51async def test_ko_not_found_2(async_client, tmp_path): 

52 """ 

53 Test the `GET /gui/projects/{project_id}/constraints/{constraint_id}` route with not existing constraint. 

54 

55 Arguments: 

56 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

57 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

58 """ 

59 # Assert HTTP client is created. 

60 assert async_client 

61 

62 # Create dummy projects. 

63 create_dummy_projects( 

64 tmp_path=tmp_path, 

65 list_of_dummy_project_ids=[ 

66 "0g_ITERATION_END", 

67 ], 

68 ) 

69 

70 # Assert route `GET /gui/projects/{project_id}/constraints/{constraint_id}` works. 

71 response_get = await async_client.get(url="/gui/projects/0g_ITERATION_END/constraints/UNKNOWN_CONSTRAINT") 

72 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8")) 

73 assert response_get.status_code == 200 

74 assert response_get.headers["content-type"] == "text/html; charset=utf-8" 

75 assert "<!-- HEAD -->" in parsed_response_get 

76 assert "<title>Interactive Clustering</title>" in parsed_response_get 

77 assert "<!-- BODY -->" in parsed_response_get 

78 assert "<!-- CONTAINER ERROR -->" in parsed_response_get 

79 assert "Error: 404" in parsed_response_get 

80 assert ( 

81 "In project with id '0g_ITERATION_END', the constraint with id 'UNKNOWN_CONSTRAINT' to annotate doesn't exist." 

82 in parsed_response_get 

83 ) 

84 

85 

86# ============================================================================== 

87# test_ok_1 

88# ============================================================================== 

89 

90 

91@pytest.mark.asyncio() 

92async def test_ok_1(async_client, tmp_path): 

93 """ 

94 Test the `GET /gui/projects/{project_id}/constraints/{constraint_id}` route. 

95 

96 Arguments: 

97 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

98 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

99 """ 

100 # Assert HTTP client is created. 

101 assert async_client 

102 

103 # Create dummy projects. 

104 create_dummy_projects( 

105 tmp_path=tmp_path, 

106 list_of_dummy_project_ids=[ 

107 "1d_ANNOTATION_WITH_UPTODATE_MODELIZATION", 

108 ], 

109 ) 

110 

111 # Assert route `GET /gui/projects/{project_id}/constraints/{constraint_id}` works. 

112 response_get = await async_client.get( 

113 url="/gui/projects/1d_ANNOTATION_WITH_UPTODATE_MODELIZATION/constraints/(0,4)" 

114 ) 

115 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8")) 

116 assert response_get.status_code == 200 

117 assert response_get.headers["content-type"] == "text/html; charset=utf-8" 

118 assert "<!-- HEAD -->" in parsed_response_get 

119 assert "<title>Interactive Clustering</title>" in parsed_response_get 

120 assert "<!-- BODY -->" in parsed_response_get 

121 assert "<!-- CONTAINER ANNOTATION -->" in parsed_response_get 

122 assert "<!-- CONTAINER ANNOTATION - TITLE -->" in parsed_response_get 

123 assert 'id="(0,4)"' in parsed_response_get 

124 assert "Iteration (1): Annotations" in parsed_response_get 

125 assert "<!-- CONTAINER ANNOTATION - CONTENT -->" in parsed_response_get 

126 assert "<!-- CONTAINER ANNOTATION - TEXTS -->" in parsed_response_get 

127 assert "<!-- CONTAINER ANNOTATION - ACTIONS ANNOTATION -->" in parsed_response_get 

128 assert "<!-- CONTAINER ANNOTATION - ACTIONS COMMENT/REVIEW -->" in parsed_response_get 

129 assert "<!-- CONTAINER ANNOTATION - DETAILS -->" in parsed_response_get 

130 assert "<!-- CONTAINER ANNOTATION - DETAILS CARD DESCRIPTION -->" in parsed_response_get 

131 assert "<!-- CONTAINER ANNOTATION - DETAILS CARD LOCAL GRAPH -->" in parsed_response_get 

132 assert "<!-- CONTAINER ANNOTATION - ACTIONS NAVIGATION -->" in parsed_response_get 

133 

134 

135# ============================================================================== 

136# test_ok_2 

137# ============================================================================== 

138 

139 

140@pytest.mark.asyncio() 

141async def test_ok_2(async_client, tmp_path): 

142 """ 

143 Test the `GET /gui/projects/{project_id}/constraints/{constraint_id}` route. 

144 

145 Arguments: 

146 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

147 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

148 """ 

149 # Assert HTTP client is created. 

150 assert async_client 

151 

152 # Create dummy projects. 

153 create_dummy_projects( 

154 tmp_path=tmp_path, 

155 list_of_dummy_project_ids=[ 

156 "1m_CLUSTERING_TODO", 

157 ], 

158 ) 

159 

160 # Assert route `GET /gui/projects/{project_id}/constraints/{constraint_id}` works. 

161 response_get = await async_client.get(url="/gui/projects/1m_CLUSTERING_TODO/constraints/(14,9)") 

162 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8")) 

163 assert response_get.status_code == 200 

164 assert response_get.headers["content-type"] == "text/html; charset=utf-8" 

165 assert "<!-- HEAD -->" in parsed_response_get 

166 assert 'id="(14,9)"' in parsed_response_get 

167 assert "<title>Interactive Clustering</title>" in parsed_response_get 

168 assert "<!-- BODY -->" in parsed_response_get 

169 assert "<!-- CONTAINER ANNOTATION -->" in parsed_response_get 

170 assert "<!-- CONTAINER ANNOTATION - TITLE -->" in parsed_response_get 

171 assert "Iteration (1): Annotations" in parsed_response_get 

172 assert "<!-- CONTAINER ANNOTATION - CONTENT -->" in parsed_response_get 

173 assert "<!-- CONTAINER ANNOTATION - TEXTS -->" in parsed_response_get 

174 assert "<!-- CONTAINER ANNOTATION - ACTIONS ANNOTATION -->" in parsed_response_get 

175 assert "<!-- CONTAINER ANNOTATION - ACTIONS COMMENT/REVIEW -->" in parsed_response_get 

176 assert "<!-- CONTAINER ANNOTATION - DETAILS -->" in parsed_response_get 

177 assert "<!-- CONTAINER ANNOTATION - DETAILS CARD DESCRIPTION -->" in parsed_response_get 

178 assert "<!-- CONTAINER ANNOTATION - DETAILS CARD LOCAL GRAPH -->" in parsed_response_get 

179 assert "<!-- CONTAINER ANNOTATION - ACTIONS NAVIGATION -->" in parsed_response_get 

180 

181 

182# ============================================================================== 

183# test_ok_3 

184# ============================================================================== 

185 

186 

187@pytest.mark.asyncio() 

188async def test_ok_3(async_client, tmp_path): 

189 """ 

190 Test the `GET /gui/projects/{project_id}/constraints/{constraint_id}` route. 

191 

192 Arguments: 

193 async_client: Fixture providing an HTTP client, declared in `conftest.py`. 

194 tmp_path: The temporary path given for this test, declared in `conftest.py`. 

195 """ 

196 # Assert HTTP client is created. 

197 assert async_client 

198 

199 # Create dummy projects. 

200 create_dummy_projects( 

201 tmp_path=tmp_path, 

202 list_of_dummy_project_ids=[ 

203 "1p_ITERATION_END", 

204 ], 

205 ) 

206 

207 # Assert route `GET /gui/projects/{project_id}/constraints/{constraint_id}` works. 

208 response_get = await async_client.get(url="/gui/projects/1p_ITERATION_END/constraints/(18,8)") 

209 parsed_response_get = html.unescape(bytes.decode(response_get.content, encoding="utf-8")) 

210 assert response_get.status_code == 200 

211 assert response_get.headers["content-type"] == "text/html; charset=utf-8" 

212 assert "<!-- HEAD -->" in parsed_response_get 

213 assert 'id="(18,8)"' in parsed_response_get 

214 assert "<title>Interactive Clustering</title>" in parsed_response_get 

215 assert "<!-- BODY -->" in parsed_response_get 

216 assert "<!-- CONTAINER ANNOTATION -->" in parsed_response_get 

217 assert "<!-- CONTAINER ANNOTATION - TITLE -->" in parsed_response_get 

218 assert "Iteration (1): Annotations" in parsed_response_get 

219 assert "<!-- CONTAINER ANNOTATION - CONTENT -->" in parsed_response_get 

220 assert "<!-- CONTAINER ANNOTATION - TEXTS -->" in parsed_response_get 

221 assert "<!-- CONTAINER ANNOTATION - ACTIONS ANNOTATION -->" in parsed_response_get 

222 assert "<!-- CONTAINER ANNOTATION - ACTIONS COMMENT/REVIEW -->" in parsed_response_get 

223 assert "<!-- CONTAINER ANNOTATION - DETAILS -->" in parsed_response_get 

224 assert "<!-- CONTAINER ANNOTATION - DETAILS CARD DESCRIPTION -->" in parsed_response_get 

225 assert "<!-- CONTAINER ANNOTATION - DETAILS CARD LOCAL GRAPH -->" in parsed_response_get 

226 assert "<!-- CONTAINER ANNOTATION - ACTIONS NAVIGATION -->" in parsed_response_get