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

9 

10## Acts 

11 

12Modifying contribution fields that have values in value tables. 

13 

14`test_start` 

15: **owner** looks for his contribution, but if it is not there, creates a new one. 

16 So this batch can also be run in isolation. 

17 

18`test_valueEdit` 

19: **owner** opens an edit view for all value fields. 

20 

21`test_modifyVcc` 

22: **owner** enters multiple values in vcc field. 

23 

24`test_modifyVccWrong` 

25: **owner** cannot enter a value from an other value table in the vcc field. 

26 

27`test_modifyVccError` 

28: **owner** cannot enter something that is not a value in a value table. 

29 

30`test_modifyTypeEx1` 

31: **owner** enters a single value in the typeContribution field. 

32 

33`test_modifyTypeMult` 

34: **owner** cannot enter multiple values in the typeContribution field. 

35 

36`test_modifyTypeEx2` 

37: **owner** enters the same single value in the typeContribution field again. 

38 

39`test_modifyTypeWrong` 

40: **owner** cannot enter a value from an other value table in the 

41 typeContribution field. 

42 

43`test_modifyTypeTypo` 

44: **owner** cannot enter a value in a field with a mis-spelled way. 

45 The user could do so with `curl`, he cannot do so in the web-interface. 

46 

47`test_modifyMeta` 

48: **owner** enters multiple values in all metadata fields. 

49 

50`test_addMetaWrong` 

51: **owner** cannot enter new values in metadata fields that do not allow new values. 

52 

53`test_addMetaRight` 

54: **owner** can new values in metadata fields that allow new values. 

55 **office** then deletes these new values. 

56 

57 

58Here we focus on the fields that have values in other tables, the valueTables. 

59 

60""" 

61 

62 

63from pymongo import MongoClient 

64import pytest 

65 

66import magic # noqa 

67from control.utils import pick as G 

68from example import ( 

69 _ID, 

70 DB, 

71 DISCIPLINE, 

72 CONTRIB, 

73 COUNTRY, 

74 EXAMPLE, 

75 KEYWORD, 

76 REP, 

77 TADIRAH_ACTIVITY, 

78 TADIRAH_OBJECT, 

79 TADIRAH_TECHNIQUE, 

80 TYPE, 

81 TYPE1, 

82 TYPE2, 

83 VCC, 

84 VCC1, 

85 VCC2, 

86 VCC12, 

87 YEAR, 

88) 

89from helpers import modifyField 

90from starters import start, getValueTable 

91from subtest import assertModifyField, assertDelItem 

92 

93 

94startInfo = {} 

95 

96 

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

98def test_start(clientOffice, clientOwner): 

99 startInfo.update( 

100 start( 

101 clientOffice=clientOffice, clientOwner=clientOwner, users=True, contrib=True 

102 ) 

103 ) 

104 

105 

106@pytest.mark.parametrize( 

107 ("field",), 

108 ( 

109 (YEAR,), 

110 (COUNTRY,), 

111 (VCC,), 

112 (TYPE,), 

113 (TADIRAH_OBJECT,), 

114 (TADIRAH_ACTIVITY,), 

115 (TADIRAH_TECHNIQUE,), 

116 (DISCIPLINE,), 

117 (KEYWORD,), 

118 ), 

119) 

120def test_valueEdit(clientOffice, clientOwner, field): 

121 valueTables = startInfo["valueTables"] 

122 

123 values = getValueTable(clientOffice, field) 

124 valueTables[field] = values 

125 

126 for exampleValue in EXAMPLE[field]: 

127 assert exampleValue in values 

128 

129 

130def test_modifyVcc(clientOwner): 

131 valueTables = startInfo["valueTables"] 

132 recordId = startInfo["recordId"] 

133 

134 eid = G(recordId, CONTRIB) 

135 vccs = valueTables[VCC] 

136 vcc12 = [vccs[VCC1], vccs[VCC2]] 

137 assertModifyField(clientOwner, CONTRIB, eid, VCC, (vcc12, VCC12), True) 

138 

139 

140def test_modifyVccWrong(clientOwner): 

141 valueTables = startInfo["valueTables"] 

142 recordId = startInfo["recordId"] 

143 

144 eid = G(recordId, CONTRIB) 

145 vccs = valueTables[VCC] 

146 wrongValue = list(valueTables[TADIRAH_OBJECT].values())[0] 

147 vccVal = [wrongValue, vccs["vcc2"]] 

148 assertModifyField(clientOwner, CONTRIB, eid, VCC, (vccVal, None), False) 

149 

150 

151def test_modifyVccError(clientOwner): 

152 valueTables = startInfo["valueTables"] 

153 recordId = startInfo["recordId"] 

154 

155 eid = G(recordId, CONTRIB) 

156 vccs = valueTables[VCC] 

157 vccVal = ["monkey", vccs[VCC2]] 

158 assertModifyField(clientOwner, CONTRIB, eid, VCC, (vccVal, None), False) 

159 

160 

161def test_modifyTypeEx1(clientOwner): 

162 valueTables = startInfo["valueTables"] 

163 recordId = startInfo["recordId"] 

164 

165 eid = G(recordId, CONTRIB) 

166 assertModifyField( 

167 clientOwner, CONTRIB, eid, TYPE, (valueTables[TYPE][TYPE2], TYPE2), True 

168 ) 

169 

170 

171def test_modifyTypeMult(clientOwner): 

172 valueTables = startInfo["valueTables"] 

173 recordId = startInfo["recordId"] 

174 

175 eid = G(recordId, CONTRIB) 

176 types = valueTables[TYPE] 

177 newValue = (types[TYPE2], types[TYPE1]) 

178 assertModifyField(clientOwner, CONTRIB, eid, TYPE, (newValue, None), False) 

179 

180 

181def test_modifyTypeEx2(clientOwner): 

182 valueTables = startInfo["valueTables"] 

183 recordId = startInfo["recordId"] 

184 

185 eid = G(recordId, CONTRIB) 

186 assertModifyField( 

187 clientOwner, CONTRIB, eid, TYPE, (valueTables[TYPE][TYPE2], TYPE2), True 

188 ) 

189 

190 

191def test_modifyTypeWrong(clientOwner): 

192 valueTables = startInfo["valueTables"] 

193 recordId = startInfo["recordId"] 

194 

195 eid = G(recordId, CONTRIB) 

196 wrongValue = list(valueTables[TADIRAH_OBJECT].values())[0] 

197 assertModifyField(clientOwner, CONTRIB, eid, TYPE, wrongValue, False) 

198 

199 

200def test_modifyTypeTypo(clientOwner): 

201 valueTables = startInfo["valueTables"] 

202 recordId = startInfo["recordId"] 

203 

204 eid = G(recordId, CONTRIB) 

205 types = valueTables[TYPE] 

206 fieldx = "xxxContribution" 

207 (text, fields) = modifyField(clientOwner, CONTRIB, eid, fieldx, types[TYPE2]) 

208 assert text == f"No field {CONTRIB}:{fieldx}" 

209 

210 

211@pytest.mark.parametrize( 

212 ("field",), 

213 ( 

214 (TADIRAH_OBJECT,), 

215 (TADIRAH_ACTIVITY,), 

216 (TADIRAH_TECHNIQUE,), 

217 (DISCIPLINE,), 

218 (KEYWORD,), 

219 ), 

220) 

221def test_modifyMeta(clientOwner, field): 

222 valueTables = startInfo["valueTables"] 

223 recordId = startInfo["recordId"] 

224 

225 eid = G(recordId, CONTRIB) 

226 meta = valueTables[field] 

227 checkValues = EXAMPLE[field][0:3] 

228 updateValues = tuple(meta[ex] for ex in checkValues) 

229 

230 assertModifyField( 

231 clientOwner, CONTRIB, eid, field, (updateValues, ",".join(checkValues)), True 

232 ) 

233 

234 

235@pytest.mark.parametrize( 

236 ("field",), 

237 ((VCC,), (TYPE,), (TADIRAH_OBJECT,), (TADIRAH_ACTIVITY,), (TADIRAH_TECHNIQUE,),), 

238) 

239def test_addMetaWrong(clientOwner, field): 

240 recordId = startInfo["recordId"] 

241 

242 eid = G(recordId, CONTRIB) 

243 updateValues = [["xxx"]] 

244 

245 assertModifyField(clientOwner, CONTRIB, eid, field, updateValues, False) 

246 

247 

248@pytest.mark.parametrize( 

249 ("field", "value"), ((DISCIPLINE, "ddd"), (KEYWORD, "kkk"),), 

250) 

251def test_addMetaRight(clientOwner, clientOffice, field, value): 

252 recordId = startInfo["recordId"] 

253 

254 eid = G(recordId, CONTRIB) 

255 updateValues = ((value,),) 

256 assertModifyField(clientOwner, CONTRIB, eid, field, (updateValues, value), True) 

257 assertModifyField(clientOwner, CONTRIB, eid, field, (None, ""), True) 

258 

259 client = MongoClient() 

260 db = client[DB] 

261 mid = list(db[field].find({REP: value}))[0][_ID] 

262 assertDelItem(clientOffice, field, mid, True)