Coverage for tests\test_get_gui_projects_listing.py: 100.00%

73 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_listing.py 

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

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

22 

23 

24@pytest.mark.asyncio() 

25async def test_ok_empty(async_client): 

26 """ 

27 Test the `GET /gui/projects` route with no projects. 

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 /gui/projects` works. 

36 response_get = await async_client.get(url="/gui/projects") 

37 assert response_get.status_code == 200 

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

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

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

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

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

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

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

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

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

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

48 assert b"Add new" in response_get.content 

49 assert b"Import" in response_get.content 

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

51 assert b"Create" in response_get.content 

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

53 assert b"Import" in response_get.content 

54 

55 

56# ============================================================================== 

57# test_ok_one_project 

58# ============================================================================== 

59 

60 

61@pytest.mark.asyncio() 

62async def test_ok_one_project(async_client, tmp_path): 

63 """ 

64 Test the `GET /gui/projects` route with one projects. 

65 

66 Arguments: 

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

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

69 """ 

70 # Assert HTTP client is created. 

71 assert async_client 

72 

73 # Create dummy projects. 

74 create_dummy_projects( 

75 tmp_path=tmp_path, 

76 list_of_dummy_project_ids=[ 

77 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

78 ], 

79 ) 

80 

81 # Assert route `GET /gui/projects` works. 

82 response_get = await async_client.get(url="/gui/projects") 

83 assert response_get.status_code == 200 

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

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

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

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

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

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

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

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

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

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

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

95 assert b"Add new" in response_get.content 

96 assert b"Import" in response_get.content 

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

98 assert b"Create" in response_get.content 

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

100 assert b"Import" in response_get.content 

101 

102 

103# ============================================================================== 

104# test_ok_some_projects 

105# ============================================================================== 

106 

107 

108@pytest.mark.asyncio() 

109async def test_ok_some_projects(async_client, tmp_path): 

110 """ 

111 Test the `GET /gui/projects` route with some projects. 

112 

113 Arguments: 

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

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

116 """ 

117 # Assert HTTP client is created. 

118 assert async_client 

119 

120 # Create dummy projects. 

121 create_dummy_projects( 

122 tmp_path=tmp_path, 

123 list_of_dummy_project_ids=[ 

124 "0a_INITIALIZATION_WITHOUT_MODELIZATION", 

125 "0e_CLUSTERING_PENDING", 

126 "1a_SAMPLING_TODO", 

127 "1k_ANNOTATION_WITH_WORKING_MODELIZATION_WITH_CONFLICTS", 

128 "archive-1d_ANNOTATION_WITH_UPTODATE_MODELIZATION.zip", 

129 ], 

130 ) 

131 

132 # Assert route `GET /gui/projects` works. 

133 response_get = await async_client.get(url="/gui/projects") 

134 assert response_get.status_code == 200 

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

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

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

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

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

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

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

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

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

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

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

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

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

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

149 assert b"Add new" in response_get.content 

150 assert b"Import" in response_get.content 

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

152 assert b"Create" in response_get.content 

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

154 assert b"Import" in response_get.content