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 reviews. 

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* One contribution record 

10* One assessment record 

11* The assessment submitted and reviewers assigned. 

12 

13## Acts 

14 

15Filling out reviews. 

16 

17`test_sidebar` 

18: Check the sidebar entries. 

19 

20`test_viewAssessment` 

21: View the assessment and check for the `start review` button. 

22 Only **expert** and **final** should see it. 

23 

24`test_tryStartReviewAll` 

25: All users try to start a review for the assessment. Only **expert** and **final** 

26 succeed and they delete the assessment again. 

27 

28`test_startReview` 

29: **expert** and **final** start their review again. 

30 

31`test_reviewEntries` 

32: All users try to see the review entries. 

33 Only **owner**, **editor**, **expert**, **final**, **mycoord** and the 

34 powerusers succeed. 

35 Moreover, **expert** and **final** see an empty comments field in their column. 

36 

37`test_reviewEntryFillFirstAll` 

38: All users try to fill in the first review comment. 

39 Only **expert** and **final** succeed. 

40 After that, they reset their comment to the empty string. 

41 

42`test_reviewEntryFill` 

43: **expert** and **final** fill out their review entries. 

44""" 

45 

46import pytest 

47 

48import magic # noqa 

49from control.utils import pick as G, E 

50from conftest import USERS, POWER_USERS 

51from example import ( 

52 ASSESS, 

53 BELGIUM, 

54 COMMENTS, 

55 CRITERIA_ENTRY, 

56 EDITOR, 

57 EXPERT, 

58 FINAL, 

59 MYCOORD, 

60 OWNER, 

61 REVIEW, 

62 REVIEW_ENTRY, 

63 START_REVIEW, 

64) 

65from helpers import ( 

66 findReviewEntries, 

67 findTasks, 

68 forall, 

69 getItem, 

70 getReviewEntryId, 

71) 

72from starters import start 

73from subtest import ( 

74 assertDelItem, 

75 assertModifyField, 

76 assertStartTask, 

77 sidebar, 

78) 

79 

80startInfo = {} 

81 

82 

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

84def test_start(clientOffice, clientOwner): 

85 startInfo.update( 

86 start( 

87 clientOffice=clientOffice, 

88 clientOwner=clientOwner, 

89 users=True, 

90 assessment=True, 

91 countries=True, 

92 assign=True, 

93 ) 

94 ) 

95 

96 

97def test_sidebar(clients): 

98 amounts = { 

99 "All contributions": [1], 

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

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

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

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

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

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

106 "Assessments in review by me": [({EXPERT, FINAL}, 1)], 

107 } 

108 sidebar(clients, amounts) 

109 

110 

111def test_viewAssessment(clients): 

112 recordId = startInfo["recordId"] 

113 

114 aId = G(recordId, ASSESS) 

115 

116 def assertIt(cl, exp): 

117 assessInfo = getItem(cl, ASSESS, aId) 

118 text = assessInfo["text"] 

119 tasks = findTasks(text) 

120 if exp: 

121 assert len(tasks) == 1 

122 assert tasks[0] == exp 

123 

124 expect = {user: () for user in USERS} 

125 expect.update({user: (START_REVIEW, aId) for user in (EXPERT, FINAL)}) 

126 forall(clients, expect, assertIt) 

127 

128 

129def test_tryStartReviewAll(clients): 

130 recordId = startInfo["recordId"] 

131 

132 aId = G(recordId, ASSESS) 

133 

134 def assertIt(cl, exp): 

135 rId = assertStartTask(cl, START_REVIEW, aId, exp) 

136 if exp: 

137 assert rId is not None 

138 assertDelItem(cl, REVIEW, rId, True) 

139 else: 

140 assert rId is None 

141 

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

143 expect.update({user: True for user in {EXPERT, FINAL}}) 

144 forall(clients, expect, assertIt) 

145 

146 

147def test_startReview(clientsReviewer): 

148 recordId = startInfo["recordId"] 

149 

150 aId = G(recordId, ASSESS) 

151 recordId.setdefault(REVIEW, {}) 

152 

153 def assertIt(cl, exp): 

154 rId = assertStartTask(cl, START_REVIEW, aId, exp) 

155 assert rId is not None 

156 user = cl.user 

157 recordId[REVIEW][user] = rId 

158 

159 expect = {user: True for user in {EXPERT, FINAL}} 

160 forall(clientsReviewer, expect, assertIt) 

161 

162 

163def test_reviewEntries(clients): 

164 recordId = startInfo["recordId"] 

165 

166 cIds = recordId[CRITERIA_ENTRY] 

167 reviewId = G(recordId, REVIEW) 

168 rEid = G(reviewId, EXPERT) 

169 rFid = G(reviewId, FINAL) 

170 assert rEid is not None 

171 assert rFid is not None 

172 

173 def assertIt(cl, exp): 

174 user = cl.user 

175 for crId in cIds: 

176 criteriaEntryInfo = getItem(cl, CRITERIA_ENTRY, crId) 

177 text = criteriaEntryInfo["text"] 

178 reviewEntries = findReviewEntries(text) 

179 if exp: 

180 if user in {EXPERT, FINAL}: 

181 assert user in reviewEntries 

182 assert COMMENTS in reviewEntries[user][1] 

183 assert reviewEntries[user][1][COMMENTS] == E 

184 else: 

185 assert EXPERT in reviewEntries 

186 assert FINAL in reviewEntries 

187 

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

189 expect.update({user: True for user in POWER_USERS | {EXPERT, FINAL}}) 

190 forall(clients, expect, assertIt) 

191 

192 

193def test_reviewEntryFillFirstAll(clients): 

194 recordId = startInfo["recordId"] 

195 

196 cIds = recordId[CRITERIA_ENTRY] 

197 cIdFirst = cIds[0] 

198 reviewId = recordId[REVIEW] 

199 reviewEntryId = getReviewEntryId( 

200 clients, cIdFirst, reviewId[EXPERT], reviewId[FINAL] 

201 ) 

202 

203 def assertIt(cl, exp): 

204 user = cl.user 

205 for (kind, renId) in reviewEntryId.items(): 

206 thisExp = exp and (kind == user or user in POWER_USERS) 

207 newValue = [f"{user}'s comment"] 

208 newValueRep = ",".join(newValue) 

209 assertModifyField( 

210 cl, REVIEW_ENTRY, renId, COMMENTS, (newValue, newValueRep), thisExp 

211 ) 

212 if thisExp: 

213 assertModifyField(cl, REVIEW_ENTRY, renId, COMMENTS, ([], E), True) 

214 

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

216 expect.update({user: True for user in {EXPERT, FINAL} | POWER_USERS}) 

217 forall(clients, expect, assertIt) 

218 

219 

220def test_reviewEntryFill(clientsReviewer): 

221 recordId = startInfo["recordId"] 

222 

223 cIds = recordId[CRITERIA_ENTRY] 

224 

225 def assertIt(cl, exp): 

226 user = cl.user 

227 for (i, crId) in enumerate(cIds): 

228 criteriaEntryInfo = getItem(cl, CRITERIA_ENTRY, crId) 

229 text = criteriaEntryInfo["text"] 

230 reviewEntries = findReviewEntries(text) 

231 rId = reviewEntries[user][0] 

232 newValue = [f"{user}'s comment on criteria {i + 1}"] 

233 newValueRep = ",".join(newValue) 

234 assertModifyField( 

235 cl, REVIEW_ENTRY, rId, COMMENTS, (newValue, newValueRep), exp 

236 ) 

237 

238 expect = {user: True for user in {EXPERT, FINAL}} 

239 forall(clientsReviewer, expect, assertIt)