Coverage for tests/test_40_assess20.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* One contribution record
10* One assessment record
12## Acts
14Starting a second assessment.
16`test_addAssessment`
17: **owner** cannot add another assessment.
19`test_addAssessment2`
20: **owner** modifies type of contribution, which invalidates the assessment,
21 then adds a new assessment, and deletes it afterwards.
22 Also sets the contribution type back to the old value, which validates the
23 assessment.
24"""
26import pytest
28import magic # noqa
29from control.utils import pick as G
30from example import (
31 CONTRIB,
32 ASSESS,
33 START_ASSESSMENT,
34 TITLE,
35 TYPE,
36 TYPE1,
37 TYPE2,
38)
39from helpers import (
40 checkWarning,
41 getEid,
42 getItem,
43)
44from starters import start
45from subtest import (
46 assertDelItem,
47 assertModifyField,
48 assertStartTask,
49)
51startInfo = {}
54@pytest.mark.usefixtures("db")
55def test_start(clientOffice, clientOwner):
56 startInfo.update(
57 start(
58 clientOffice=clientOffice,
59 clientOwner=clientOwner,
60 users=True,
61 assessment=True,
62 countries=True,
63 )
64 )
67def test_addAssessment(clientOwner):
68 recordId = startInfo["recordId"]
70 eid = G(recordId, CONTRIB)
71 aId = assertStartTask(clientOwner, START_ASSESSMENT, eid, False)
72 assert aId is None
75def test_addAssessment2(clientOwner):
76 recordId = startInfo["recordId"]
77 recordInfo = startInfo["recordInfo"]
78 ids = startInfo["ids"]
80 eid = G(recordId, CONTRIB)
81 aId = G(recordId, ASSESS)
83 assessInfo = getItem(clientOwner, ASSESS, aId)
84 recordInfo[ASSESS] = assessInfo
85 fields = assessInfo["fields"]
87 aTitle = G(fields, TITLE)
88 assertModifyField(clientOwner, CONTRIB, eid, TYPE, (ids["TYPE2"], TYPE2), True)
89 assessInfo = getItem(clientOwner, ASSESS, aId)
90 text = assessInfo["text"]
91 assert checkWarning(text, aTitle)
93 assertStartTask(clientOwner, START_ASSESSMENT, eid, True)
94 aIds = getEid(clientOwner, ASSESS, multiple=True)
95 assert len(aIds) == 2
97 newAId = [i for i in aIds if i != aId][0]
98 assertDelItem(clientOwner, ASSESS, newAId, True)
100 assertModifyField(clientOwner, CONTRIB, eid, TYPE, (ids["TYPE1"], TYPE1), True)
101 assessInfo = getItem(clientOwner, ASSESS, aId)
102 text = assessInfo["text"]
103 assert not checkWarning(text, aTitle)