Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""Test scenario for assessments. 

2 

3## Domain 

4 

5* Users as in `conftest`, under *players* 

6* Clean slate, see `starters`. 

7* The user table 

8* The country table 

9* The contribution type table 

10* One contribution record 

11 

12## Acts 

13 

14Starting an assessment. 

15 

16`test_resetType` 

17: **owner** resets the contribution type to undefined. 

18 

19`test_tryStartAll` 

20: We start with a contribution without type. Then we cannot start an assessment. 

21 All users cannot perform out a wrongly shaped task: 

22 

23 * a nonsense task: a typo of `startAssessment` 

24 * without specifying a contribution 

25 * specifying something else than a contribution 

26 * with a nonexisting contribution 

27 

28 All users cannot perform the proper task either, because the contribution 

29 does not have a type yet. 

30 

31`test_tryStartAgainAll` 

32: We assign a type to the contribution. 

33 All users try the task `startAssessment` with the proper contribution. 

34 Only the owner and editor succeed, and they delete the assessment again. 

35 

36 !!! caution 

37 The power users are not allowed to start an assessment of a contribution 

38 of which they are not owner or editor. 

39 

40`test_tryStartAgainOwner` 

41: **owner** performs the task `startAssessment` with the proper contribution. 

42 

43`test_sidebar` 

44: All users check the entries in the sidebar. 

45 All users should see 1 contribution now and some should see 1 assessment too. 

46 

47`test_editor` 

48: Then we add **editor** to the editors of the assessment, 

49 

50`test_sidebar2` 

51: All users check the entries in the sidebar. 

52 The editor should see the assessment now as well. 

53 

54`test_inspectTitleAll` 

55: All users try to check the prefilled title of the assessment. 

56 

57`test_inspectTypeAll` 

58: All users try to check whether the type of the assessment is the same as the one 

59 for the contribution. 

60 

61`test_modifyTypeAll` 

62: All users cannot change the type of the assessment. The assessment type 

63 is fixed after creation. 

64 

65`test_modifyTitleAll` 

66: All users try to change the title of the assessment. Only some succeed. 

67 They change it back. 

68 

69`test_assignReviewers` 

70: All users try to assign reviewers to this assessment, but they all fail. 

71 Most users fail because they do not have the right permission level. 

72 The office user fails because of a workflow condition: 

73 the assessment is not yet submitted. 

74""" 

75 

76import pytest 

77 

78import magic # noqa 

79from control.utils import pick as G 

80from conftest import USERS, RIGHTFUL_USERS, POWER_USERS 

81from example import ( 

82 ASSESS, 

83 BELGIUM, 

84 CONTRIB, 

85 DUMMY_ID, 

86 EDITOR, 

87 EXPERT, 

88 FINAL, 

89 MYCOORD, 

90 OWNER, 

91 REVIEWER_E, 

92 REVIEWER_F, 

93 START_ASSESSMENT, 

94 TITLE, 

95 TITLE_A, 

96 TITLE_A2, 

97 TYPE, 

98 TYPE1, 

99 TYPEA, 

100 UNDEF_VALUE, 

101 USER, 

102) 

103from helpers import forall, getItem 

104from starters import start 

105from subtest import ( 

106 assertEditor, 

107 assertFieldValue, 

108 assertModifyField, 

109 assertStartTask, 

110 assertStatus, 

111 inspectTitleAll, 

112 assignReviewers, 

113 sidebar, 

114 startAssessment, 

115) 

116 

117startInfo = {} 

118 

119 

120@pytest.mark.usefixtures("db") 

121def test_start(clientOffice, clientOwner): 

122 startInfo.update( 

123 start( 

124 clientOffice=clientOffice, 

125 clientOwner=clientOwner, 

126 users=True, 

127 contrib=True, 

128 types=True, 

129 countries=True, 

130 ) 

131 ) 

132 

133 

134def test_resetType(clientOwner, clientOffice): 

135 recordId = startInfo["recordId"] 

136 

137 eid = G(recordId, CONTRIB) 

138 assertModifyField(clientOwner, CONTRIB, eid, TYPE, (None, UNDEF_VALUE), True) 

139 

140 

141@pytest.mark.parametrize( 

142 ("url",), 

143 ( 

144 ("/api/task/startAssessmentXXX",), 

145 (f"/api/task/{START_ASSESSMENT}",), 

146 (f"/api/task/{START_ASSESSMENT}/{DUMMY_ID}",), 

147 (f"/api/task/{START_ASSESSMENT}/{{eid}}",), 

148 ), 

149) 

150def test_tryStartAll(clients, url): 

151 recordId = startInfo["recordId"] 

152 

153 eid = G(recordId, CONTRIB) 

154 theUrl = url.format(eid=eid) 

155 

156 def assertIt(cl, exp): 

157 assertStatus(cl, theUrl, exp) 

158 

159 expect = {user: False for user in USERS} 

160 forall(clients, expect, assertIt) 

161 

162 

163def test_tryStartAgainAll(clients): 

164 recordId = startInfo["recordId"] 

165 ids = startInfo["ids"] 

166 

167 eid = G(recordId, CONTRIB) 

168 assertModifyField(clients[OWNER], CONTRIB, eid, TYPE, (ids["TYPE1"], TYPE1), True) 

169 

170 expect = {user: False for user in USERS} 

171 expect.update({user: True for user in {OWNER, EDITOR}}) 

172 startAssessment(clients, eid, expect) 

173 

174 

175def test_tryStartAgainOwner(clientOwner): 

176 recordId = startInfo["recordId"] 

177 

178 eid = G(recordId, CONTRIB) 

179 aId = assertStartTask(clientOwner, START_ASSESSMENT, eid, True) 

180 assert aId is not None 

181 recordId[ASSESS] = aId 

182 

183 

184def test_sidebar(clients): 

185 amounts = { 

186 "All contributions": [1], 

187 "My contributions": [({OWNER, EDITOR}, 1)], 

188 f"{BELGIUM} contributions": [1], 

189 "Contributions to be selected": [({MYCOORD}, 1)], 

190 "Contributions I am assessing": [({OWNER}, 1)], 

191 "My assessments": [({OWNER}, 1)], 

192 "All assessments": [(POWER_USERS, 1)], 

193 } 

194 sidebar(clients, amounts) 

195 

196 

197def test_editor(clientOwner): 

198 valueTables = startInfo["valueTables"] 

199 recordId = startInfo["recordId"] 

200 

201 aId = G(recordId, ASSESS) 

202 assertEditor(clientOwner, ASSESS, aId, valueTables, True) 

203 

204 

205def test_sidebar2(clients): 

206 amounts = { 

207 "All contributions": [1], 

208 "My contributions": [({OWNER, EDITOR}, 1)], 

209 f"{BELGIUM} contributions": [1], 

210 "Contributions to be selected": [({MYCOORD}, 1)], 

211 "Contributions I am assessing": [({OWNER, EDITOR}, 1)], 

212 "My assessments": [({OWNER, EDITOR}, 1)], 

213 "All assessments": [(POWER_USERS, 1)], 

214 } 

215 sidebar(clients, amounts) 

216 

217 

218def test_inspectTitleAll(clients): 

219 recordId = startInfo["recordId"] 

220 recordInfo = startInfo["recordInfo"] 

221 

222 eid = G(recordId, CONTRIB) 

223 aId = G(recordId, ASSESS) 

224 

225 contribInfo = getItem(clients[OWNER], CONTRIB, eid) 

226 recordInfo[CONTRIB] = contribInfo 

227 fields = contribInfo["fields"] 

228 

229 cTitle = G(fields, TITLE) 

230 aTitle = TITLE_A.format(cTitle=cTitle) 

231 expect = {user: None for user in USERS} 

232 expect.update({user: aTitle for user in RIGHTFUL_USERS}) 

233 inspectTitleAll(clients, ASSESS, aId, expect) 

234 

235 

236def test_inspectTypeAll(clients): 

237 recordId = startInfo["recordId"] 

238 

239 aId = G(recordId, ASSESS) 

240 

241 def assertIt(cl, exp): 

242 assertFieldValue((cl, ASSESS, aId), TYPEA, exp) 

243 

244 expect = {user: None for user in USERS} 

245 expect.update({user: TYPE1 for user in RIGHTFUL_USERS}) 

246 forall(clients, expect, assertIt) 

247 

248 

249def test_modifyTypeAll(clients): 

250 recordId = startInfo["recordId"] 

251 ids = startInfo["ids"] 

252 

253 aId = G(recordId, ASSESS) 

254 

255 def assertIt(cl, exp): 

256 assertModifyField(cl, ASSESS, aId, TYPEA, (ids["TYPE2"], None), exp) 

257 

258 expect = {user: False for user in USERS} 

259 forall(clients, expect, assertIt) 

260 

261 

262def test_modifyTitleAll(clients): 

263 recordId = startInfo["recordId"] 

264 recordInfo = startInfo["recordInfo"] 

265 

266 aId = G(recordId, ASSESS) 

267 contribInfo = recordInfo[CONTRIB] 

268 fields = contribInfo["fields"] 

269 

270 cTitle = G(fields, TITLE) 

271 aTitle = TITLE_A.format(cTitle=cTitle) 

272 

273 def assertIt(cl, exp): 

274 assertModifyField(cl, ASSESS, aId, TITLE, TITLE_A2, exp) 

275 if exp: 

276 assertModifyField(cl, ASSESS, aId, TITLE, aTitle, exp) 

277 

278 expect = {user: False for user in USERS} 

279 expect.update({user: True for user in RIGHTFUL_USERS}) 

280 forall(clients, expect, assertIt) 

281 

282 

283@pytest.mark.parametrize( 

284 ("field", USER), ((REVIEWER_E, EXPERT), (REVIEWER_F, FINAL),), 

285) 

286def test_assignReviewers(clients, field, user): 

287 valueTables = startInfo["valueTables"] 

288 recordId = startInfo["recordId"] 

289 

290 aId = G(recordId, ASSESS) 

291 users = G(valueTables, USER) 

292 expect = {user: False for user in USERS} 

293 assignReviewers(clients, users, aId, field, user, True, expect)