138 |
138 |
assert 'Views must have at least one column.' in resp.text
|
139 |
139 |
|
140 |
140 |
|
|
141 |
def test_backoffice_custom_view_user_filter(pub):
|
|
142 |
superuser = create_superuser(pub)
|
|
143 |
|
|
144 |
FormDef.wipe()
|
|
145 |
pub.custom_view_class.wipe()
|
|
146 |
formdef = FormDef()
|
|
147 |
formdef.name = 'form title'
|
|
148 |
formdef.fields = [
|
|
149 |
fields.ItemField(
|
|
150 |
id='1',
|
|
151 |
label='field',
|
|
152 |
type='item',
|
|
153 |
items=['foo', 'bar', 'baz'],
|
|
154 |
display_locations=['validation', 'summary', 'listings'],
|
|
155 |
),
|
|
156 |
]
|
|
157 |
formdef.workflow_roles = {'_receiver': 1}
|
|
158 |
formdef.store()
|
|
159 |
|
|
160 |
user1 = pub.user_class(name='userA')
|
|
161 |
user1.store()
|
|
162 |
user2 = pub.user_class(name='userB')
|
|
163 |
user2.store()
|
|
164 |
|
|
165 |
formdef.data_class().wipe()
|
|
166 |
for i in range(10):
|
|
167 |
formdata = formdef.data_class()()
|
|
168 |
formdata.data = {'1': 'foo', '1_display': 'foo'}
|
|
169 |
if i < 1:
|
|
170 |
formdata.user_id = user1.id
|
|
171 |
elif i < 3:
|
|
172 |
formdata.user_id = user2.id
|
|
173 |
else:
|
|
174 |
formdata.user_id = superuser.id
|
|
175 |
formdata.jump_status('new')
|
|
176 |
formdata.store()
|
|
177 |
|
|
178 |
app = login(get_app(pub))
|
|
179 |
resp = app.get('/backoffice/management/form-title/')
|
|
180 |
assert resp.text.count('<tr') == 10 + 1
|
|
181 |
|
|
182 |
# No value selected, no filtering
|
|
183 |
resp.forms['listing-settings']['filter-user'].checked = True
|
|
184 |
resp = resp.forms['listing-settings'].submit()
|
|
185 |
resp.forms['listing-settings']['filter-user-value'] = ''
|
|
186 |
resp = resp.forms['listing-settings'].submit()
|
|
187 |
assert resp.text.count('<tr') == 10 + 1
|
|
188 |
assert resp.text.count('"cell-user">userA<') == 1
|
|
189 |
assert resp.text.count('"cell-user">userB<') == 2
|
|
190 |
assert resp.text.count('"cell-user">admin<') == 7
|
|
191 |
resp.forms['save-custom-view']['title'] = 'custom test view'
|
|
192 |
resp = resp.forms['save-custom-view'].submit().follow()
|
|
193 |
assert resp.text.count('<tr') == 10 + 1
|
|
194 |
assert resp.text.count('"cell-user">userA<') == 1
|
|
195 |
assert resp.text.count('"cell-user">userB<') == 2
|
|
196 |
assert resp.text.count('"cell-user">admin<') == 7
|
|
197 |
|
|
198 |
# filter on current user
|
|
199 |
resp.forms['listing-settings']['filter-user-value'] = '__current__'
|
|
200 |
resp = resp.forms['listing-settings'].submit()
|
|
201 |
assert resp.text.count('<tr') == 7 + 1
|
|
202 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
203 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
204 |
assert resp.text.count('"cell-user">admin<') == 7
|
|
205 |
resp = resp.forms['save-custom-view'].submit().follow()
|
|
206 |
assert resp.text.count('<tr') == 7 + 1
|
|
207 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
208 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
209 |
assert resp.text.count('"cell-user">admin<') == 7
|
|
210 |
|
|
211 |
# filter on userA
|
|
212 |
resp = app.get(
|
|
213 |
'/backoffice/management/form-title/user-custom-test-view/?filter-user=on&filter-user-value=%s'
|
|
214 |
% user1.id
|
|
215 |
)
|
|
216 |
assert resp.text.count('<tr') == 1 + 1
|
|
217 |
assert resp.text.count('"cell-user">userA<') == 1
|
|
218 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
219 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
220 |
assert '<option value="%s" selected="selected">userA</option>' % user1.id in resp
|
|
221 |
resp = resp.forms['listing-settings'].submit()
|
|
222 |
resp = resp.forms['save-custom-view'].submit().follow()
|
|
223 |
assert resp.text.count('<tr') == 1 + 1
|
|
224 |
assert resp.text.count('"cell-user">userA<') == 1
|
|
225 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
226 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
227 |
|
|
228 |
# filter on unknown
|
|
229 |
resp = app.get(
|
|
230 |
'/backoffice/management/form-title/user-custom-test-view/?filter-user=on&filter-user-value=unknown'
|
|
231 |
)
|
|
232 |
assert resp.text.count('<tr') == 0 + 1
|
|
233 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
234 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
235 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
236 |
assert '<option value="unknown" selected="selected">Unknown</option>' in resp
|
|
237 |
resp = resp.forms['listing-settings'].submit()
|
|
238 |
resp = resp.forms['save-custom-view'].submit().follow()
|
|
239 |
assert resp.text.count('<tr') == 0 + 1
|
|
240 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
241 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
242 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
243 |
|
|
244 |
# filter on uuid - userB
|
|
245 |
user2.name_identifiers = ['0123456789']
|
|
246 |
user2.store()
|
|
247 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-user-uuid=0123456789')
|
|
248 |
assert resp.text.count('<tr') == 2 + 1
|
|
249 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
250 |
assert resp.text.count('"cell-user">userB<') == 2
|
|
251 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
252 |
assert '<option value="%s" selected="selected">userB</option>' % user2.id in resp
|
|
253 |
resp = resp.forms['listing-settings'].submit()
|
|
254 |
resp = resp.forms['save-custom-view'].submit().follow()
|
|
255 |
assert resp.text.count('<tr') == 2 + 1
|
|
256 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
257 |
assert resp.text.count('"cell-user">userB<') == 2
|
|
258 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
259 |
|
|
260 |
# filter on uuid - current
|
|
261 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-user-uuid=__current__')
|
|
262 |
assert resp.text.count('<tr') == 7 + 1
|
|
263 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
264 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
265 |
assert resp.text.count('"cell-user">admin<') == 7
|
|
266 |
assert '<option value="__current__" selected="selected">Current user</option>' in resp
|
|
267 |
resp = resp.forms['listing-settings'].submit()
|
|
268 |
resp = resp.forms['save-custom-view'].submit().follow()
|
|
269 |
assert resp.text.count('<tr') == 7 + 1
|
|
270 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
271 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
272 |
assert resp.text.count('"cell-user">admin<') == 7
|
|
273 |
|
|
274 |
# filter on uuid - unknown
|
|
275 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-user-uuid=unknown')
|
|
276 |
assert resp.text.count('<tr') == 0 + 1
|
|
277 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
278 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
279 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
280 |
assert '<option value="-1" selected="selected">Unknown</option>' in resp
|
|
281 |
resp = resp.forms['listing-settings'].submit()
|
|
282 |
resp = resp.forms['save-custom-view'].submit().follow()
|
|
283 |
assert resp.text.count('<tr') == 0 + 1
|
|
284 |
assert resp.text.count('"cell-user">userA<') == 0
|
|
285 |
assert resp.text.count('"cell-user">userB<') == 0
|
|
286 |
assert resp.text.count('"cell-user">admin<') == 0
|
|
287 |
|
|
288 |
|
141 |
289 |
def test_backoffice_custom_view_delete(pub):
|
142 |
290 |
create_superuser(pub)
|
143 |
291 |
|