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 

59import pytest 

60 

61import magic # noqa 

62from control.utils import pick as G, serverprint 

63from conftest import USERS, RIGHTFUL_USERS 

64 

65from example import ( 

66 CONTRIB, 

67 DATE_DECIDED, 

68 EDITOR, 

69 MYCOORD, 

70 OWNER, 

71 SELECT_ACCEPT, 

72 SELECT_REJECT, 

73 SELECT_REVOKE, 

74 TYPE, 

75 TYPE1, 

76) 

77 

78from helpers import forall 

79from starters import start 

80from subtest import ( 

81 assertModifyField, 

82 assertShiftDate, 

83 assertStatus, 

84 modifyTitleAll, 

85 startAssessment, 

86) 

87 

88 

89startInfo = {} 

90 

91 

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

93def test_start(clientOffice, clientOwner): 

94 startInfo.update( 

95 start( 

96 clientOffice=clientOffice, 

97 clientOwner=clientOwner, 

98 users=True, 

99 contrib=True, 

100 types=True, 

101 countries=True, 

102 ) 

103 ) 

104 recordId = startInfo["recordId"] 

105 eid = G(recordId, CONTRIB) 

106 ids = startInfo["ids"] 

107 assertModifyField( 

108 clientOwner, CONTRIB, eid, TYPE, (ids["TYPE1"], TYPE1), True, 

109 ) 

110 

111 

112def test_select(clients): 

113 recordId = startInfo["recordId"] 

114 eid = recordId[CONTRIB] 

115 

116 def assertIt(cl, exp): 

117 user = cl.user 

118 decisions = [ 

119 SELECT_REVOKE, 

120 SELECT_ACCEPT, 

121 SELECT_REJECT, 

122 SELECT_REVOKE, 

123 SELECT_REVOKE, 

124 ] 

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

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

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

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

129 assertStatus(cl, url, expDecision) 

130 

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

132 expect.update({MYCOORD: True}) 

133 forall(clients, expect, assertIt) 

134 

135 

136def test_modify1(clients, clientMycoord): 

137 recordId = startInfo["recordId"] 

138 eid = recordId[CONTRIB] 

139 

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

141 assertStatus(clientMycoord, url, True) 

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

143 modifyTitleAll(clients, CONTRIB, eid, expect) 

144 startAssessment(clients, eid, expect) 

145 

146 

147def test_modify2(clients, clientMycoord): 

148 recordId = startInfo["recordId"] 

149 eid = recordId[CONTRIB] 

150 

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

152 assertStatus(clientMycoord, url, True) 

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

154 modifyTitleAll(clients, CONTRIB, eid, expect) 

155 startAssessment(clients, eid, expect) 

156 

157 

158def test_modify3(clients, clientMycoord): 

159 recordId = startInfo["recordId"] 

160 eid = recordId[CONTRIB] 

161 

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

163 assertStatus(clientMycoord, url, True) 

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

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

166 modifyTitleAll(clients, CONTRIB, eid, expect) 

167 

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

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

170 startAssessment(clients, eid, expect) 

171 

172 

173def test_revoke(clientMycoord, clientSystem): 

174 recordId = startInfo["recordId"] 

175 eid = recordId[CONTRIB] 

176 tests = ( 

177 (SELECT_ACCEPT, 47, SELECT_REJECT, True), 

178 (SELECT_ACCEPT, 49, SELECT_REJECT, False), 

179 (SELECT_REJECT, 47, SELECT_ACCEPT, True), 

180 (SELECT_REJECT, 49, SELECT_ACCEPT, False), 

181 (SELECT_REVOKE, 47, SELECT_ACCEPT, True), 

182 (SELECT_REVOKE, 49, SELECT_ACCEPT, True), 

183 (SELECT_REVOKE, 47, SELECT_REJECT, True), 

184 (SELECT_REVOKE, 49, SELECT_REJECT, True), 

185 (SELECT_ACCEPT, 47, SELECT_REVOKE, True), 

186 (SELECT_ACCEPT, 49, SELECT_REVOKE, False), 

187 (SELECT_REJECT, 47, SELECT_REVOKE, True), 

188 (SELECT_REJECT, 49, SELECT_REVOKE, False), 

189 ) 

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

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

192 assertStatus(clientMycoord, url, True) 

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

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

195 serverprint( 

196 f"REVOCATION: {decisionBefore} SHIFTBACK {shiftBack} {decisionAfter}: {exp}" 

197 ) 

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

199 assertStatus(clientMycoord, url, exp) 

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