Coverage for tests/test_30_contrib40.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
8* The country table
9* One contribution record
11## Acts
13Checking the visibility of sensitive fields.
15`test_modifyCost`
16: **owner** sets the cost field to an example value.
18`test_viewCost`
19: all users try to look at the costTotal and costDescription fields,
20 but only some succeed.
22"""
24import pytest
26import magic # noqa
27from control.utils import pick as G
28from conftest import USERS, RIGHTFUL_USERS
29from example import (
30 CONTRIB,
31 COST_BARE,
32 COST_TOTAL,
33 COST_DESCRIPTION,
34 EXAMPLE,
35 MYCOORD,
36)
37from helpers import forall
38from starters import start
39from subtest import (
40 assertFieldValue,
41 assertModifyField,
42)
45startInfo = {}
48@pytest.mark.usefixtures("db")
49def test_start(clientOffice, clientOwner):
50 startInfo.update(start(
51 clientOffice=clientOffice,
52 clientOwner=clientOwner,
53 users=True,
54 contrib=True,
55 countries=True,
56 ))
59def test_modifyCost(clientOwner, clientOffice):
60 recordId = startInfo["recordId"]
62 eid = G(recordId, CONTRIB)
63 value = EXAMPLE[COST_BARE]
64 expect = EXAMPLE[COST_TOTAL]
65 assertModifyField(clientOwner, CONTRIB, eid, COST_TOTAL, (value, expect), True)
67 value = EXAMPLE[COST_DESCRIPTION][0]
68 expect = value.strip()
69 assertModifyField(
70 clientOwner, CONTRIB, eid, COST_DESCRIPTION, (value, expect), True
71 )
74@pytest.mark.parametrize(
75 ("field",), ((COST_TOTAL,), (COST_DESCRIPTION,),),
76)
77def test_viewCost(clients, field):
78 recordId = startInfo["recordId"]
80 eid = G(recordId, CONTRIB)
81 value = EXAMPLE[field]
82 if field == COST_DESCRIPTION:
83 value = value[0]
84 valueStrip = value.strip()
86 def assertIt(cl, exp):
87 assertFieldValue((cl, CONTRIB, eid), field, exp)
89 expect = {user: None for user in USERS}
90 expect.update({user: valueStrip for user in RIGHTFUL_USERS})
91 expect.update({MYCOORD: valueStrip})
92 forall(clients, expect, assertIt)