Coverage for tests/test_30_contrib10.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 contributions.
3## Domain
5* Users as in `conftest`, under *players*
6* Clean slate, see `starters`.
7* The user table
9## Acts
11Getting started with contributions.
13`test_start`
14: **office** consults the list of users.
16`test_sidebar`
17: All users check the entries in the sidebar.
18 They check whether they see exactly the ones they expect, and
19 they check what happens when they follow the link.
21`test_addDelAll`
22: All users try to add a contribution. Only some succeed, and they delete it again.
24`test_addOwner`
25: **owner** adds contribution and stores details for later tests.
27`test_sidebar2`
28: All users check the entries in the sidebar.
29 All users should see 1 contribution now.
31`test_fields`
32: **owner** sees that year, country and some
33 other fields are pre-filled with appropriate values
35`test_makeEditorAll`
36: All users try to make **editor** editor of this contribution.
37 Only some succeed, and remove **editor** again.
39`test_makeEditorOwner`
40: **owner** makes **editor** editor of this contribution.
42`test_sidebar3`
43: All users check the entries in the sidebar.
44 The editor should now also see the contribution is `mylist`.
46"""
48import pytest
50import magic # noqa
51from control.utils import pick as G, now
52from conftest import USERS
53from example import (
54 BELGIUM,
55 CONTACT_PERSON_NAME,
56 CONTACT_PERSON_EMAIL,
57 CONTRIB,
58 COUNTRY,
59 EDITOR,
60 MYCOORD,
61 OFFICE,
62 OWNER,
63 OWNER_EMAIL,
64 OWNER_NAME,
65 ROOT,
66 SYSTEM,
67 TITLE,
68 TITLE1,
69 YEAR,
70)
71from helpers import forall, getItem
72from starters import start
73from subtest import assertAddItem, assertDelItem, assertEditor, sidebar
76startInfo = {}
79@pytest.mark.usefixtures("db")
80def test_start(clientOffice):
81 startInfo.update(start(clientOffice=clientOffice, users=True))
84def test_sidebar(clients):
85 amounts = {}
86 sidebar(clients, amounts)
89def test_addDelAll(clients):
90 def assertIt(cl, exp):
91 eid = assertAddItem(cl, CONTRIB, exp)
92 if exp:
93 assertDelItem(cl, CONTRIB, eid, True)
95 expect = {user: True for user in USERS}
96 expect["public"] = False
97 forall(clients, expect, assertIt)
100def test_addOwner(clientOwner):
101 recordId = startInfo["recordId"]
102 recordInfo = startInfo["recordInfo"]
104 eid = assertAddItem(clientOwner, CONTRIB, True)
105 recordId[CONTRIB] = eid
106 recordInfo[CONTRIB] = getItem(clientOwner, CONTRIB, eid)
109def test_sidebar2(clients):
110 amounts = {
111 "All contributions": [1],
112 "My contributions": [({OWNER}, 1)],
113 f"{BELGIUM} contributions": [1],
114 "Contributions to be selected": [({MYCOORD}, 1)],
115 }
116 sidebar(clients, amounts)
119@pytest.mark.parametrize(
120 ("field", "value"),
121 (
122 (TITLE, TITLE1),
123 (YEAR, str(now().year)),
124 (COUNTRY, BELGIUM),
125 (CONTACT_PERSON_NAME, OWNER_NAME),
126 (CONTACT_PERSON_EMAIL, OWNER_EMAIL),
127 ),
128)
129def test_fields(clientOwner, field, value):
130 recordInfo = startInfo["recordInfo"]
131 contribInfo = recordInfo[CONTRIB]
132 fields = G(contribInfo, "fields")
134 assert G(fields, field) == value
137def test_makeEditorAll(clients):
138 valueTables = startInfo["valueTables"]
139 recordId = startInfo["recordId"]
141 eid = G(recordId, CONTRIB)
143 def assertIt(cl, exp):
144 assertEditor(cl, CONTRIB, eid, valueTables, exp)
145 if exp:
146 assertEditor(cl, CONTRIB, eid, valueTables, exp, clear=True)
148 expect = {user: False for user in USERS}
149 expect.update({user: True for user in {OWNER, OFFICE, SYSTEM, ROOT}})
150 forall(clients, expect, assertIt)
153def test_makeEditorOwner(clientOwner):
154 valueTables = startInfo["valueTables"]
155 recordId = startInfo["recordId"]
157 eid = G(recordId, CONTRIB)
158 assertEditor(clientOwner, CONTRIB, eid, valueTables, True)
161def test_sidebar3(clients):
162 amounts = {
163 "All contributions": [1],
164 "My contributions": [({OWNER, EDITOR}, 1)],
165 f"{BELGIUM} contributions": [1],
166 "Contributions to be selected": [({MYCOORD}, 1)],
167 }
168 sidebar(clients, amounts)