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 contributions. 

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* One contribution record 

10 

11## Acts 

12 

13Checking the visibility of sensitive fields. 

14 

15`test_modifyCost` 

16: **owner** sets the cost field to an example value. 

17 

18`test_viewCost` 

19: all users try to look at the costTotal and costDescription fields, 

20 but only some succeed. 

21 

22""" 

23 

24import pytest 

25 

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) 

43 

44 

45startInfo = {} 

46 

47 

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 )) 

57 

58 

59def test_modifyCost(clientOwner, clientOffice): 

60 recordId = startInfo["recordId"] 

61 

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) 

66 

67 value = EXAMPLE[COST_DESCRIPTION][0] 

68 expect = value.strip() 

69 assertModifyField( 

70 clientOwner, CONTRIB, eid, COST_DESCRIPTION, (value, expect), True 

71 ) 

72 

73 

74@pytest.mark.parametrize( 

75 ("field",), ((COST_TOTAL,), (COST_DESCRIPTION,),), 

76) 

77def test_viewCost(clients, field): 

78 recordId = startInfo["recordId"] 

79 

80 eid = G(recordId, CONTRIB) 

81 value = EXAMPLE[field] 

82 if field == COST_DESCRIPTION: 

83 value = value[0] 

84 valueStrip = value.strip() 

85 

86 def assertIt(cl, exp): 

87 assertFieldValue((cl, CONTRIB, eid), field, exp) 

88 

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)