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 

14`test_select` 

15: All users try to 

16 

17 * revoke the selection decision, 

18 * select the contribution, 

19 * deselect the contribution, 

20 * revoke the selection decision. 

21 * revoke the selection decision again. 

22 

23 Nobody succeeds for the first task and last task, because there is no decision. 

24 

25 Only **mycoord** succeeds for the remaining tasks. 

26 

27`test_modify1` 

28: **mycoord** accepts the contribution. Then the contribution is frozen. 

29 We test the frozen-ness. 

30 

31 * All users try to modify the title of the contribution, but fail. 

32 * All users try to start a self-assessment, but fail. 

33 

34`test_modify2` 

35: **mycoord** rejects the contribution. Then the contribution is frozen. 

36 We test the frozen-ness. 

37 

38 * All users try to modify the title of the contribution, but fail. 

39 * All users try to start a self-assessment, but fail. 

40 

41`test_modify3` 

42: **mycoord** revokes the selection decision. Then the contribution is 

43 not frozen anymore. 

44 We test the unfrozen-ness. 

45 

46 * All users try to modify the title of the contribution, 

47 only the rightful users succeed. 

48 * All users try to start a self-assessment, 

49 only *owner** and **editor** succeed. 

50 

51`test_revoke` 

52: **mycoord** takes a decision. 

53 There is a delay time during which this decision can be revoked. 

54 We'll test what happens when the delay time is past. 

55 We do this by updating the `dateDecided` field under water, directly 

56 in Mongo. 

57 

58`test_revokeIntervention` 

59: **mycoord** takes a decision. 

60 We let **office** and **system** revoke that decision. 

61 **office** has a limited time to do that, **system** can do it anytime. 

62 We do this by updating the `dateDecided` field under water, directly 

63 in Mongo. 

64""" 

65 

66import pytest 

67 

68import magic # noqa 

69from control.utils import pick as G, serverprint 

70from conftest import USERS, RIGHTFUL_USERS 

71 

72from example import ( 

73 CONTRIB, 

74 DATE_DECIDED, 

75 EDITOR, 

76 MYCOORD, 

77 OWNER, 

78 SELECT_ACCEPT, 

79 SELECT_REJECT, 

80 SELECT_REVOKE, 

81 TYPE, 

82 TYPE1, 

83) 

84 

85from helpers import forall 

86from starters import start 

87from subtest import ( 

88 assertModifyField, 

89 assertShiftDate, 

90 assertStatus, 

91 modifyTitleAll, 

92 startAssessment, 

93) 

94 

95 

96startInfo = {} 

97 

98 

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

100def test_start(clientOffice, clientOwner): 

101 startInfo.update( 

102 start( 

103 clientOffice=clientOffice, 

104 clientOwner=clientOwner, 

105 users=True, 

106 contrib=True, 

107 types=True, 

108 countries=True, 

109 ) 

110 ) 

111 recordId = startInfo["recordId"] 

112 eid = G(recordId, CONTRIB) 

113 ids = startInfo["ids"] 

114 assertModifyField( 

115 clientOwner, 

116 CONTRIB, 

117 eid, 

118 TYPE, 

119 (ids["TYPE1"], TYPE1), 

120 True, 

121 ) 

122 

123 

124def test_select(clients): 

125 recordId = startInfo["recordId"] 

126 eid = recordId[CONTRIB] 

127 

128 def assertIt(cl, exp): 

129 user = cl.user 

130 decisions = [ 

131 SELECT_REVOKE, 

132 SELECT_ACCEPT, 

133 SELECT_REJECT, 

134 SELECT_REVOKE, 

135 SELECT_REVOKE, 

136 ] 

137 for (i, decision) in enumerate(decisions): 

138 expDecision = False if i == 0 or i == len(decisions) - 1 else exp 

139 serverprint(f"{user} expects to {decision}: {expDecision}") 

140 url = f"/api/task/{decision}/{eid}" 

141 assertStatus(cl, url, expDecision) 

142 

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

144 expect.update({MYCOORD: True}) 

145 forall(clients, expect, assertIt) 

146 

147 

148def test_modify1(clients, clientMycoord): 

149 recordId = startInfo["recordId"] 

150 eid = recordId[CONTRIB] 

151 

152 url = f"/api/task/{SELECT_ACCEPT}/{eid}" 

153 assertStatus(clientMycoord, url, True) 

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

155 modifyTitleAll(clients, CONTRIB, eid, expect) 

156 startAssessment(clients, eid, expect) 

157 

158 

159def test_modify2(clients, clientMycoord): 

160 recordId = startInfo["recordId"] 

161 eid = recordId[CONTRIB] 

162 

163 url = f"/api/task/{SELECT_REJECT}/{eid}" 

164 assertStatus(clientMycoord, url, True) 

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

166 modifyTitleAll(clients, CONTRIB, eid, expect) 

167 startAssessment(clients, eid, expect) 

168 

169 

170def test_modify3(clients, clientMycoord): 

171 recordId = startInfo["recordId"] 

172 eid = recordId[CONTRIB] 

173 

174 url = f"/api/task/{SELECT_REVOKE}/{eid}" 

175 assertStatus(clientMycoord, url, True) 

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

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

178 modifyTitleAll(clients, CONTRIB, eid, expect) 

179 

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

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

182 startAssessment(clients, eid, expect) 

183 

184 

185def test_revoke(clientMycoord, clientSystem): 

186 recordId = startInfo["recordId"] 

187 eid = recordId[CONTRIB] 

188 tests = ( 

189 (SELECT_ACCEPT, 95, SELECT_REJECT, True), 

190 (SELECT_ACCEPT, 97, SELECT_REJECT, False), 

191 (SELECT_REJECT, 95, SELECT_ACCEPT, True), 

192 (SELECT_REJECT, 97, SELECT_ACCEPT, False), 

193 (SELECT_REVOKE, 95, SELECT_ACCEPT, True), 

194 (SELECT_REVOKE, 97, SELECT_ACCEPT, True), 

195 (SELECT_REVOKE, 95, SELECT_REJECT, True), 

196 (SELECT_REVOKE, 97, SELECT_REJECT, True), 

197 (SELECT_ACCEPT, 95, SELECT_REVOKE, True), 

198 (SELECT_ACCEPT, 97, SELECT_REVOKE, False), 

199 (SELECT_REJECT, 95, SELECT_REVOKE, True), 

200 (SELECT_REJECT, 97, SELECT_REVOKE, False), 

201 ) 

202 for (decisionBefore, shiftBack, decisionAfter, exp) in tests: 

203 url = f"/api/task/{decisionBefore}/{eid}" 

204 serverprint(f"{decisionBefore}: True") 

205 assertStatus(clientMycoord, url, True) 

206 

207 assertShiftDate(clientSystem, CONTRIB, eid, DATE_DECIDED, -shiftBack) 

208 

209 url = f"/api/task/{decisionAfter}/{eid}" 

210 serverprint(f"{decisionAfter}: SHIFTBACK {shiftBack}: {exp}") 

211 assertStatus(clientMycoord, url, exp) 

212 assertShiftDate(clientSystem, CONTRIB, eid, DATE_DECIDED, shiftBack) 

213 

214 

215def test_revokeIntervention(clientMycoord, clientOffice, clientSystem): 

216 recordId = startInfo["recordId"] 

217 eid = recordId[CONTRIB] 

218 # note the switch to SELECT_REJECT below after the first failure to revoke: 

219 # this is because mycoord cannot accept an accepted contrib 

220 tests = ( 

221 (SELECT_ACCEPT, 95, SELECT_REVOKE, "office", True), 

222 (SELECT_ACCEPT, 97, SELECT_REVOKE, "office", True), 

223 (SELECT_ACCEPT, 2399, SELECT_REVOKE, "office", True), 

224 (SELECT_ACCEPT, 2401, SELECT_REVOKE, "office", False), 

225 (SELECT_REJECT, 95, SELECT_REVOKE, "system", True), 

226 (SELECT_ACCEPT, 97, SELECT_REVOKE, "system", True), 

227 (SELECT_ACCEPT, 2399, SELECT_REVOKE, "system", True), 

228 (SELECT_ACCEPT, 2401, SELECT_REVOKE, "system", True), 

229 (SELECT_ACCEPT, 24000, SELECT_REVOKE, "system", True), 

230 ) 

231 for (decisionBefore, shiftBack, decisionAfter, who, exp) in tests: 

232 url = f"/api/task/{decisionBefore}/{eid}" 

233 serverprint(f"SELECT DECISION {decisionBefore}: True") 

234 assertStatus(clientMycoord, url, True) 

235 

236 assertShiftDate(clientSystem, CONTRIB, eid, DATE_DECIDED, -shiftBack) 

237 

238 url = f"/api/task/{decisionAfter}/{eid}" 

239 clientWho = ( 

240 clientOffice 

241 if who == "office" 

242 else clientSystem 

243 if who == "system" 

244 else clientMycoord 

245 ) 

246 serverprint(f"{decisionAfter} by {who}: SHIFTBACK {shiftBack}: {exp}") 

247 assertStatus(clientWho, url, exp) 

248 assertShiftDate(clientSystem, CONTRIB, eid, DATE_DECIDED, shiftBack)