Projet

Général

Profil

0001-tests-also-run-admin-pages-tests-with-sql-enabled.patch

Frédéric Péters, 22 septembre 2015 14:19

Télécharger (32,3 ko)

Voir les différences:

Subject: [PATCH 1/3] tests: also run admin pages tests with sql enabled

 tests/test_admin_pages.py | 334 ++++++++++++++++++++++++----------------------
 tests/test_saml_auth.py   |   3 +-
 2 files changed, 174 insertions(+), 163 deletions(-)
tests/test_admin_pages.py
27 27
from wcs.formdef import FormDef
28 28
from wcs import fields
29 29

  
30
from utilities import get_app, login, create_temporary_pub
30
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
31 31

  
32
def setup_module(module):
33
    cleanup()
32
def pytest_generate_tests(metafunc):
33
    if 'pub' in metafunc.fixturenames:
34
        metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
34 35

  
35
    global pub
36

  
37
    pub = create_temporary_pub()
36
@pytest.fixture
37
def pub(request):
38
    pub = create_temporary_pub(sql_mode=(request.param == 'sql'))
38 39

  
39 40
    req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
40 41
    pub.set_app_dir(req)
......
42 43
    pub.cfg['language'] = {'language': 'en'}
43 44
    pub.write_cfg()
44 45

  
45
def create_superuser():
46
    if pub.user_class.has_key('admin'):
47
        return pub.user_class.get('admin')
46
    return pub
47

  
48
def create_superuser(pub):
49
    if pub.user_class.select(lambda x: x.name == 'admin'):
50
        user1 = pub.user_class.select(lambda x: x.name == 'admin')[0]
51
        user1.is_admin = True
52
        user1.store()
53
        return user1
54

  
48 55
    user1 = pub.user_class(name='admin')
49
    user1.id = 'admin'
50 56
    user1.is_admin = True
51 57
    user1.store()
52 58

  
......
55 61
    account1.user_id = user1.id
56 62
    account1.store()
57 63

  
58
    pub.cfg['identification'] = {'methods': ['password']}
59
    pub.write_cfg()
60

  
61 64
    return user1
62 65

  
63 66
def create_role():
......
67 70
    return role
68 71

  
69 72
def teardown_module(module):
70
    shutil.rmtree(pub.APP_DIR)
73
    clean_temporary_pub()
71 74

  
72
def test_empty_site():
75
def test_empty_site(pub):
73 76
    resp = get_app(pub).get('/backoffice/')
74 77
    resp = resp.click('Users', index=0)
75 78
    resp = resp.click('New User')
76 79
    resp = get_app(pub).get('/backoffice/')
77 80
    resp = resp.click('Settings', index=0)
78 81

  
79
def test_with_user():
80
    create_superuser()
82
def test_with_user(pub):
83
    create_superuser(pub)
81 84
    resp = get_app(pub).get('/backoffice/', status=302)
82 85
    resp = resp.follow()
83 86
    assert resp.location == 'http://example.net/login/'
84 87

  
85
def test_with_superuser():
88
def test_with_superuser(pub):
86 89
    app = login(get_app(pub))
87 90
    app.get('/backoffice/')
88 91

  
89
def test_admin_redirect():
90
    create_superuser()
92
def test_admin_redirect(pub):
93
    create_superuser(pub)
91 94
    app = login(get_app(pub))
92 95
    assert app.get('/admin/whatever', status=302).location == 'http://example.net/backoffice/whatever'
93 96

  
94
def test_admin_for_all():
95
    user = create_superuser()
97
def test_admin_for_all(pub):
98
    user = create_superuser(pub)
96 99
    role = create_role()
97 100

  
98 101
    try:
......
141 144
        user.is_admin = True
142 145
        user.store()
143 146

  
144
def test_forms():
147
def test_forms(pub):
145 148
    app = login(get_app(pub))
146 149
    resp = app.get('/backoffice/forms/')
147 150
    assert 'You first have to define roles.' in resp.body
148 151
    assert not 'New Form' in resp.body
149 152

  
150
def test_forms_new():
153
def test_forms_new(pub):
151 154
    app = login(get_app(pub))
155
    user = create_superuser(pub)
152 156
    create_role()
153 157

  
154 158
    # create a new form
......
167 171
    assert formdef.url_name == 'form-title'
168 172
    assert formdef.fields == []
169 173
    assert formdef.disabled == True
170
    assert formdef.last_modification_user_id == 'admin'
174
    assert formdef.last_modification_user_id == str(user.id)
171 175

  
172 176
def assert_option_display(resp, label, value):
173 177
    option_line = re.findall('%s.*%s' % (label, value), resp.body, re.DOTALL)
174 178
    assert option_line
175 179
    assert not '</li>' in option_line
176 180

  
177
def test_forms_edit():
178
    create_superuser()
181
def test_forms_edit(pub):
182
    create_superuser(pub)
179 183
    create_role()
180 184

  
181 185
    FormDef.wipe()
......
294 298
    assert FormDef.get(1).name == 'new title'
295 299
    assert FormDef.get(1).url_name == 'new-title'
296 300

  
297
def test_form_category():
298
    create_superuser()
301
def test_form_category(pub):
302
    create_superuser(pub)
299 303
    create_role()
300 304

  
301 305
    FormDef.wipe()
......
317 321
    assert 'Category' in resp.body
318 322
    assert_option_display(resp, 'Category', 'None')
319 323

  
320
def test_form_category_select():
321
    create_superuser()
324
def test_form_category_select(pub):
325
    create_superuser(pub)
322 326
    create_role()
323 327

  
324 328
    FormDef.wipe()
......
345 349
    resp = resp.forms[0].submit('submit')
346 350
    assert FormDef.get(formdef.id).category_id == cat.id
347 351

  
348
def test_form_workflow():
349
    create_superuser()
352
def test_form_workflow(pub):
353
    create_superuser(pub)
350 354
    create_role()
351 355

  
352 356
    FormDef.wipe()
......
368 372
    resp = app.get('/backoffice/forms/1/')
369 373
    assert_option_display(resp, 'Workflow', 'Default')
370 374

  
371
def test_form_workflow_change():
372
    create_superuser()
375
def test_form_workflow_change(pub):
376
    create_superuser(pub)
373 377
    create_role()
374 378

  
375 379
    FormDef.wipe()
......
398 402
    resp = resp.forms[0].submit('submit')
399 403
    assert FormDef.get(formdef.id).workflow_id == workflow.id
400 404

  
401
def test_form_workflow_remapping():
402
    create_superuser()
405
def test_form_workflow_remapping(pub):
406
    create_superuser(pub)
403 407
    create_role()
404 408

  
405 409
    FormDef.wipe()
......
437 441
    resp = resp.forms[0].submit()
438 442
    assert data_class.get(1).status == 'wf-finished'
439 443

  
440
def test_form_workflow_role():
441
    create_superuser()
444
def test_form_workflow_role(pub):
445
    create_superuser(pub)
442 446
    create_role()
443 447

  
444 448
    FormDef.wipe()
......
458 462
    resp = resp.forms[0].submit('submit')
459 463
    assert FormDef.get(1).workflow_roles == {'_receiver': '1'}
460 464

  
461
def test_form_workflow_options():
462
    create_superuser()
465
def test_form_workflow_options(pub):
466
    create_superuser(pub)
463 467
    create_role()
464 468

  
465 469
    Workflow.wipe()
......
478 482
    resp = app.get('/backoffice/forms/1/')
479 483
    assert '"workflow-options"' in resp.body
480 484

  
481
def test_form_workflow_variables():
482
    create_superuser()
485
def test_form_workflow_variables(pub):
486
    create_superuser(pub)
483 487
    create_role()
484 488

  
485 489
    Workflow.wipe()
......
520 524
    resp = resp.forms[0].submit('cancel')
521 525
    assert resp.location == 'http://example.net/backoffice/forms/1/'
522 526

  
523
def test_form_roles():
524
    create_superuser()
527
def test_form_roles(pub):
528
    create_superuser(pub)
525 529
    role = create_role()
526 530

  
527 531
    FormDef.wipe()
......
542 546
    resp = resp.forms[0].submit('submit')
543 547
    assert FormDef.get(1).roles == [role.id]
544 548

  
545
def test_form_always_advertise():
546
    create_superuser()
549
def test_form_always_advertise(pub):
550
    create_superuser(pub)
547 551
    role = create_role()
548 552

  
549 553
    FormDef.wipe()
......
569 573
    assert_option_display(resp, 'Display to unlogged users', 'Enabled')
570 574
    assert FormDef.get(1).always_advertise is True
571 575

  
572
def test_form_delete():
576
def test_form_delete(pub):
573 577
    create_role()
574 578

  
575 579
    FormDef.wipe()
......
587 591
    resp = resp.follow()
588 592
    assert FormDef.count() == 0
589 593

  
590
def test_form_duplicate():
594
def test_form_duplicate(pub):
591 595
    create_role()
592 596

  
593 597
    FormDef.wipe()
......
612 616
    assert FormDef.count() == 3
613 617
    assert FormDef.get(3).name == 'form title (copy 2)'
614 618

  
615
def test_form_export():
619
def test_form_export(pub):
616 620
    create_role()
617 621

  
618 622
    FormDef.wipe()
......
631 635
    formdef2 = FormDef.import_from_xml(fd)
632 636
    assert formdef2.name == 'form title'
633 637

  
634
def test_form_import():
635
    user = create_superuser()
638
def test_form_import(pub):
639
    user = create_superuser(pub)
636 640
    role = create_role()
637 641

  
638 642
    FormDef.wipe()
......
662 666
    assert FormDef.get(1).url_name == 'form-title'
663 667
    assert FormDef.get(2).url_name == 'form-title-1'
664 668

  
665
def test_form_qrcode():
669
def test_form_qrcode(pub):
666 670
    create_role()
667 671

  
668 672
    FormDef.wipe()
......
677 681
    resp = resp.click(href='qrcode')
678 682
    assert '<div id="qrcode">' in resp.body
679 683

  
680
def test_form_description():
681
    create_superuser()
684
def test_form_description(pub):
685
    create_superuser(pub)
682 686
    create_role()
683 687

  
684 688
    FormDef.wipe()
......
698 702
    resp = resp.follow()
699 703
    assert_option_display(resp, 'Description', 'On')
700 704

  
701
def test_form_new_field():
702
    create_superuser()
705
def test_form_new_field(pub):
706
    create_superuser(pub)
703 707
    create_role()
704 708

  
705 709
    FormDef.wipe()
......
736 740
    resp = app.get('/backoffice/forms/1/')
737 741
    assert '<h3>baz</h3>' in resp.body
738 742

  
739
def test_form_delete_field():
743
def test_form_delete_field(pub):
740 744
    create_role()
741 745

  
742 746
    FormDef.wipe()
......
757 761
    resp = resp.follow()
758 762
    assert len(FormDef.get(1).fields) == 0
759 763

  
760
def test_form_duplicate_field():
764
def test_form_duplicate_field(pub):
761 765
    create_role()
762 766

  
763 767
    FormDef.wipe()
......
778 782
    assert FormDef.get(1).fields[0].label == '1st field'
779 783
    assert FormDef.get(1).fields[1].label == '1st field'
780 784

  
781
def test_form_edit_field():
785
def test_form_edit_field(pub):
782 786
    create_role()
783 787

  
784 788
    FormDef.wipe()
......
802 806
    assert FormDef.get(1).fields[0].label == 'changed field'
803 807
    assert FormDef.get(1).fields[0].required == False
804 808

  
805
def test_form_edit_field_advanced():
806
    create_superuser()
809
def test_form_edit_field_advanced(pub):
810
    create_superuser(pub)
807 811
    create_role()
808 812

  
809 813
    FormDef.wipe()
......
858 862
    assert resp.body.index('<legend>Additional parameters</legend>') > \
859 863
            resp.body.index('<label for="form_data_source">Data Source</label>')
860 864

  
861
def test_form_legacy_int_id():
862
    create_superuser()
865
def test_form_legacy_int_id(pub):
866
    create_superuser(pub)
863 867
    create_role()
864 868

  
865 869
    Category.wipe()
......
909 913
    resp = resp.click('Recipient')
910 914
    assert resp.forms[0]['role_id'].value == 'ZAB'
911 915

  
912
def test_form_anonymise():
913
    create_superuser()
916
def test_form_anonymise(pub):
917
    create_superuser(pub)
914 918
    create_role()
915 919

  
916 920
    FormDef.wipe()
......
970 974
    assert resp.location == 'http://example.net/backoffice/forms/1/'
971 975
    assert len([x for x in formdef.data_class().select() if x.anonymised]) == 3
972 976

  
973
def test_form_public_url():
974
    create_superuser()
977
def test_form_public_url(pub):
978
    create_superuser(pub)
975 979
    create_role()
976 980

  
977 981
    FormDef.wipe()
......
985 989
    resp = resp.click('Display public URL')
986 990
    assert 'http://example.net/form-title/' in resp.body
987 991

  
988
def test_form_archive():
989
    create_superuser()
992
def test_form_archive(pub):
993
    create_superuser(pub)
990 994
    create_role()
991 995

  
996
    if getattr(pub, 'pgconn', None):
997
        # this doesn't exist in SQL
998
        pytest.skip('no archive in SQL mode')
999
        return
1000

  
992 1001
    FormDef.wipe()
993 1002
    formdef = FormDef()
994 1003
    formdef.name = 'form title'
......
1030 1039
    assert 'formdef' in [x.name for x in tf.getmembers()]
1031 1040
    assert len(tf.getmembers()) == 1 # 0 formdata + 1 formdef
1032 1041

  
1033
def test_form_overwrite():
1034
    user = create_superuser()
1042
def test_form_overwrite(pub):
1043
    user = create_superuser(pub)
1035 1044
    role = create_role()
1036 1045

  
1037 1046
    FormDef.wipe()
......
1104 1113
    assert FormDef.get(formdef_id).url_name == 'form-test'
1105 1114
    assert FormDef.get(formdef_id).table_name == 'xxx'
1106 1115

  
1107
def test_workflows():
1116
def test_workflows(pub):
1108 1117
    app = login(get_app(pub))
1109 1118
    app.get('/backoffice/workflows/')
1110 1119

  
1111
def test_workflows_default():
1120
def test_workflows_default(pub):
1112 1121
    app = login(get_app(pub))
1113 1122
    resp = app.get('/backoffice/workflows/')
1114 1123
    assert 'Default' in resp.body
......
1124 1133
    assert 'Change Status Name' not in resp.body
1125 1134
    assert 'Delete' not in resp.body
1126 1135

  
1127
def test_workflows_new():
1136
def test_workflows_new(pub):
1128 1137
    Workflow.wipe()
1129 1138
    app = login(get_app(pub))
1130 1139
    resp = app.get('/backoffice/workflows/')
......
1166 1175
    assert wf.possible_status[0].name == 'new status'
1167 1176
    assert wf.possible_status[0].items[0].message == 'bla bla bla'
1168 1177

  
1169
def test_workflows_edit():
1178
def test_workflows_edit(pub):
1170 1179
    Workflow.wipe()
1171 1180
    workflow = Workflow(name='foo')
1172 1181
    workflow.store()
......
1181 1190
    resp = resp.follow()
1182 1191
    assert 'baz' in resp.body
1183 1192

  
1184
def test_workflows_edit_status():
1193
def test_workflows_edit_status(pub):
1185 1194
    Workflow.wipe()
1186 1195
    workflow = Workflow(name='foo')
1187 1196
    workflow.add_status(name='baz')
......
1228 1237
    resp = resp.follow()
1229 1238
    assert Workflow.get(1).possible_status[0].backoffice_info_text == '<p>Hello</p>'
1230 1239

  
1231
def test_workflows_delete():
1240
def test_workflows_delete(pub):
1232 1241
    Workflow.wipe()
1233 1242
    workflow = Workflow(name='foo')
1234 1243
    workflow.store()
......
1242 1251
    resp = resp.follow()
1243 1252
    assert Workflow.count() == 0
1244 1253

  
1245
def test_workflows_add_all_actions():
1254
def test_workflows_add_all_actions(pub):
1246 1255
    Workflow.wipe()
1247 1256
    workflow = Workflow(name='foo')
1248 1257
    workflow.add_status(name='baz')
......
1263 1272
        resp = resp.follow() # redirect to items/
1264 1273
        resp = resp.follow() # redirect to ./
1265 1274

  
1266
def test_workflows_variables():
1267
    create_superuser()
1275
def test_workflows_variables(pub):
1276
    create_superuser(pub)
1268 1277
    create_role()
1269 1278

  
1270 1279
    Workflow.wipe()
......
1293 1302
    assert Workflow.get(1).variables_formdef.fields[0].key == 'string'
1294 1303
    assert Workflow.get(1).variables_formdef.fields[0].label == 'foobar'
1295 1304

  
1296
def test_workflows_variables_edit():
1297
    test_workflows_variables()
1305
def test_workflows_variables_edit(pub):
1306
    test_workflows_variables(pub)
1298 1307

  
1299 1308
    app = login(get_app(pub))
1300 1309
    resp = app.get('/backoffice/workflows/1/')
......
1321 1330
    assert Workflow.get(1).variables_formdef.fields[0].key == 'string'
1322 1331
    assert Workflow.get(1).variables_formdef.fields[0].varname == '1*1*message'
1323 1332

  
1324
def test_workflows_functions():
1325
    create_superuser()
1333
def test_workflows_functions(pub):
1334
    create_superuser(pub)
1326 1335
    create_role()
1327 1336

  
1328 1337
    Workflow.wipe()
......
1365 1374
    resp = resp.click('Recipient')
1366 1375
    assert not 'delete' in resp.forms[0].fields
1367 1376

  
1368
def test_workflows_functions_vs_visibility():
1369
    create_superuser()
1377
def test_workflows_functions_vs_visibility(pub):
1378
    create_superuser(pub)
1370 1379
    create_role()
1371 1380

  
1372 1381
    Workflow.wipe()
......
1403 1412
    assert set(Workflow.get(workflow.id).possible_status[2].visibility) == set(
1404 1413
            ['_receiver', '_other-function'])
1405 1414

  
1406
def test_users():
1407
    create_superuser()
1415
def test_users(pub):
1416
    create_superuser(pub)
1408 1417
    app = login(get_app(pub))
1409 1418
    app.get('/backoffice/users/')
1410 1419

  
1411
def test_users_new():
1420
def test_users_new(pub):
1412 1421
    pub.user_class.wipe()
1413
    create_superuser()
1422
    create_superuser(pub)
1414 1423
    user_count = pub.user_class.count()
1415 1424
    account_count = PasswordAccount.count()
1416 1425
    app = login(get_app(pub))
......
1426 1435
    assert pub.user_class.count() == user_count + 1
1427 1436
    assert PasswordAccount.count() == account_count
1428 1437

  
1429
def test_users_new_with_account():
1438
def test_users_new_with_account(pub):
1430 1439
    pub.user_class.wipe()
1431
    create_superuser()
1440
    create_superuser(pub)
1432 1441
    user_count = pub.user_class.count()
1433 1442
    account_count = PasswordAccount.count()
1434 1443
    app = login(get_app(pub))
......
1446 1455
    assert pub.user_class.count() == user_count + 1
1447 1456
    assert PasswordAccount.count() == account_count + 1
1448 1457

  
1449
def test_users_edit():
1458
def test_users_edit(pub):
1450 1459
    pub.user_class.wipe()
1451
    create_superuser()
1460
    create_superuser(pub)
1452 1461
    user = pub.user_class(name='foo bar')
1453 1462
    user.store()
1454
    assert user.id == '2'
1455 1463

  
1456 1464
    app = login(get_app(pub))
1457
    resp = app.get('/backoffice/users/2/')
1465
    resp = app.get('/backoffice/users/%s/' % user.id)
1458 1466
    resp = resp.click(href='edit')
1459 1467
    resp.forms[0]['is_admin'].checked = True
1460 1468
    resp = resp.forms[0].submit('submit')
1461
    assert resp.location == 'http://example.net/backoffice/users/2/'
1469
    assert resp.location == 'http://example.net/backoffice/users/%s/' % user.id
1462 1470
    resp = resp.follow()
1463 1471

  
1464
def test_users_edit_new_account():
1472
def test_users_edit_new_account(pub):
1465 1473
    pub.user_class.wipe()
1466 1474
    PasswordAccount.wipe()
1467
    create_superuser()
1475
    create_superuser(pub)
1468 1476
    user = pub.user_class(name='foo bar')
1469 1477
    user.store()
1470
    assert user.id == '2'
1471 1478
    account_count = PasswordAccount.count()
1472 1479

  
1473 1480
    app = login(get_app(pub))
1474
    resp = app.get('/backoffice/users/2/')
1481
    resp = app.get('/backoffice/users/%s/' % user.id)
1475 1482
    resp = resp.click(href='edit')
1476 1483
    resp.forms[0]['is_admin'].checked = True
1477 1484
    resp.forms[0]['method_password$username'] = 'foo'
1478 1485
    resp.forms[0]['method_password$password'] = 'bar'
1479 1486
    resp = resp.forms[0].submit('submit')
1480
    assert resp.location == 'http://example.net/backoffice/users/2/'
1487
    assert resp.location == 'http://example.net/backoffice/users/%s/' % user.id
1481 1488
    resp = resp.follow()
1482 1489

  
1483 1490
    assert PasswordAccount.count() == account_count + 1
1484 1491

  
1485
def test_users_edit_edit_account():
1492
def test_users_edit_edit_account(pub):
1486 1493
    pub.user_class.wipe()
1487 1494
    PasswordAccount.wipe()
1488
    create_superuser()
1495
    create_superuser(pub)
1489 1496
    user = pub.user_class(name='foo bar')
1490 1497
    user.store()
1491 1498
    account = PasswordAccount(id='test')
......
1494 1501
    assert PasswordAccount.has_key('test')
1495 1502

  
1496 1503
    app = login(get_app(pub))
1497
    resp = app.get('/backoffice/users/2/')
1504
    resp = app.get('/backoffice/users/%s/' % user.id)
1498 1505
    resp = resp.click(href='edit')
1499 1506
    resp.forms[0]['is_admin'].checked = True
1500 1507
    resp.forms[0]['method_password$username'] = 'foo' # change username
1501 1508
    resp.forms[0]['method_password$password'] = 'bar'
1502 1509
    resp = resp.forms[0].submit('submit')
1503
    assert resp.location == 'http://example.net/backoffice/users/2/'
1510
    assert resp.location == 'http://example.net/backoffice/users/%s/' % user.id
1504 1511
    resp = resp.follow()
1505 1512

  
1506 1513
    # makes sure the old account has been removed
......
1508 1515
    assert PasswordAccount.has_key('foo')
1509 1516
    assert PasswordAccount.get('foo').user_id == user.id
1510 1517

  
1511
def test_users_delete():
1518
def test_users_delete(pub):
1512 1519
    pub.user_class.wipe()
1513 1520
    PasswordAccount.wipe()
1514
    create_superuser()
1521
    create_superuser(pub)
1515 1522
    user = pub.user_class(name='foo bar')
1516 1523
    user.store()
1517 1524
    account = PasswordAccount(id='test')
......
1522 1529
    account_count = PasswordAccount.count()
1523 1530

  
1524 1531
    app = login(get_app(pub))
1525
    resp = app.get('/backoffice/users/2/')
1532
    resp = app.get('/backoffice/users/%s/' % user.id)
1526 1533

  
1527 1534
    resp = resp.click(href='delete')
1528 1535
    resp = resp.forms[0].submit()
......
1532 1539
    assert pub.user_class.count() == user_count - 1
1533 1540
    assert PasswordAccount.count() == account_count - 1
1534 1541

  
1535
def test_users_pagination():
1542
def test_users_pagination(pub):
1536 1543
    pub.user_class.wipe()
1537 1544
    PasswordAccount.wipe()
1538
    create_superuser()
1545
    create_superuser(pub)
1539 1546
    for i in range(50):
1540 1547
        user = pub.user_class(name='foo bar %s' % (i+1))
1541 1548
        user.store()
......
1557 1564
    resp = resp.click('Next Page')
1558 1565
    assert 'foo bar 50' in resp.body
1559 1566

  
1560
def test_users_filter():
1567
def test_users_filter(pub):
1561 1568
    pub.user_class.wipe()
1562 1569
    PasswordAccount.wipe()
1563
    create_superuser()
1570
    create_superuser(pub)
1564 1571
    role = create_role()
1565 1572
    for i in range(50):
1566 1573
        user = pub.user_class(name='foo bar %s' % (i+1))
......
1592 1599
    assert 'foo bar 10' not in resp.body # simple user
1593 1600
    assert 'baz bar 1' in resp.body # user with role
1594 1601

  
1595
def test_users_search():
1602
def test_users_search(pub):
1596 1603
    pub.user_class.wipe()
1597 1604
    PasswordAccount.wipe()
1598
    create_superuser()
1605
    create_superuser(pub)
1599 1606
    for i in range(20):
1600 1607
        user = pub.user_class(name='foo %s' % (i+1))
1601 1608
        user.store()
......
1613 1620
    assert 'bar 10' in resp.body
1614 1621
    assert 'Number of filtered users: 10' in resp.body
1615 1622

  
1616
def test_roles():
1623
def test_roles(pub):
1617 1624
    app = login(get_app(pub))
1618 1625
    app.get('/backoffice/roles/')
1619 1626

  
1620
def test_roles_new():
1627
def test_roles_new(pub):
1621 1628
    Role.wipe()
1622 1629
    app = login(get_app(pub))
1623 1630
    resp = app.get('/backoffice/roles/')
......
1634 1641
    assert Role.get(1).name == 'a new role'
1635 1642
    assert Role.get(1).details == 'bla bla bla'
1636 1643

  
1637
def test_roles_edit():
1644
def test_roles_edit(pub):
1638 1645
    Role.wipe()
1639 1646
    role = Role(name='foobar')
1640 1647
    role.store()
......
1657 1664
    assert Role.get(1).details == 'bla bla bla'
1658 1665
    assert Role.get(1).emails_to_members == True
1659 1666

  
1660
def test_roles_matching_formdefs():
1667
def test_roles_matching_formdefs(pub):
1661 1668
    Role.wipe()
1662 1669
    role = Role(name='foo')
1663 1670
    role.store()
......
1670 1677
    formdef = FormDef()
1671 1678
    formdef.name = 'form bar'
1672 1679
    formdef.roles = [role.id]
1680
    formdef.fields = []
1673 1681
    formdef.store()
1674 1682

  
1675 1683
    resp = app.get('/backoffice/roles/1/')
......
1679 1687
    FormDef.wipe()
1680 1688
    formdef = FormDef()
1681 1689
    formdef.name = 'form baz'
1690
    formdef.fields = []
1682 1691
    formdef.workflow_roles = {'_receiver': role.id}
1683 1692
    formdef.store()
1684 1693

  
......
1686 1695
    assert 'form baz' in resp.body
1687 1696
    assert 'form bar' not in resp.body
1688 1697

  
1689
def test_roles_delete():
1698
def test_roles_delete(pub):
1690 1699
    Role.wipe()
1691 1700
    role = Role(name='foobar')
1692 1701
    role.store()
......
1700 1709
    resp = resp.follow()
1701 1710
    assert Role.count() == 0
1702 1711

  
1703
def test_categories():
1712
def test_categories(pub):
1704 1713
    app = login(get_app(pub))
1705 1714
    app.get('/backoffice/categories/')
1706 1715

  
1707
def test_categories_new():
1716
def test_categories_new(pub):
1708 1717
    Category.wipe()
1709 1718
    app = login(get_app(pub))
1710 1719

  
......
1729 1738
    assert Category.get(1).name == 'a new category'
1730 1739
    assert Category.get(1).description == 'description of the category'
1731 1740

  
1732
def test_categories_edit():
1741
def test_categories_edit(pub):
1733 1742
    Category.wipe()
1734 1743
    category = Category(name='foobar')
1735 1744
    category.store()
......
1749 1758

  
1750 1759
    assert Category.get(1).description == 'category description'
1751 1760

  
1752
def test_categories_edit_duplicate_name():
1761
def test_categories_edit_duplicate_name(pub):
1753 1762
    Category.wipe()
1754 1763
    category = Category(name='foobar')
1755 1764
    category.store()
......
1768 1777
    resp = resp.forms[0].submit('cancel')
1769 1778
    assert resp.location == 'http://example.net/backoffice/categories/'
1770 1779

  
1771
def test_categories_with_formdefs():
1780
def test_categories_with_formdefs(pub):
1772 1781
    Category.wipe()
1773 1782
    category = Category(name='foobar')
1774 1783
    category.store()
......
1780 1789

  
1781 1790
    formdef = FormDef()
1782 1791
    formdef.name = 'form bar'
1792
    formdef.fields = []
1783 1793
    formdef.category_id = category.id
1784 1794
    formdef.store()
1785 1795

  
......
1787 1797
    assert 'form bar' in resp.body
1788 1798
    assert 'no form associated to this category' not in resp.body
1789 1799

  
1790
def test_categories_delete():
1800
def test_categories_delete(pub):
1791 1801
    Category.wipe()
1792 1802
    category = Category(name='foobar')
1793 1803
    category.store()
......
1809 1819
    assert Category.count() == 0
1810 1820

  
1811 1821

  
1812
def test_categories_edit_description():
1822
def test_categories_edit_description(pub):
1813 1823
    Category.wipe()
1814 1824
    category = Category(name='foobar')
1815 1825
    category.description = 'category description'
......
1833 1843
    resp2 = resp2.follow()
1834 1844
    assert Category.get(1).description == 'updated description'
1835 1845

  
1836
def test_categories_new_duplicate_name():
1846
def test_categories_new_duplicate_name(pub):
1837 1847
    Category.wipe()
1838 1848
    category = Category(name='foobar')
1839 1849
    category.store()
......
1845 1855
    resp = resp.forms[0].submit('submit')
1846 1856
    assert 'This name is already used' in resp.body
1847 1857

  
1848
def test_categories_reorder():
1858
def test_categories_reorder(pub):
1849 1859
    Category.wipe()
1850 1860
    category = Category(name='foo')
1851 1861
    category.store()
......
1865 1875
    Category.sort_by_position(categories)
1866 1876
    assert [x.id for x in categories] == ['3', '1', '2']
1867 1877

  
1868
def test_settings():
1878
def test_settings(pub):
1869 1879
    app = login(get_app(pub))
1870 1880
    app.get('/backoffice/settings/')
1871 1881

  
......
1881 1891
    app.get('/backoffice/settings/admin-permissions')
1882 1892

  
1883 1893

  
1884
def test_settings_themes():
1885
    create_superuser()
1894
def test_settings_themes(pub):
1895
    create_superuser(pub)
1886 1896
    app = login(get_app(pub))
1887 1897

  
1888 1898
    # create mock theme
......
1913 1923
    assert 'checked' in resp.body
1914 1924
    assert get_current_theme()['name'] == 'test'
1915 1925

  
1916
def test_settings_template():
1917
    create_superuser()
1926
def test_settings_template(pub):
1927
    create_superuser(pub)
1918 1928
    app = login(get_app(pub))
1919 1929
    resp = app.get('/backoffice/settings/template')
1920 1930

  
......
1933 1943
    resp = app.get('/backoffice/settings/template')
1934 1944
    assert resp.forms[0]['template'].value == orig_value
1935 1945

  
1936
def test_settings_user():
1937
    create_superuser()
1946
def test_settings_user(pub):
1947
    user = create_superuser(pub)
1938 1948
    app = login(get_app(pub))
1939 1949
    resp = app.get('/backoffice/settings/users').follow().follow()
1940 1950

  
......
1970 1980
    assert 'barfoo' in resp.body
1971 1981

  
1972 1982
    # check fields are present in edit form
1973
    resp = app.get('/backoffice/users/admin/edit')
1983
    resp = app.get('/backoffice/users/%s/edit' % user.id)
1974 1984
    assert 'barfoo' in resp.body
1975 1985
    assert 'f1' in resp.forms[0].fields
1976 1986
    assert 'email' in resp.forms[0].fields
......
1979 1989
    # field.
1980 1990
    pub.cfg['users']['field_email'] = '1'
1981 1991
    pub.write_cfg()
1982
    resp = app.get('/backoffice/users/admin/edit')
1992
    resp = app.get('/backoffice/users/%s/edit' % user.id)
1983 1993
    assert 'f1' in resp.forms[0].fields
1984 1994
    assert 'email' not in resp.forms[0].fields
1985 1995

  
......
1987 1997
    pub.cfg['users']['field_email'] = None
1988 1998
    pub.write_cfg()
1989 1999

  
1990
def test_settings_emails():
1991
    create_superuser()
2000
def test_settings_emails(pub):
2001
    create_superuser(pub)
1992 2002
    app = login(get_app(pub))
1993 2003

  
1994 2004
    pub.cfg['debug'] = {'mail_redirection': 'foo@example.net'}
......
2018 2028
    resp = resp.forms[0].submit()
2019 2029
    assert pub.cfg['emails']['email-new-account-approved_subject'] is None
2020 2030

  
2021
def test_settings_texts():
2022
    create_superuser()
2031
def test_settings_texts(pub):
2032
    create_superuser(pub)
2023 2033
    app = login(get_app(pub))
2024 2034

  
2025 2035
    resp = app.get('/backoffice/settings/texts/')
......
2036 2046
    assert pub.cfg['texts']['text-top-of-login'] == None
2037 2047

  
2038 2048
@pytest.mark.skipif('lasso is None')
2039
def test_settings_auth():
2049
def test_settings_auth(pub):
2040 2050
    pub.user_class.wipe() # makes sure there are no users
2041 2051
    pub.cfg['identification'] = {}
2042 2052
    pub.write_cfg()
......
2066 2076
    assert pub.cfg['identification']['methods'] == ['password']
2067 2077

  
2068 2078
@pytest.mark.skipif('lasso is None')
2069
def test_settings_idp():
2079
def test_settings_idp(pub):
2070 2080
    pub.user_class.wipe() # makes sure there are no users
2071 2081
    pub.cfg['identification'] = {'methods': ['idp']}
2072 2082
    pub.write_cfg()
......
2102 2112
    resp = resp.forms[0].submit() # confirm delete
2103 2113
    assert len(pub.cfg['idp']) == 0
2104 2114

  
2105
def test_settings_auth_password():
2115
def test_settings_auth_password(pub):
2106 2116
    pub.user_class.wipe() # makes sure there are no users
2107 2117
    pub.cfg['identification'] = {'methods': ['password']}
2108 2118
    assert pub.cfg['identification']['methods'] == ['password']
......
2121 2131
    resp = resp.click('Bulk Import')
2122 2132
    resp = resp.forms[0].submit()
2123 2133

  
2124
def test_settings_filetypes():
2125
    create_superuser()
2134
def test_settings_filetypes(pub):
2135
    create_superuser(pub)
2126 2136
    app = login(get_app(pub))
2127 2137

  
2128 2138
    resp = app.get('/backoffice/settings/filetypes/')
......
2159 2169
    resp = resp.follow()
2160 2170
    assert 'HTML files' not in resp.body
2161 2171

  
2162
def test_settings_filetypes_update():
2163
    create_superuser()
2172
def test_settings_filetypes_update(pub):
2173
    create_superuser(pub)
2164 2174
    app = login(get_app(pub))
2165 2175

  
2166 2176
    pub.cfg['filetypes'] = {
......
2186 2196
    assert 'application/pdf' in pub.cfg['filetypes'][1]['mimetypes']
2187 2197
    assert FormDef.get(formdef.id).fields[0].file_type == ['application/vnd.oasis.opendocument.text,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf']
2188 2198

  
2189
def test_data_sources():
2190
    create_superuser()
2199
def test_data_sources(pub):
2200
    create_superuser(pub)
2191 2201
    app = login(get_app(pub))
2192 2202
    app.get('/backoffice/settings/data-sources/')
2193 2203

  
2194
def test_data_sources_new():
2195
    create_superuser()
2204
def test_data_sources_new(pub):
2205
    create_superuser(pub)
2196 2206
    NamedDataSource.wipe()
2197 2207
    app = login(get_app(pub))
2198 2208

  
......
2223 2233
    assert NamedDataSource.get(1).name == 'a new data source'
2224 2234
    assert NamedDataSource.get(1).description == 'description of the data source'
2225 2235

  
2226
def test_data_sources_edit():
2227
    create_superuser()
2236
def test_data_sources_edit(pub):
2237
    create_superuser(pub)
2228 2238
    NamedDataSource.wipe()
2229 2239
    data_source = NamedDataSource(name='foobar')
2230 2240
    data_source.data_source = {'type': 'formula', 'value': '[]'}
......
2243 2253

  
2244 2254
    assert NamedDataSource.get(1).description == 'data source description'
2245 2255

  
2246
def test_data_sources_edit_duplicate_name():
2247
    create_superuser()
2256
def test_data_sources_edit_duplicate_name(pub):
2257
    create_superuser(pub)
2248 2258
    NamedDataSource.wipe()
2249 2259
    data_source = NamedDataSource(name='foobar')
2250 2260
    data_source.data_source = {'type': 'formula', 'value': '[]'}
......
2264 2274
    resp = resp.forms[0].submit('cancel')
2265 2275
    assert resp.location == 'http://example.net/backoffice/settings/data-sources/'
2266 2276

  
2267
def test_data_sources_delete():
2268
    create_superuser()
2277
def test_data_sources_delete(pub):
2278
    create_superuser(pub)
2269 2279
    NamedDataSource.wipe()
2270 2280
    category = NamedDataSource(name='foobar')
2271 2281
    category.store()
......
2286 2296
    resp = resp.follow()
2287 2297
    assert NamedDataSource.count() == 0
2288 2298

  
2289
def test_settings_permissions():
2290
    create_superuser()
2299
def test_settings_permissions(pub):
2300
    create_superuser(pub)
2291 2301
    role1 = create_role()
2292 2302
    role1.name = 'foobar1'
2293 2303
    role1.store()
tests/test_saml_auth.py
38 38
    pub = create_temporary_pub()
39 39

  
40 40
def setup_environment(pub, idp_number=1):
41
    pub.cfg = {}
41
    if not pub.cfg:
42
        pub.cfg = {}
42 43
    pub.cfg['sp'] = {
43 44
        'saml2_metadata': 'saml2-metadata.xml',
44 45
        'saml2_base_url': 'http://example.net/saml',
45
-