1 |
1 |
# -*- coding: utf-8 -*-
|
2 |
2 |
import os
|
|
3 |
import re
|
3 |
4 |
|
4 |
5 |
import pytest
|
5 |
6 |
|
... | ... | |
467 |
468 |
assert resp.location == 'http://example.net/backoffice/management/form-title/1/?plop'
|
468 |
469 |
|
469 |
470 |
|
|
471 |
def test_backoffice_custom_view_sort_field(pub):
|
|
472 |
if not pub.is_using_postgresql():
|
|
473 |
pytest.skip('this requires SQL')
|
|
474 |
return
|
|
475 |
|
|
476 |
create_superuser(pub)
|
|
477 |
|
|
478 |
FormDef.wipe()
|
|
479 |
pub.custom_view_class.wipe()
|
|
480 |
formdef = FormDef()
|
|
481 |
formdef.name = 'form title'
|
|
482 |
formdef.fields = [
|
|
483 |
fields.ItemField(
|
|
484 |
id='1',
|
|
485 |
label='field 1',
|
|
486 |
type='item',
|
|
487 |
items=['foo', 'bar', 'baz'],
|
|
488 |
display_locations=['validation', 'summary', 'listings'],
|
|
489 |
),
|
|
490 |
]
|
|
491 |
formdef.workflow_roles = {'_receiver': 1}
|
|
492 |
formdef.store()
|
|
493 |
|
|
494 |
formdef.data_class().wipe()
|
|
495 |
formdata = formdef.data_class()()
|
|
496 |
formdata.data = {'1': 'foo', '1_display': 'foo'}
|
|
497 |
formdata.jump_status('new')
|
|
498 |
formdata.store()
|
|
499 |
formdata = formdef.data_class()()
|
|
500 |
formdata.data = {'1': 'bar', '1_display': 'bar'}
|
|
501 |
formdata.jump_status('new')
|
|
502 |
formdata.store()
|
|
503 |
formdata = formdef.data_class()()
|
|
504 |
formdata.data = {'1': 'baz', '1_display': 'baz'}
|
|
505 |
formdata.jump_status('new')
|
|
506 |
formdata.store()
|
|
507 |
|
|
508 |
custom_view = pub.custom_view_class()
|
|
509 |
custom_view.title = 'shared custom test view'
|
|
510 |
custom_view.formdef = formdef
|
|
511 |
custom_view.visibility = 'any'
|
|
512 |
custom_view.columns = {'list': [{'id': 'id'}]}
|
|
513 |
custom_view.filters = {}
|
|
514 |
custom_view.order_by = 'f1'
|
|
515 |
custom_view.is_default = True
|
|
516 |
custom_view.store()
|
|
517 |
|
|
518 |
app = login(get_app(pub))
|
|
519 |
resp = app.get('/backoffice/management/form-title/shared-custom-test-view/')
|
|
520 |
assert resp.text.count('<tr') == 4
|
|
521 |
# bar, baz, foo
|
|
522 |
assert re.findall(r'<a href="(\d)/">1-(\d)</a>', resp.text) == [('2', '2'), ('3', '3'), ('1', '1')]
|
|
523 |
|
|
524 |
custom_view.order_by = '-f1'
|
|
525 |
custom_view.store()
|
|
526 |
resp = app.get('/backoffice/management/form-title/shared-custom-test-view/')
|
|
527 |
assert resp.text.count('<tr') == 4
|
|
528 |
# foo, baz, bar
|
|
529 |
assert re.findall(r'<a href="(\d)/">1-(\d)</a>', resp.text) == [('1', '1'), ('3', '3'), ('2', '2')]
|
|
530 |
|
|
531 |
custom_view.order_by = 'unknown'
|
|
532 |
custom_view.store()
|
|
533 |
# unknown sort field, ignore it
|
|
534 |
resp = app.get('/backoffice/management/form-title/shared-custom-test-view/')
|
|
535 |
assert resp.text.count('<tr') == 4
|
|
536 |
|
|
537 |
|
470 |
538 |
def test_carddata_custom_view(pub):
|
471 |
539 |
user = create_user(pub)
|
472 |
540 |
|