tests: also run admin pages tests with sql enabled (#8315)
This commit is contained in:
parent
59fd4c662b
commit
f22031acf4
|
@ -27,14 +27,15 @@ from wcs.workflows import Workflow, DisplayMessageWorkflowStatusItem
|
|||
from wcs.formdef import FormDef
|
||||
from wcs import fields
|
||||
|
||||
from utilities import get_app, login, create_temporary_pub
|
||||
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
def pytest_generate_tests(metafunc):
|
||||
if 'pub' in metafunc.fixturenames:
|
||||
metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
|
||||
|
||||
global pub
|
||||
|
||||
pub = create_temporary_pub()
|
||||
@pytest.fixture
|
||||
def pub(request):
|
||||
pub = create_temporary_pub(sql_mode=(request.param == 'sql'))
|
||||
|
||||
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
|
||||
pub.set_app_dir(req)
|
||||
|
@ -42,11 +43,16 @@ def setup_module(module):
|
|||
pub.cfg['language'] = {'language': 'en'}
|
||||
pub.write_cfg()
|
||||
|
||||
def create_superuser():
|
||||
if pub.user_class.has_key('admin'):
|
||||
return pub.user_class.get('admin')
|
||||
return pub
|
||||
|
||||
def create_superuser(pub):
|
||||
if pub.user_class.select(lambda x: x.name == 'admin'):
|
||||
user1 = pub.user_class.select(lambda x: x.name == 'admin')[0]
|
||||
user1.is_admin = True
|
||||
user1.store()
|
||||
return user1
|
||||
|
||||
user1 = pub.user_class(name='admin')
|
||||
user1.id = 'admin'
|
||||
user1.is_admin = True
|
||||
user1.store()
|
||||
|
||||
|
@ -55,9 +61,6 @@ def create_superuser():
|
|||
account1.user_id = user1.id
|
||||
account1.store()
|
||||
|
||||
pub.cfg['identification'] = {'methods': ['password']}
|
||||
pub.write_cfg()
|
||||
|
||||
return user1
|
||||
|
||||
def create_role():
|
||||
|
@ -67,32 +70,32 @@ def create_role():
|
|||
return role
|
||||
|
||||
def teardown_module(module):
|
||||
shutil.rmtree(pub.APP_DIR)
|
||||
clean_temporary_pub()
|
||||
|
||||
def test_empty_site():
|
||||
def test_empty_site(pub):
|
||||
resp = get_app(pub).get('/backoffice/')
|
||||
resp = resp.click('Users', index=0)
|
||||
resp = resp.click('New User')
|
||||
resp = get_app(pub).get('/backoffice/')
|
||||
resp = resp.click('Settings', index=0)
|
||||
|
||||
def test_with_user():
|
||||
create_superuser()
|
||||
def test_with_user(pub):
|
||||
create_superuser(pub)
|
||||
resp = get_app(pub).get('/backoffice/', status=302)
|
||||
resp = resp.follow()
|
||||
assert resp.location == 'http://example.net/login/'
|
||||
|
||||
def test_with_superuser():
|
||||
def test_with_superuser(pub):
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/')
|
||||
|
||||
def test_admin_redirect():
|
||||
create_superuser()
|
||||
def test_admin_redirect(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
assert app.get('/admin/whatever', status=302).location == 'http://example.net/backoffice/whatever'
|
||||
|
||||
def test_admin_for_all():
|
||||
user = create_superuser()
|
||||
def test_admin_for_all(pub):
|
||||
user = create_superuser(pub)
|
||||
role = create_role()
|
||||
|
||||
try:
|
||||
|
@ -141,14 +144,15 @@ def test_admin_for_all():
|
|||
user.is_admin = True
|
||||
user.store()
|
||||
|
||||
def test_forms():
|
||||
def test_forms(pub):
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/forms/')
|
||||
assert 'You first have to define roles.' in resp.body
|
||||
assert not 'New Form' in resp.body
|
||||
|
||||
def test_forms_new():
|
||||
def test_forms_new(pub):
|
||||
app = login(get_app(pub))
|
||||
user = create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
# create a new form
|
||||
|
@ -167,15 +171,15 @@ def test_forms_new():
|
|||
assert formdef.url_name == 'form-title'
|
||||
assert formdef.fields == []
|
||||
assert formdef.disabled == True
|
||||
assert formdef.last_modification_user_id == 'admin'
|
||||
assert formdef.last_modification_user_id == str(user.id)
|
||||
|
||||
def assert_option_display(resp, label, value):
|
||||
option_line = re.findall('%s.*%s' % (label, value), resp.body, re.DOTALL)
|
||||
assert option_line
|
||||
assert not '</li>' in option_line
|
||||
|
||||
def test_forms_edit():
|
||||
create_superuser()
|
||||
def test_forms_edit(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -294,8 +298,8 @@ def test_forms_edit():
|
|||
assert FormDef.get(1).name == 'new title'
|
||||
assert FormDef.get(1).url_name == 'new-title'
|
||||
|
||||
def test_form_category():
|
||||
create_superuser()
|
||||
def test_form_category(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -317,8 +321,8 @@ def test_form_category():
|
|||
assert 'Category' in resp.body
|
||||
assert_option_display(resp, 'Category', 'None')
|
||||
|
||||
def test_form_category_select():
|
||||
create_superuser()
|
||||
def test_form_category_select(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -345,8 +349,8 @@ def test_form_category_select():
|
|||
resp = resp.forms[0].submit('submit')
|
||||
assert FormDef.get(formdef.id).category_id == cat.id
|
||||
|
||||
def test_form_workflow():
|
||||
create_superuser()
|
||||
def test_form_workflow(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -368,8 +372,8 @@ def test_form_workflow():
|
|||
resp = app.get('/backoffice/forms/1/')
|
||||
assert_option_display(resp, 'Workflow', 'Default')
|
||||
|
||||
def test_form_workflow_change():
|
||||
create_superuser()
|
||||
def test_form_workflow_change(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -398,8 +402,8 @@ def test_form_workflow_change():
|
|||
resp = resp.forms[0].submit('submit')
|
||||
assert FormDef.get(formdef.id).workflow_id == workflow.id
|
||||
|
||||
def test_form_workflow_remapping():
|
||||
create_superuser()
|
||||
def test_form_workflow_remapping(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -437,8 +441,8 @@ def test_form_workflow_remapping():
|
|||
resp = resp.forms[0].submit()
|
||||
assert data_class.get(1).status == 'wf-finished'
|
||||
|
||||
def test_form_workflow_role():
|
||||
create_superuser()
|
||||
def test_form_workflow_role(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -458,8 +462,8 @@ def test_form_workflow_role():
|
|||
resp = resp.forms[0].submit('submit')
|
||||
assert FormDef.get(1).workflow_roles == {'_receiver': '1'}
|
||||
|
||||
def test_form_workflow_options():
|
||||
create_superuser()
|
||||
def test_form_workflow_options(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
Workflow.wipe()
|
||||
|
@ -478,8 +482,8 @@ def test_form_workflow_options():
|
|||
resp = app.get('/backoffice/forms/1/')
|
||||
assert '"workflow-options"' in resp.body
|
||||
|
||||
def test_form_workflow_variables():
|
||||
create_superuser()
|
||||
def test_form_workflow_variables(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
Workflow.wipe()
|
||||
|
@ -520,8 +524,8 @@ def test_form_workflow_variables():
|
|||
resp = resp.forms[0].submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/forms/1/'
|
||||
|
||||
def test_form_roles():
|
||||
create_superuser()
|
||||
def test_form_roles(pub):
|
||||
create_superuser(pub)
|
||||
role = create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -542,8 +546,8 @@ def test_form_roles():
|
|||
resp = resp.forms[0].submit('submit')
|
||||
assert FormDef.get(1).roles == [role.id]
|
||||
|
||||
def test_form_always_advertise():
|
||||
create_superuser()
|
||||
def test_form_always_advertise(pub):
|
||||
create_superuser(pub)
|
||||
role = create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -569,7 +573,7 @@ def test_form_always_advertise():
|
|||
assert_option_display(resp, 'Display to unlogged users', 'Enabled')
|
||||
assert FormDef.get(1).always_advertise is True
|
||||
|
||||
def test_form_delete():
|
||||
def test_form_delete(pub):
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -587,7 +591,7 @@ def test_form_delete():
|
|||
resp = resp.follow()
|
||||
assert FormDef.count() == 0
|
||||
|
||||
def test_form_duplicate():
|
||||
def test_form_duplicate(pub):
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -612,7 +616,7 @@ def test_form_duplicate():
|
|||
assert FormDef.count() == 3
|
||||
assert FormDef.get(3).name == 'form title (copy 2)'
|
||||
|
||||
def test_form_export():
|
||||
def test_form_export(pub):
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -631,8 +635,8 @@ def test_form_export():
|
|||
formdef2 = FormDef.import_from_xml(fd)
|
||||
assert formdef2.name == 'form title'
|
||||
|
||||
def test_form_import():
|
||||
user = create_superuser()
|
||||
def test_form_import(pub):
|
||||
user = create_superuser(pub)
|
||||
role = create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -662,7 +666,7 @@ def test_form_import():
|
|||
assert FormDef.get(1).url_name == 'form-title'
|
||||
assert FormDef.get(2).url_name == 'form-title-1'
|
||||
|
||||
def test_form_qrcode():
|
||||
def test_form_qrcode(pub):
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -677,8 +681,8 @@ def test_form_qrcode():
|
|||
resp = resp.click(href='qrcode')
|
||||
assert '<div id="qrcode">' in resp.body
|
||||
|
||||
def test_form_description():
|
||||
create_superuser()
|
||||
def test_form_description(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -698,8 +702,8 @@ def test_form_description():
|
|||
resp = resp.follow()
|
||||
assert_option_display(resp, 'Description', 'On')
|
||||
|
||||
def test_form_new_field():
|
||||
create_superuser()
|
||||
def test_form_new_field(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -736,7 +740,7 @@ def test_form_new_field():
|
|||
resp = app.get('/backoffice/forms/1/')
|
||||
assert '<h3>baz</h3>' in resp.body
|
||||
|
||||
def test_form_delete_field():
|
||||
def test_form_delete_field(pub):
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -757,7 +761,7 @@ def test_form_delete_field():
|
|||
resp = resp.follow()
|
||||
assert len(FormDef.get(1).fields) == 0
|
||||
|
||||
def test_form_duplicate_field():
|
||||
def test_form_duplicate_field(pub):
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -778,7 +782,7 @@ def test_form_duplicate_field():
|
|||
assert FormDef.get(1).fields[0].label == '1st field'
|
||||
assert FormDef.get(1).fields[1].label == '1st field'
|
||||
|
||||
def test_form_edit_field():
|
||||
def test_form_edit_field(pub):
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -802,8 +806,8 @@ def test_form_edit_field():
|
|||
assert FormDef.get(1).fields[0].label == 'changed field'
|
||||
assert FormDef.get(1).fields[0].required == False
|
||||
|
||||
def test_form_edit_field_advanced():
|
||||
create_superuser()
|
||||
def test_form_edit_field_advanced(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -858,8 +862,8 @@ def test_form_edit_field_advanced():
|
|||
assert resp.body.index('<legend>Additional parameters</legend>') > \
|
||||
resp.body.index('<label for="form_data_source">Data Source</label>')
|
||||
|
||||
def test_form_legacy_int_id():
|
||||
create_superuser()
|
||||
def test_form_legacy_int_id(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
Category.wipe()
|
||||
|
@ -909,8 +913,8 @@ def test_form_legacy_int_id():
|
|||
resp = resp.click('Recipient')
|
||||
assert resp.forms[0]['role_id'].value == 'ZAB'
|
||||
|
||||
def test_form_anonymise():
|
||||
create_superuser()
|
||||
def test_form_anonymise(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -970,8 +974,8 @@ def test_form_anonymise():
|
|||
assert resp.location == 'http://example.net/backoffice/forms/1/'
|
||||
assert len([x for x in formdef.data_class().select() if x.anonymised]) == 3
|
||||
|
||||
def test_form_public_url():
|
||||
create_superuser()
|
||||
def test_form_public_url(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -985,10 +989,15 @@ def test_form_public_url():
|
|||
resp = resp.click('Display public URL')
|
||||
assert 'http://example.net/form-title/' in resp.body
|
||||
|
||||
def test_form_archive():
|
||||
create_superuser()
|
||||
def test_form_archive(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
if getattr(pub, 'pgconn', None):
|
||||
# this doesn't exist in SQL
|
||||
pytest.skip('no archive in SQL mode')
|
||||
return
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
|
@ -1030,8 +1039,8 @@ def test_form_archive():
|
|||
assert 'formdef' in [x.name for x in tf.getmembers()]
|
||||
assert len(tf.getmembers()) == 1 # 0 formdata + 1 formdef
|
||||
|
||||
def test_form_overwrite():
|
||||
user = create_superuser()
|
||||
def test_form_overwrite(pub):
|
||||
user = create_superuser(pub)
|
||||
role = create_role()
|
||||
|
||||
FormDef.wipe()
|
||||
|
@ -1104,11 +1113,11 @@ def test_form_overwrite():
|
|||
assert FormDef.get(formdef_id).url_name == 'form-test'
|
||||
assert FormDef.get(formdef_id).table_name == 'xxx'
|
||||
|
||||
def test_workflows():
|
||||
def test_workflows(pub):
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/workflows/')
|
||||
|
||||
def test_workflows_default():
|
||||
def test_workflows_default(pub):
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
assert 'Default' in resp.body
|
||||
|
@ -1124,7 +1133,7 @@ def test_workflows_default():
|
|||
assert 'Change Status Name' not in resp.body
|
||||
assert 'Delete' not in resp.body
|
||||
|
||||
def test_workflows_new():
|
||||
def test_workflows_new(pub):
|
||||
Workflow.wipe()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
|
@ -1166,7 +1175,7 @@ def test_workflows_new():
|
|||
assert wf.possible_status[0].name == 'new status'
|
||||
assert wf.possible_status[0].items[0].message == 'bla bla bla'
|
||||
|
||||
def test_workflows_edit():
|
||||
def test_workflows_edit(pub):
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='foo')
|
||||
workflow.store()
|
||||
|
@ -1181,7 +1190,7 @@ def test_workflows_edit():
|
|||
resp = resp.follow()
|
||||
assert 'baz' in resp.body
|
||||
|
||||
def test_workflows_edit_status():
|
||||
def test_workflows_edit_status(pub):
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='foo')
|
||||
workflow.add_status(name='baz')
|
||||
|
@ -1228,7 +1237,7 @@ def test_workflows_edit_status():
|
|||
resp = resp.follow()
|
||||
assert Workflow.get(1).possible_status[0].backoffice_info_text == '<p>Hello</p>'
|
||||
|
||||
def test_workflows_delete():
|
||||
def test_workflows_delete(pub):
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='foo')
|
||||
workflow.store()
|
||||
|
@ -1242,7 +1251,7 @@ def test_workflows_delete():
|
|||
resp = resp.follow()
|
||||
assert Workflow.count() == 0
|
||||
|
||||
def test_workflows_add_all_actions():
|
||||
def test_workflows_add_all_actions(pub):
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='foo')
|
||||
workflow.add_status(name='baz')
|
||||
|
@ -1263,8 +1272,8 @@ def test_workflows_add_all_actions():
|
|||
resp = resp.follow() # redirect to items/
|
||||
resp = resp.follow() # redirect to ./
|
||||
|
||||
def test_workflows_variables():
|
||||
create_superuser()
|
||||
def test_workflows_variables(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
Workflow.wipe()
|
||||
|
@ -1293,8 +1302,8 @@ def test_workflows_variables():
|
|||
assert Workflow.get(1).variables_formdef.fields[0].key == 'string'
|
||||
assert Workflow.get(1).variables_formdef.fields[0].label == 'foobar'
|
||||
|
||||
def test_workflows_variables_edit():
|
||||
test_workflows_variables()
|
||||
def test_workflows_variables_edit(pub):
|
||||
test_workflows_variables(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/1/')
|
||||
|
@ -1321,8 +1330,8 @@ def test_workflows_variables_edit():
|
|||
assert Workflow.get(1).variables_formdef.fields[0].key == 'string'
|
||||
assert Workflow.get(1).variables_formdef.fields[0].varname == '1*1*message'
|
||||
|
||||
def test_workflows_functions():
|
||||
create_superuser()
|
||||
def test_workflows_functions(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
Workflow.wipe()
|
||||
|
@ -1365,8 +1374,8 @@ def test_workflows_functions():
|
|||
resp = resp.click('Recipient')
|
||||
assert not 'delete' in resp.forms[0].fields
|
||||
|
||||
def test_workflows_functions_vs_visibility():
|
||||
create_superuser()
|
||||
def test_workflows_functions_vs_visibility(pub):
|
||||
create_superuser(pub)
|
||||
create_role()
|
||||
|
||||
Workflow.wipe()
|
||||
|
@ -1403,14 +1412,14 @@ def test_workflows_functions_vs_visibility():
|
|||
assert set(Workflow.get(workflow.id).possible_status[2].visibility) == set(
|
||||
['_receiver', '_other-function'])
|
||||
|
||||
def test_users():
|
||||
create_superuser()
|
||||
def test_users(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/users/')
|
||||
|
||||
def test_users_new():
|
||||
def test_users_new(pub):
|
||||
pub.user_class.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
user_count = pub.user_class.count()
|
||||
account_count = PasswordAccount.count()
|
||||
app = login(get_app(pub))
|
||||
|
@ -1426,9 +1435,9 @@ def test_users_new():
|
|||
assert pub.user_class.count() == user_count + 1
|
||||
assert PasswordAccount.count() == account_count
|
||||
|
||||
def test_users_new_with_account():
|
||||
def test_users_new_with_account(pub):
|
||||
pub.user_class.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
user_count = pub.user_class.count()
|
||||
account_count = PasswordAccount.count()
|
||||
app = login(get_app(pub))
|
||||
|
@ -1446,46 +1455,44 @@ def test_users_new_with_account():
|
|||
assert pub.user_class.count() == user_count + 1
|
||||
assert PasswordAccount.count() == account_count + 1
|
||||
|
||||
def test_users_edit():
|
||||
def test_users_edit(pub):
|
||||
pub.user_class.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
user = pub.user_class(name='foo bar')
|
||||
user.store()
|
||||
assert user.id == '2'
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/users/2/')
|
||||
resp = app.get('/backoffice/users/%s/' % user.id)
|
||||
resp = resp.click(href='edit')
|
||||
resp.forms[0]['is_admin'].checked = True
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/users/2/'
|
||||
assert resp.location == 'http://example.net/backoffice/users/%s/' % user.id
|
||||
resp = resp.follow()
|
||||
|
||||
def test_users_edit_new_account():
|
||||
def test_users_edit_new_account(pub):
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
user = pub.user_class(name='foo bar')
|
||||
user.store()
|
||||
assert user.id == '2'
|
||||
account_count = PasswordAccount.count()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/users/2/')
|
||||
resp = app.get('/backoffice/users/%s/' % user.id)
|
||||
resp = resp.click(href='edit')
|
||||
resp.forms[0]['is_admin'].checked = True
|
||||
resp.forms[0]['method_password$username'] = 'foo'
|
||||
resp.forms[0]['method_password$password'] = 'bar'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/users/2/'
|
||||
assert resp.location == 'http://example.net/backoffice/users/%s/' % user.id
|
||||
resp = resp.follow()
|
||||
|
||||
assert PasswordAccount.count() == account_count + 1
|
||||
|
||||
def test_users_edit_edit_account():
|
||||
def test_users_edit_edit_account(pub):
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
user = pub.user_class(name='foo bar')
|
||||
user.store()
|
||||
account = PasswordAccount(id='test')
|
||||
|
@ -1494,13 +1501,13 @@ def test_users_edit_edit_account():
|
|||
assert PasswordAccount.has_key('test')
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/users/2/')
|
||||
resp = app.get('/backoffice/users/%s/' % user.id)
|
||||
resp = resp.click(href='edit')
|
||||
resp.forms[0]['is_admin'].checked = True
|
||||
resp.forms[0]['method_password$username'] = 'foo' # change username
|
||||
resp.forms[0]['method_password$password'] = 'bar'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert resp.location == 'http://example.net/backoffice/users/2/'
|
||||
assert resp.location == 'http://example.net/backoffice/users/%s/' % user.id
|
||||
resp = resp.follow()
|
||||
|
||||
# makes sure the old account has been removed
|
||||
|
@ -1508,10 +1515,10 @@ def test_users_edit_edit_account():
|
|||
assert PasswordAccount.has_key('foo')
|
||||
assert PasswordAccount.get('foo').user_id == user.id
|
||||
|
||||
def test_users_delete():
|
||||
def test_users_delete(pub):
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
user = pub.user_class(name='foo bar')
|
||||
user.store()
|
||||
account = PasswordAccount(id='test')
|
||||
|
@ -1522,7 +1529,7 @@ def test_users_delete():
|
|||
account_count = PasswordAccount.count()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/users/2/')
|
||||
resp = app.get('/backoffice/users/%s/' % user.id)
|
||||
|
||||
resp = resp.click(href='delete')
|
||||
resp = resp.forms[0].submit()
|
||||
|
@ -1532,10 +1539,10 @@ def test_users_delete():
|
|||
assert pub.user_class.count() == user_count - 1
|
||||
assert PasswordAccount.count() == account_count - 1
|
||||
|
||||
def test_users_pagination():
|
||||
def test_users_pagination(pub):
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
for i in range(50):
|
||||
user = pub.user_class(name='foo bar %s' % (i+1))
|
||||
user.store()
|
||||
|
@ -1557,10 +1564,10 @@ def test_users_pagination():
|
|||
resp = resp.click('Next Page')
|
||||
assert 'foo bar 50' in resp.body
|
||||
|
||||
def test_users_filter():
|
||||
def test_users_filter(pub):
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
role = create_role()
|
||||
for i in range(50):
|
||||
user = pub.user_class(name='foo bar %s' % (i+1))
|
||||
|
@ -1592,10 +1599,10 @@ def test_users_filter():
|
|||
assert 'foo bar 10' not in resp.body # simple user
|
||||
assert 'baz bar 1' in resp.body # user with role
|
||||
|
||||
def test_users_search():
|
||||
def test_users_search(pub):
|
||||
pub.user_class.wipe()
|
||||
PasswordAccount.wipe()
|
||||
create_superuser()
|
||||
create_superuser(pub)
|
||||
for i in range(20):
|
||||
user = pub.user_class(name='foo %s' % (i+1))
|
||||
user.store()
|
||||
|
@ -1613,11 +1620,11 @@ def test_users_search():
|
|||
assert 'bar 10' in resp.body
|
||||
assert 'Number of filtered users: 10' in resp.body
|
||||
|
||||
def test_roles():
|
||||
def test_roles(pub):
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/roles/')
|
||||
|
||||
def test_roles_new():
|
||||
def test_roles_new(pub):
|
||||
Role.wipe()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/roles/')
|
||||
|
@ -1634,7 +1641,7 @@ def test_roles_new():
|
|||
assert Role.get(1).name == 'a new role'
|
||||
assert Role.get(1).details == 'bla bla bla'
|
||||
|
||||
def test_roles_edit():
|
||||
def test_roles_edit(pub):
|
||||
Role.wipe()
|
||||
role = Role(name='foobar')
|
||||
role.store()
|
||||
|
@ -1657,7 +1664,7 @@ def test_roles_edit():
|
|||
assert Role.get(1).details == 'bla bla bla'
|
||||
assert Role.get(1).emails_to_members == True
|
||||
|
||||
def test_roles_matching_formdefs():
|
||||
def test_roles_matching_formdefs(pub):
|
||||
Role.wipe()
|
||||
role = Role(name='foo')
|
||||
role.store()
|
||||
|
@ -1670,6 +1677,7 @@ def test_roles_matching_formdefs():
|
|||
formdef = FormDef()
|
||||
formdef.name = 'form bar'
|
||||
formdef.roles = [role.id]
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
resp = app.get('/backoffice/roles/1/')
|
||||
|
@ -1679,6 +1687,7 @@ def test_roles_matching_formdefs():
|
|||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form baz'
|
||||
formdef.fields = []
|
||||
formdef.workflow_roles = {'_receiver': role.id}
|
||||
formdef.store()
|
||||
|
||||
|
@ -1686,7 +1695,7 @@ def test_roles_matching_formdefs():
|
|||
assert 'form baz' in resp.body
|
||||
assert 'form bar' not in resp.body
|
||||
|
||||
def test_roles_delete():
|
||||
def test_roles_delete(pub):
|
||||
Role.wipe()
|
||||
role = Role(name='foobar')
|
||||
role.store()
|
||||
|
@ -1700,11 +1709,11 @@ def test_roles_delete():
|
|||
resp = resp.follow()
|
||||
assert Role.count() == 0
|
||||
|
||||
def test_categories():
|
||||
def test_categories(pub):
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/categories/')
|
||||
|
||||
def test_categories_new():
|
||||
def test_categories_new(pub):
|
||||
Category.wipe()
|
||||
app = login(get_app(pub))
|
||||
|
||||
|
@ -1729,7 +1738,7 @@ def test_categories_new():
|
|||
assert Category.get(1).name == 'a new category'
|
||||
assert Category.get(1).description == 'description of the category'
|
||||
|
||||
def test_categories_edit():
|
||||
def test_categories_edit(pub):
|
||||
Category.wipe()
|
||||
category = Category(name='foobar')
|
||||
category.store()
|
||||
|
@ -1749,7 +1758,7 @@ def test_categories_edit():
|
|||
|
||||
assert Category.get(1).description == 'category description'
|
||||
|
||||
def test_categories_edit_duplicate_name():
|
||||
def test_categories_edit_duplicate_name(pub):
|
||||
Category.wipe()
|
||||
category = Category(name='foobar')
|
||||
category.store()
|
||||
|
@ -1768,7 +1777,7 @@ def test_categories_edit_duplicate_name():
|
|||
resp = resp.forms[0].submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/categories/'
|
||||
|
||||
def test_categories_with_formdefs():
|
||||
def test_categories_with_formdefs(pub):
|
||||
Category.wipe()
|
||||
category = Category(name='foobar')
|
||||
category.store()
|
||||
|
@ -1780,6 +1789,7 @@ def test_categories_with_formdefs():
|
|||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form bar'
|
||||
formdef.fields = []
|
||||
formdef.category_id = category.id
|
||||
formdef.store()
|
||||
|
||||
|
@ -1787,7 +1797,7 @@ def test_categories_with_formdefs():
|
|||
assert 'form bar' in resp.body
|
||||
assert 'no form associated to this category' not in resp.body
|
||||
|
||||
def test_categories_delete():
|
||||
def test_categories_delete(pub):
|
||||
Category.wipe()
|
||||
category = Category(name='foobar')
|
||||
category.store()
|
||||
|
@ -1809,7 +1819,7 @@ def test_categories_delete():
|
|||
assert Category.count() == 0
|
||||
|
||||
|
||||
def test_categories_edit_description():
|
||||
def test_categories_edit_description(pub):
|
||||
Category.wipe()
|
||||
category = Category(name='foobar')
|
||||
category.description = 'category description'
|
||||
|
@ -1833,7 +1843,7 @@ def test_categories_edit_description():
|
|||
resp2 = resp2.follow()
|
||||
assert Category.get(1).description == 'updated description'
|
||||
|
||||
def test_categories_new_duplicate_name():
|
||||
def test_categories_new_duplicate_name(pub):
|
||||
Category.wipe()
|
||||
category = Category(name='foobar')
|
||||
category.store()
|
||||
|
@ -1845,7 +1855,7 @@ def test_categories_new_duplicate_name():
|
|||
resp = resp.forms[0].submit('submit')
|
||||
assert 'This name is already used' in resp.body
|
||||
|
||||
def test_categories_reorder():
|
||||
def test_categories_reorder(pub):
|
||||
Category.wipe()
|
||||
category = Category(name='foo')
|
||||
category.store()
|
||||
|
@ -1865,7 +1875,7 @@ def test_categories_reorder():
|
|||
Category.sort_by_position(categories)
|
||||
assert [x.id for x in categories] == ['3', '1', '2']
|
||||
|
||||
def test_settings():
|
||||
def test_settings(pub):
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/settings/')
|
||||
|
||||
|
@ -1881,8 +1891,8 @@ def test_settings():
|
|||
app.get('/backoffice/settings/admin-permissions')
|
||||
|
||||
|
||||
def test_settings_themes():
|
||||
create_superuser()
|
||||
def test_settings_themes(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
||||
# create mock theme
|
||||
|
@ -1913,8 +1923,8 @@ def test_settings_themes():
|
|||
assert 'checked' in resp.body
|
||||
assert get_current_theme()['name'] == 'test'
|
||||
|
||||
def test_settings_template():
|
||||
create_superuser()
|
||||
def test_settings_template(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/settings/template')
|
||||
|
||||
|
@ -1933,8 +1943,8 @@ def test_settings_template():
|
|||
resp = app.get('/backoffice/settings/template')
|
||||
assert resp.forms[0]['template'].value == orig_value
|
||||
|
||||
def test_settings_user():
|
||||
create_superuser()
|
||||
def test_settings_user(pub):
|
||||
user = create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/settings/users').follow().follow()
|
||||
|
||||
|
@ -1970,7 +1980,7 @@ def test_settings_user():
|
|||
assert 'barfoo' in resp.body
|
||||
|
||||
# check fields are present in edit form
|
||||
resp = app.get('/backoffice/users/admin/edit')
|
||||
resp = app.get('/backoffice/users/%s/edit' % user.id)
|
||||
assert 'barfoo' in resp.body
|
||||
assert 'f1' in resp.forms[0].fields
|
||||
assert 'email' in resp.forms[0].fields
|
||||
|
@ -1979,7 +1989,7 @@ def test_settings_user():
|
|||
# field.
|
||||
pub.cfg['users']['field_email'] = '1'
|
||||
pub.write_cfg()
|
||||
resp = app.get('/backoffice/users/admin/edit')
|
||||
resp = app.get('/backoffice/users/%s/edit' % user.id)
|
||||
assert 'f1' in resp.forms[0].fields
|
||||
assert 'email' not in resp.forms[0].fields
|
||||
|
||||
|
@ -1987,8 +1997,8 @@ def test_settings_user():
|
|||
pub.cfg['users']['field_email'] = None
|
||||
pub.write_cfg()
|
||||
|
||||
def test_settings_emails():
|
||||
create_superuser()
|
||||
def test_settings_emails(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
||||
pub.cfg['debug'] = {'mail_redirection': 'foo@example.net'}
|
||||
|
@ -2018,8 +2028,8 @@ def test_settings_emails():
|
|||
resp = resp.forms[0].submit()
|
||||
assert pub.cfg['emails']['email-new-account-approved_subject'] is None
|
||||
|
||||
def test_settings_texts():
|
||||
create_superuser()
|
||||
def test_settings_texts(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get('/backoffice/settings/texts/')
|
||||
|
@ -2036,7 +2046,7 @@ def test_settings_texts():
|
|||
assert pub.cfg['texts']['text-top-of-login'] == None
|
||||
|
||||
@pytest.mark.skipif('lasso is None')
|
||||
def test_settings_auth():
|
||||
def test_settings_auth(pub):
|
||||
pub.user_class.wipe() # makes sure there are no users
|
||||
pub.cfg['identification'] = {}
|
||||
pub.write_cfg()
|
||||
|
@ -2066,7 +2076,7 @@ def test_settings_auth():
|
|||
assert pub.cfg['identification']['methods'] == ['password']
|
||||
|
||||
@pytest.mark.skipif('lasso is None')
|
||||
def test_settings_idp():
|
||||
def test_settings_idp(pub):
|
||||
pub.user_class.wipe() # makes sure there are no users
|
||||
pub.cfg['identification'] = {'methods': ['idp']}
|
||||
pub.write_cfg()
|
||||
|
@ -2102,7 +2112,7 @@ def test_settings_idp():
|
|||
resp = resp.forms[0].submit() # confirm delete
|
||||
assert len(pub.cfg['idp']) == 0
|
||||
|
||||
def test_settings_auth_password():
|
||||
def test_settings_auth_password(pub):
|
||||
pub.user_class.wipe() # makes sure there are no users
|
||||
pub.cfg['identification'] = {'methods': ['password']}
|
||||
assert pub.cfg['identification']['methods'] == ['password']
|
||||
|
@ -2121,8 +2131,8 @@ def test_settings_auth_password():
|
|||
resp = resp.click('Bulk Import')
|
||||
resp = resp.forms[0].submit()
|
||||
|
||||
def test_settings_filetypes():
|
||||
create_superuser()
|
||||
def test_settings_filetypes(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
||||
resp = app.get('/backoffice/settings/filetypes/')
|
||||
|
@ -2159,8 +2169,8 @@ def test_settings_filetypes():
|
|||
resp = resp.follow()
|
||||
assert 'HTML files' not in resp.body
|
||||
|
||||
def test_settings_filetypes_update():
|
||||
create_superuser()
|
||||
def test_settings_filetypes_update(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
||||
pub.cfg['filetypes'] = {
|
||||
|
@ -2186,13 +2196,13 @@ def test_settings_filetypes_update():
|
|||
assert 'application/pdf' in pub.cfg['filetypes'][1]['mimetypes']
|
||||
assert FormDef.get(formdef.id).fields[0].file_type == ['application/vnd.oasis.opendocument.text,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf']
|
||||
|
||||
def test_data_sources():
|
||||
create_superuser()
|
||||
def test_data_sources(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/settings/data-sources/')
|
||||
|
||||
def test_data_sources_new():
|
||||
create_superuser()
|
||||
def test_data_sources_new(pub):
|
||||
create_superuser(pub)
|
||||
NamedDataSource.wipe()
|
||||
app = login(get_app(pub))
|
||||
|
||||
|
@ -2223,8 +2233,8 @@ def test_data_sources_new():
|
|||
assert NamedDataSource.get(1).name == 'a new data source'
|
||||
assert NamedDataSource.get(1).description == 'description of the data source'
|
||||
|
||||
def test_data_sources_edit():
|
||||
create_superuser()
|
||||
def test_data_sources_edit(pub):
|
||||
create_superuser(pub)
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foobar')
|
||||
data_source.data_source = {'type': 'formula', 'value': '[]'}
|
||||
|
@ -2243,8 +2253,8 @@ def test_data_sources_edit():
|
|||
|
||||
assert NamedDataSource.get(1).description == 'data source description'
|
||||
|
||||
def test_data_sources_edit_duplicate_name():
|
||||
create_superuser()
|
||||
def test_data_sources_edit_duplicate_name(pub):
|
||||
create_superuser(pub)
|
||||
NamedDataSource.wipe()
|
||||
data_source = NamedDataSource(name='foobar')
|
||||
data_source.data_source = {'type': 'formula', 'value': '[]'}
|
||||
|
@ -2264,8 +2274,8 @@ def test_data_sources_edit_duplicate_name():
|
|||
resp = resp.forms[0].submit('cancel')
|
||||
assert resp.location == 'http://example.net/backoffice/settings/data-sources/'
|
||||
|
||||
def test_data_sources_delete():
|
||||
create_superuser()
|
||||
def test_data_sources_delete(pub):
|
||||
create_superuser(pub)
|
||||
NamedDataSource.wipe()
|
||||
category = NamedDataSource(name='foobar')
|
||||
category.store()
|
||||
|
@ -2286,8 +2296,8 @@ def test_data_sources_delete():
|
|||
resp = resp.follow()
|
||||
assert NamedDataSource.count() == 0
|
||||
|
||||
def test_settings_permissions():
|
||||
create_superuser()
|
||||
def test_settings_permissions(pub):
|
||||
create_superuser(pub)
|
||||
role1 = create_role()
|
||||
role1.name = 'foobar1'
|
||||
role1.store()
|
||||
|
|
|
@ -38,7 +38,8 @@ def setup_module(module):
|
|||
pub = create_temporary_pub()
|
||||
|
||||
def setup_environment(pub, idp_number=1):
|
||||
pub.cfg = {}
|
||||
if not pub.cfg:
|
||||
pub.cfg = {}
|
||||
pub.cfg['sp'] = {
|
||||
'saml2_metadata': 'saml2-metadata.xml',
|
||||
'saml2_base_url': 'http://example.net/saml',
|
||||
|
|
Loading…
Reference in New Issue