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 

9## Acts 

10 

11Getting started with contributions. 

12 

13`test_start` 

14: **office** consults the list of users. 

15 

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. 

20 

21`test_addDelAll` 

22: All users try to add a contribution. Only some succeed, and they delete it again. 

23 

24`test_addOwner` 

25: **owner** adds contribution and stores details for later tests. 

26 

27`test_sidebar2` 

28: All users check the entries in the sidebar. 

29 All users should see 1 contribution now. 

30 

31`test_fields` 

32: **owner** sees that year, country and some 

33 other fields are pre-filled with appropriate values 

34 

35`test_makeEditorAll` 

36: All users try to make **editor** editor of this contribution. 

37 Only some succeed, and remove **editor** again. 

38 

39`test_makeEditorOwner` 

40: **owner** makes **editor** editor of this contribution. 

41 

42`test_sidebar3` 

43: All users check the entries in the sidebar. 

44 The editor should now also see the contribution is `mylist`. 

45 

46""" 

47 

48import pytest 

49 

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 

74 

75 

76startInfo = {} 

77 

78 

79@pytest.mark.usefixtures("db") 

80def test_start(clientOffice): 

81 startInfo.update(start(clientOffice=clientOffice, users=True)) 

82 

83 

84def test_sidebar(clients): 

85 amounts = {} 

86 sidebar(clients, amounts) 

87 

88 

89def test_addDelAll(clients): 

90 def assertIt(cl, exp): 

91 eid = assertAddItem(cl, CONTRIB, exp) 

92 if exp: 

93 assertDelItem(cl, CONTRIB, eid, True) 

94 

95 expect = {user: True for user in USERS} 

96 expect["public"] = False 

97 forall(clients, expect, assertIt) 

98 

99 

100def test_addOwner(clientOwner): 

101 recordId = startInfo["recordId"] 

102 recordInfo = startInfo["recordInfo"] 

103 

104 eid = assertAddItem(clientOwner, CONTRIB, True) 

105 recordId[CONTRIB] = eid 

106 recordInfo[CONTRIB] = getItem(clientOwner, CONTRIB, eid) 

107 

108 

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) 

117 

118 

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

133 

134 assert G(fields, field) == value 

135 

136 

137def test_makeEditorAll(clients): 

138 valueTables = startInfo["valueTables"] 

139 recordId = startInfo["recordId"] 

140 

141 eid = G(recordId, CONTRIB) 

142 

143 def assertIt(cl, exp): 

144 assertEditor(cl, CONTRIB, eid, valueTables, exp) 

145 if exp: 

146 assertEditor(cl, CONTRIB, eid, valueTables, exp, clear=True) 

147 

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) 

151 

152 

153def test_makeEditorOwner(clientOwner): 

154 valueTables = startInfo["valueTables"] 

155 recordId = startInfo["recordId"] 

156 

157 eid = G(recordId, CONTRIB) 

158 assertEditor(clientOwner, CONTRIB, eid, valueTables, True) 

159 

160 

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)