Coverage for tests\test_get_welcome.py: 100.00%

78 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_welcome.py 

5* Description: Unittests for `app` module on the `GET /` 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 pytest 

16 

17from tests.dummies_utils import create_dummy_projects 

18 

19# ============================================================================== 

20# test_ok 

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

22 

23 

24@pytest.mark.asyncio() 

25async def test_ok(async_client): 

26 """ 

27 Test the `GET /` route. 

28 

29 Arguments: 

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

31 """ 

32 # Assert HTTP client is created. 

33 assert async_client 

34 

35 # Assert route `GET /` works. 

36 response = await async_client.get(url="/") 

37 assert response.status_code == 200 

38 

39 

40# ============================================================================== 

41# test_ok_empty 

42# ============================================================================== 

43 

44 

45@pytest.mark.asyncio() 

46async def test_ok_empty(async_client): 

47 """ 

48 Test the `GET /` route with no projects. 

49 

50 Arguments: 

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

52 """ 

53 # Assert HTTP client is created. 

54 assert async_client 

55 

56 # Assert route `GET /` works. 

57 response_get = await async_client.get(url="/") 

58 assert response_get.status_code == 200 

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

60 assert b"<!-- HEAD -->" in response_get.content 

61 assert b"<title>Interactive Clustering</title>" in response_get.content 

62 assert b"<!-- BODY -->" in response_get.content 

63 assert b"<!-- CONTAINER PROJECTS LISTING -->" in response_get.content 

64 assert b"List of existing projects" in response_get.content 

65 assert b"(no projects)" in response_get.content 

66 assert b"<!-- CONTAINER PROJECTS LISTING - CONTENT -->" in response_get.content 

67 assert response_get.content.count(b'<div class="card" id="') == 0 

68 assert b"<!-- CONTAINER PROJECTS LISTING - CONTENT ACTIONS -->" in response_get.content 

69 assert b"Add new" in response_get.content 

70 assert b"Import" in response_get.content 

71 assert b"<!-- PROJECT CREATION POPUP -->" in response_get.content 

72 assert b"Create" in response_get.content 

73 assert b"<!-- PROJECT IMPORT POPUP -->" in response_get.content 

74 assert b"Import" in response_get.content 

75 

76 

77# ============================================================================== 

78# test_ok_one_project 

79# ============================================================================== 

80 

81 

82@pytest.mark.asyncio() 

83async def test_ok_one_project(async_client, tmp_path): 

84 """ 

85 Test the `GET /` route with one projects. 

86 

87 Arguments: 

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

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

90 """ 

91 # Assert HTTP client is created. 

92 assert async_client 

93 

94 # Create dummy projects. 

95 create_dummy_projects( 

96 tmp_path=tmp_path, 

97 list_of_dummy_project_ids=[ 

98 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

99 ], 

100 ) 

101 

102 # Assert route `GET /` works. 

103 response_get = await async_client.get(url="/") 

104 assert response_get.status_code == 200 

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

106 assert b"<!-- HEAD -->" in response_get.content 

107 assert b"<title>Interactive Clustering</title>" in response_get.content 

108 assert b"<!-- BODY -->" in response_get.content 

109 assert b"<!-- CONTAINER PROJECTS LISTING -->" in response_get.content 

110 assert b"List of existing projects" in response_get.content 

111 assert b"(1 project)" in response_get.content 

112 assert b"<!-- CONTAINER PROJECTS LISTING - CONTENT -->" in response_get.content 

113 assert response_get.content.count(b'<div class="card" id="') == 1 

114 assert b'<div class="card" id="0a_INITIALIZATION_WITHOUT_MODELIZATION">' in response_get.content 

115 assert b"<!-- CONTAINER PROJECTS LISTING - CONTENT ACTIONS -->" in response_get.content 

116 assert b"Add new" in response_get.content 

117 assert b"Import" in response_get.content 

118 assert b"<!-- PROJECT CREATION POPUP -->" in response_get.content 

119 assert b"Create" in response_get.content 

120 assert b"<!-- PROJECT IMPORT POPUP -->" in response_get.content 

121 assert b"Import" in response_get.content 

122 

123 

124# ============================================================================== 

125# test_ok_some_projects 

126# ============================================================================== 

127 

128 

129@pytest.mark.asyncio() 

130async def test_ok_some_projects(async_client, tmp_path): 

131 """ 

132 Test the `GET /` route with some projects. 

133 

134 Arguments: 

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

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

137 """ 

138 # Assert HTTP client is created. 

139 assert async_client 

140 

141 # Create dummy projects. 

142 create_dummy_projects( 

143 tmp_path=tmp_path, 

144 list_of_dummy_project_ids=[ 

145 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

146 "0e_CLUSTERING_PENDING", 

147 "1a_SAMPLING_TODO", 

148 "1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS", 

149 "archive-1d_ANNOTATION_WITH_UPTODATE_MODELIZATION.zip", 

150 ], 

151 ) 

152 

153 # Assert route `GET /` works. 

154 response_get = await async_client.get(url="/") 

155 assert response_get.status_code == 200 

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

157 assert b"<!-- HEAD -->" in response_get.content 

158 assert b"<title>Interactive Clustering</title>" in response_get.content 

159 assert b"<!-- BODY -->" in response_get.content 

160 assert b"<!-- CONTAINER PROJECTS LISTING -->" in response_get.content 

161 assert b"List of existing projects" in response_get.content 

162 assert b"(4 projects)" in response_get.content 

163 assert b"<!-- CONTAINER PROJECTS LISTING - CONTENT -->" in response_get.content 

164 assert response_get.content.count(b'<div class="card" id="') == 4 

165 assert b'<div class="card" id="0a_INITIALIZATION_WITHOUT_MODELIZATION">' in response_get.content 

166 assert b'<div class="card" id="0e_CLUSTERING_PENDING">' in response_get.content 

167 assert b'<div class="card" id="1a_SAMPLING_TODO">' in response_get.content 

168 assert b'<div class="card" id="1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS">' in response_get.content 

169 assert b"<!-- CONTAINER PROJECTS LISTING - CONTENT ACTIONS -->" in response_get.content 

170 assert b"Add new" in response_get.content 

171 assert b"Import" in response_get.content 

172 assert b"<!-- PROJECT CREATION POPUP -->" in response_get.content 

173 assert b"Create" in response_get.content 

174 assert b"<!-- PROJECT IMPORT POPUP -->" in response_get.content 

175 assert b"Import" in response_get.content