Coverage for tests/test_40_assess10.py : 100%

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.
3## Domain
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
12## Acts
14Starting an assessment.
16`test_resetType`
17: **owner** resets the contribution type to undefined.
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:
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
28 All users cannot perform the proper task either, because the contribution
29 does not have a type yet.
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.
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.
40`test_tryStartAgainOwner`
41: **owner** performs the task `startAssessment` with the proper contribution.
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.
47`test_editor`
48: Then we add **editor** to the editors of the assessment,
50`test_sidebar2`
51: All users check the entries in the sidebar.
52 The editor should see the assessment now as well.
54`test_inspectTitleAll`
55: All users try to check the prefilled title of the assessment.
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.
61`test_modifyTypeAll`
62: All users cannot change the type of the assessment. The assessment type
63 is fixed after creation.
65`test_modifyTitleAll`
66: All users try to change the title of the assessment. Only some succeed.
67 They change it back.
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"""
76import pytest
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)
117startInfo = {}
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 )
134def test_resetType(clientOwner, clientOffice):
135 recordId = startInfo["recordId"]
137 eid = G(recordId, CONTRIB)
138 assertModifyField(clientOwner, CONTRIB, eid, TYPE, (None, UNDEF_VALUE), True)
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"]
153 eid = G(recordId, CONTRIB)
154 theUrl = url.format(eid=eid)
156 def assertIt(cl, exp):
157 assertStatus(cl, theUrl, exp)
159 expect = {user: False for user in USERS}
160 forall(clients, expect, assertIt)
163def test_tryStartAgainAll(clients):
164 recordId = startInfo["recordId"]
165 ids = startInfo["ids"]
167 eid = G(recordId, CONTRIB)
168 assertModifyField(clients[OWNER], CONTRIB, eid, TYPE, (ids["TYPE1"], TYPE1), True)
170 expect = {user: False for user in USERS}
171 expect.update({user: True for user in {OWNER, EDITOR}})
172 startAssessment(clients, eid, expect)
175def test_tryStartAgainOwner(clientOwner):
176 recordId = startInfo["recordId"]
178 eid = G(recordId, CONTRIB)
179 aId = assertStartTask(clientOwner, START_ASSESSMENT, eid, True)
180 assert aId is not None
181 recordId[ASSESS] = aId
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)
197def test_editor(clientOwner):
198 valueTables = startInfo["valueTables"]
199 recordId = startInfo["recordId"]
201 aId = G(recordId, ASSESS)
202 assertEditor(clientOwner, ASSESS, aId, valueTables, True)
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)
218def test_inspectTitleAll(clients):
219 recordId = startInfo["recordId"]
220 recordInfo = startInfo["recordInfo"]
222 eid = G(recordId, CONTRIB)
223 aId = G(recordId, ASSESS)
225 contribInfo = getItem(clients[OWNER], CONTRIB, eid)
226 recordInfo[CONTRIB] = contribInfo
227 fields = contribInfo["fields"]
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)
236def test_inspectTypeAll(clients):
237 recordId = startInfo["recordId"]
239 aId = G(recordId, ASSESS)
241 def assertIt(cl, exp):
242 assertFieldValue((cl, ASSESS, aId), TYPEA, exp)
244 expect = {user: None for user in USERS}
245 expect.update({user: TYPE1 for user in RIGHTFUL_USERS})
246 forall(clients, expect, assertIt)
249def test_modifyTypeAll(clients):
250 recordId = startInfo["recordId"]
251 ids = startInfo["ids"]
253 aId = G(recordId, ASSESS)
255 def assertIt(cl, exp):
256 assertModifyField(cl, ASSESS, aId, TYPEA, (ids["TYPE2"], None), exp)
258 expect = {user: False for user in USERS}
259 forall(clients, expect, assertIt)
262def test_modifyTitleAll(clients):
263 recordId = startInfo["recordId"]
264 recordInfo = startInfo["recordInfo"]
266 aId = G(recordId, ASSESS)
267 contribInfo = recordInfo[CONTRIB]
268 fields = contribInfo["fields"]
270 cTitle = G(fields, TITLE)
271 aTitle = TITLE_A.format(cTitle=cTitle)
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)
278 expect = {user: False for user in USERS}
279 expect.update({user: True for user in RIGHTFUL_USERS})
280 forall(clients, expect, assertIt)
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"]
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)