diff --git a/doc/scripts/rst2latex.py b/doc/scripts/rst2latex.py
index 4036fbfce..468580576 100755
--- a/doc/scripts/rst2latex.py
+++ b/doc/scripts/rst2latex.py
@@ -10,6 +10,7 @@ except:
from docutils.core import publish_cmdline, Publisher
+
def set_io(self, source_path=None, destination_path=None):
Publisher.set_io_orig(self, source_path, destination_path='/dev/null')
diff --git a/setup.py b/setup.py
index e4a8ff60b..9af47e08f 100644
--- a/setup.py
+++ b/setup.py
@@ -75,6 +75,7 @@ def data_tree(destdir, sourcedir):
dirs.remove(vcs_dirname)
return r
+
def get_version():
'''Use the VERSION, if absent generates a version with git describe, if not
tag exists, take 0.0- and add the length of the commit log.
diff --git a/tests/conftest.py b/tests/conftest.py
index 9e076a26d..aa6ff50a3 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -5,6 +5,7 @@ import pytest
from utilities import EmailsMocking, SMSMocking, HttpRequestsMocking
+
def pytest_addoption(parser):
parser.addoption('--without-postgresql-tests', action='store_true',
help='disable tests requiring postgresql')
diff --git a/tests/robot/WcsRobotFrameworkLibrary.py b/tests/robot/WcsRobotFrameworkLibrary.py
index 86ffa0ad0..ec280e16f 100644
--- a/tests/robot/WcsRobotFrameworkLibrary.py
+++ b/tests/robot/WcsRobotFrameworkLibrary.py
@@ -31,6 +31,7 @@ from robot.libraries.BuiltIn import BuiltIn
from Selenium2Library.locators import ElementFinder as BaseElementFinder
from Selenium2Library import utils
+
class ElementFinder(BaseElementFinder):
def __init__(self):
BaseElementFinder.__init__(self)
@@ -48,6 +49,7 @@ class ElementFinder(BaseElementFinder):
return self._find_by_xpath(browser, criteria, tag, constraints)
return []
+
class WcsRobotFrameworkLibrary:
def __init__(self, port=10003):
self.port = port
diff --git a/tests/test_admin_pages.py b/tests/test_admin_pages.py
index 163e77791..85f60c414 100644
--- a/tests/test_admin_pages.py
+++ b/tests/test_admin_pages.py
@@ -51,10 +51,12 @@ from wcs import fields
from utilities import get_app, login, create_temporary_pub, clean_temporary_pub, HttpRequestsMocking
+
def pytest_generate_tests(metafunc):
if 'pub' in metafunc.fixturenames:
metafunc.parametrize('pub', ['pickle', 'sql', 'pickle-templates'], indirect=True)
+
@pytest.fixture
def pub(request):
pub = create_temporary_pub(
@@ -70,6 +72,7 @@ def pub(request):
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]
@@ -88,15 +91,18 @@ def create_superuser(pub):
return user1
+
def create_role():
Role.wipe()
role = Role(name='foobar')
role.store()
return role
+
def teardown_module(module):
clean_temporary_pub()
+
def test_empty_site(pub):
resp = get_app(pub).get('/backoffice/')
resp = resp.click('Users', index=0)
@@ -104,27 +110,32 @@ def test_empty_site(pub):
resp = get_app(pub).get('/backoffice/')
resp = resp.click('Settings', index=0)
+
def test_empty_site_but_idp_settings(pub):
pub.cfg['idp'] = {'xxx': {}}
pub.write_cfg()
resp = get_app(pub).get('/backoffice/')
assert resp.location == 'http://example.net/login/?next=http%3A%2F%2Fexample.net%2Fbackoffice%2F'
+
def test_with_user(pub):
create_superuser(pub)
resp = get_app(pub).get('/backoffice/', status=302)
assert resp.location == 'http://example.net/login/?next=http%3A%2F%2Fexample.net%2Fbackoffice%2F'
+
def test_with_superuser(pub):
create_superuser(pub)
app = login(get_app(pub))
app.get('/backoffice/')
+
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(pub):
user = create_superuser(pub)
role = create_role()
@@ -177,6 +188,7 @@ def test_admin_for_all(pub):
user.is_admin = True
user.store()
+
def test_forms(pub):
user = create_superuser(pub)
app = login(get_app(pub))
@@ -184,6 +196,7 @@ def test_forms(pub):
assert 'You first have to define roles.' in resp.text
assert not 'New Form' in resp.text
+
def test_forms_new(pub):
user = create_superuser(pub)
app = login(get_app(pub))
@@ -207,6 +220,7 @@ def test_forms_new(pub):
assert formdef.disabled == True
assert formdef.last_modification_user_id == str(user.id)
+
def test_forms_new_popup(pub):
FormDef.wipe()
user = create_superuser(pub)
@@ -232,11 +246,13 @@ def test_forms_new_popup(pub):
assert formdef.disabled == True
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.text, re.DOTALL)
assert option_line
assert not '' in option_line
+
def test_forms_edit(pub):
create_superuser(pub)
create_role()
@@ -364,6 +380,7 @@ def test_forms_edit(pub):
assert_option_display(resp, 'Geolocation', 'Disabled')
assert FormDef.get(formdef.id).geolocations is None
+
def test_form_title_change(pub):
create_superuser(pub)
create_role()
@@ -416,6 +433,7 @@ def test_form_title_change(pub):
resp = resp.form.submit().follow()
assert FormDef.get(formdef2.id).url_name == 'foobar'
+
def test_form_category(pub):
create_superuser(pub)
create_role()
@@ -439,6 +457,7 @@ def test_form_category(pub):
assert 'Category' in resp.text
assert_option_display(resp, 'Category', 'None')
+
def test_form_category_select(pub):
create_superuser(pub)
create_role()
@@ -467,6 +486,7 @@ def test_form_category_select(pub):
resp = resp.forms[0].submit('submit')
assert FormDef.get(formdef.id).category_id == cat.id
+
def test_form_workflow(pub):
create_superuser(pub)
create_role()
@@ -490,6 +510,7 @@ def test_form_workflow(pub):
resp = app.get('/backoffice/forms/1/')
assert_option_display(resp, 'Workflow', 'Default')
+
def test_form_workflow_change(pub):
create_superuser(pub)
create_role()
@@ -520,6 +541,7 @@ def test_form_workflow_change(pub):
resp = resp.forms[0].submit('submit')
assert FormDef.get(formdef.id).workflow_id == workflow.id
+
def test_form_workflow_link(pub):
create_superuser(pub)
create_role()
@@ -551,6 +573,7 @@ def test_form_workflow_link(pub):
resp = app.get('/backoffice/forms/%s/' % formdef.id)
assert '../workflows/%s/' % workflow.id not in resp.text
+
def test_form_workflow_remapping(pub):
create_superuser(pub)
create_role()
@@ -616,6 +639,7 @@ def test_form_workflow_remapping(pub):
assert data_class.get(formdata1.id).status == 'wf-finished'
assert data_class.get(formdata2.id).status == 'draft'
+
def test_form_submitter_roles(pub):
create_superuser(pub)
role = create_role()
@@ -661,6 +685,7 @@ def test_form_submitter_roles(pub):
with pytest.raises(ValueError):
resp.form['roles$element0'] = str(role2.id)
+
def test_form_workflow_role(pub):
create_superuser(pub)
role = create_role()
@@ -688,6 +713,7 @@ def test_form_workflow_role(pub):
resp = app.get('/backoffice/forms/1/')
resp = resp.click(href='role/_receiver')
+
def test_form_workflow_options(pub):
create_superuser(pub)
create_role()
@@ -708,6 +734,7 @@ def test_form_workflow_options(pub):
resp = app.get('/backoffice/forms/1/')
assert '"workflow-options"' in resp.text
+
def test_form_workflow_variables(pub):
create_superuser(pub)
create_role()
@@ -761,6 +788,7 @@ def test_form_workflow_variables(pub):
resp = resp.form.submit()
assert time.strftime('%d %m %y', FormDef.get(formdef.id).workflow_options.get('test2')) == '17 06 16'
+
def test_form_workflow_table_variables(pub):
create_superuser(pub)
create_role()
@@ -807,6 +835,7 @@ def test_form_workflow_table_variables(pub):
assert resp.form['f1$element0$col0'].value == 'foobar'
assert resp.form['f2'].value == 'foobar'
+
def test_form_roles(pub):
create_superuser(pub)
role = create_role()
@@ -829,6 +858,7 @@ def test_form_roles(pub):
resp = resp.forms[0].submit('submit')
assert FormDef.get(1).roles == [role.id]
+
def test_form_always_advertise(pub):
create_superuser(pub)
role = create_role()
@@ -856,6 +886,7 @@ def test_form_always_advertise(pub):
assert_option_display(resp, 'Display to unlogged users', 'Enabled')
assert FormDef.get(1).always_advertise is True
+
def test_form_digest_template(pub):
create_superuser(pub)
role = create_role()
@@ -890,6 +921,7 @@ def test_form_digest_template(pub):
# to wait to check the digest has been updated:
assert formdef.data_class().get(formdata.id).digest == 'XhelloY'
+
def test_form_delete(pub):
create_superuser(pub)
create_role()
@@ -909,6 +941,7 @@ def test_form_delete(pub):
resp = resp.follow()
assert FormDef.count() == 0
+
def test_form_duplicate(pub):
create_superuser(pub)
create_role()
@@ -935,6 +968,7 @@ def test_form_duplicate(pub):
assert FormDef.count() == 3
assert FormDef.get(3).name == 'form title (copy 2)'
+
def test_form_export(pub):
create_superuser(pub)
create_role()
@@ -955,6 +989,7 @@ def test_form_export(pub):
formdef2 = FormDef.import_from_xml(fd)
assert formdef2.name == 'form title'
+
def test_form_import(pub):
user = create_superuser(pub)
role = create_role()
@@ -1026,6 +1061,7 @@ def test_form_import(pub):
assert FormDef.get(1).fields[0].id == '1'
assert FormDef.get(1).fields[1].id == '2'
+
def test_form_qrcode(pub):
create_superuser(pub)
create_role()
@@ -1042,6 +1078,7 @@ def test_form_qrcode(pub):
resp = resp.click(href='qrcode')
assert '
' in resp.text
+
def test_form_description(pub):
create_superuser(pub)
create_role()
@@ -1063,6 +1100,7 @@ def test_form_description(pub):
resp = resp.follow()
assert_option_display(resp, 'Description', 'On')
+
def test_form_new_field(pub):
create_superuser(pub)
create_role()
@@ -1101,6 +1139,7 @@ def test_form_new_field(pub):
resp = app.get('/backoffice/forms/1/')
assert '
baz
' in resp.text
+
def test_form_delete_field(pub):
create_superuser(pub)
create_role()
@@ -1126,6 +1165,7 @@ def test_form_delete_field(pub):
resp = resp.follow()
assert len(FormDef.get(1).fields) == 0
+
def test_form_delete_field_existing_data(pub):
create_superuser(pub)
create_role()
@@ -1188,6 +1228,7 @@ def test_form_duplicate_field(pub):
assert FormDef.get(1).fields[0].label == '1st field'
assert FormDef.get(1).fields[1].label == '1st field'
+
def test_form_duplicate_file_field(pub):
create_superuser(pub)
create_role()
@@ -1214,6 +1255,7 @@ def test_form_duplicate_file_field(pub):
assert resp.location == 'http://example.net/backoffice/forms/1/fields/#itemId_2'
resp = resp.follow()
+
def test_form_edit_field(pub):
create_superuser(pub)
create_role()
@@ -1239,6 +1281,7 @@ def test_form_edit_field(pub):
assert FormDef.get(1).fields[0].label == 'changed field'
assert FormDef.get(1).fields[0].required == False
+
def test_form_edit_field_advanced(pub):
create_superuser(pub)
create_role()
@@ -1291,6 +1334,7 @@ def test_form_edit_field_advanced(pub):
assert resp.text.index('
') > \
resp.text.index('
')
+
def test_form_prefill_field(pub):
create_superuser(pub)
create_role()
@@ -1334,6 +1378,7 @@ def test_form_prefill_field(pub):
resp = resp.form.submit('submit')
assert 'syntax error in Django template: Unexpected end of expression' in resp.text
+
def test_form_edit_string_field_validation(pub):
create_superuser(pub)
create_role()
@@ -1372,6 +1417,7 @@ def test_form_edit_string_field_validation(pub):
resp = resp.form.submit('submit')
assert 'syntax error' in resp.text
+
def test_form_edit_item_field(pub):
create_superuser(pub)
create_role()
@@ -1412,6 +1458,7 @@ def test_form_edit_item_field(pub):
assert resp.location == 'http://example.net/backoffice/forms/1/fields/#itemId_1'
assert FormDef.get(1).fields[0].items == ['XXX']
+
def test_form_edit_item_field_data_source(pub):
create_superuser(pub)
create_role()
@@ -1490,6 +1537,7 @@ def test_form_edit_item_field_data_source(pub):
resp = resp.form.submit('submit').follow()
resp = app.get('/backoffice/forms/1/')
+
def test_form_edit_items_field(pub):
create_superuser(pub)
create_role()
@@ -1536,6 +1584,7 @@ def test_form_edit_items_field(pub):
assert resp.forms[0]['prefill$type'].options == [
(u'None', True, u'None'), (u'Python Expression', False, u'Python Expression')]
+
def test_form_edit_page_field(pub):
create_superuser(pub)
create_role()
@@ -1590,6 +1639,7 @@ def test_form_edit_page_field(pub):
{'condition': {'type': 'django', 'value': 'foo3'}, 'error_message': 'bar2'},
]
+
def test_form_edit_comment_field(pub):
create_superuser(pub)
create_role()
@@ -1644,6 +1694,7 @@ def test_form_edit_comment_field(pub):
assert resp.location == 'http://example.net/backoffice/forms/1/fields/'
assert FormDef.get(formdef.id).fields[-1].label == '
blah
'
+
def test_form_edit_map_field(pub):
create_superuser(pub)
create_role()
@@ -1708,6 +1759,7 @@ def test_form_edit_map_field(pub):
assert FormDef.get(formdef.id).fields[0].prefill == {
'type': 'geolocation', 'value': 'position'}
+
def test_form_edit_field_warnings(pub):
create_superuser(pub)
create_role()
@@ -1742,6 +1794,7 @@ def test_form_edit_field_warnings(pub):
FormDef.wipe()
+
def test_form_limit_display_to_page(pub):
create_superuser(pub)
create_role()
@@ -1765,6 +1818,7 @@ def test_form_limit_display_to_page(pub):
assert '{{form_var_foobar}}' not in hidden_fields
assert '{{form_var_baz}}' in hidden_fields
+
def test_form_legacy_int_id(pub):
create_superuser(pub)
create_role()
@@ -1816,6 +1870,7 @@ def test_form_legacy_int_id(pub):
resp = resp.click('Recipient')
assert resp.forms[0]['role_id'].value == role.id
+
def test_form_anonymise(pub):
create_superuser(pub)
create_role()
@@ -1880,6 +1935,7 @@ def test_form_anonymise(pub):
assert 'completed' in resp.text
assert len([x for x in formdef.data_class().select() if x.anonymised]) == 3
+
def test_form_public_url(pub):
create_superuser(pub)
create_role()
@@ -1895,6 +1951,7 @@ def test_form_public_url(pub):
resp = resp.click('Display public URL')
assert 'http://example.net/form-title/' in resp.text
+
def test_form_archive(pub):
create_superuser(pub)
create_role()
@@ -1945,6 +2002,7 @@ def test_form_archive(pub):
assert 'formdef' in [x.name for x in tf.getmembers()]
assert len(tf.getmembers()) == 1 # 0 formdata + 1 formdef
+
def test_form_overwrite(pub):
user = create_superuser(pub)
role = create_role()
@@ -2113,6 +2171,7 @@ def test_form_export_import_export_overwrite(pub):
field_ow = formdef_overwrited.fields[i]
assert (field.id, field.label, field.type) == (field_ow.id, field_ow.label, field_ow.type)
+
def test_form_comment_with_error_in_wscall(http_requests, pub):
create_superuser(pub)
NamedWsCall.wipe()
@@ -2139,11 +2198,13 @@ def test_form_comment_with_error_in_wscall(http_requests, pub):
resp = app.get('/backoffice/forms/%s/' % formdef.id)
assert 'x [webservice.xxx.foobar] x' in resp.text
+
def test_workflows(pub):
create_superuser(pub)
app = login(get_app(pub))
app.get('/backoffice/workflows/')
+
def test_workflows_default(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -2161,6 +2222,7 @@ def test_workflows_default(pub):
assert 'Change Status Name' not in resp.text
assert 'Delete' not in resp.text
+
def test_workflows_new(pub):
user = create_superuser(pub)
role = create_role()
@@ -2206,6 +2268,7 @@ def test_workflows_new(pub):
assert wf.possible_status[0].name == 'new status'
assert wf.possible_status[0].items[0].message == 'bla bla bla'
+
def test_workflows_svg(pub):
user = create_superuser(pub)
role = create_role()
@@ -2226,6 +2289,7 @@ def test_workflows_svg(pub):
assert resp.content_type == 'image/svg+xml'
assert '/static/css/dc2/admin.css' in resp.text
+
def test_workflows_edit(pub):
Workflow.wipe()
workflow = Workflow(name='foo')
@@ -2241,6 +2305,7 @@ def test_workflows_edit(pub):
resp = resp.follow()
assert 'baz' in resp.text
+
def test_workflows_edit_status(pub):
create_superuser(pub)
Workflow.wipe()
@@ -2301,6 +2366,7 @@ def test_workflows_edit_status(pub):
resp = resp.follow()
assert 'Hello' in Workflow.get(1).possible_status[0].backoffice_info_text
+
def test_workflows_delete_status(pub):
create_superuser(pub)
Workflow.wipe()
@@ -2322,6 +2388,7 @@ def test_workflows_delete_status(pub):
assert resp.location == 'http://example.net/backoffice/workflows/1/'
resp = resp.follow()
+
def test_workflows_delete(pub):
Workflow.wipe()
workflow = Workflow(name='foo')
@@ -2336,6 +2403,7 @@ def test_workflows_delete(pub):
resp = resp.follow()
assert Workflow.count() == 0
+
def test_workflows_export_import(pub):
create_superuser(pub)
@@ -2366,6 +2434,7 @@ def test_workflows_export_import(pub):
assert 'Invalid File' in resp.text
assert Workflow.count() == 2
+
def test_workflows_export_import_create_role(pub):
create_superuser(pub)
@@ -2426,6 +2495,7 @@ def test_workflows_export_import_create_role(pub):
resp = resp.form.submit('submit')
assert 'Invalid File (Unknown referenced role (PLOP))' in resp.text
+
def test_workflows_duplicate(pub):
create_superuser(pub)
@@ -2447,6 +2517,7 @@ def test_workflows_duplicate(pub):
resp = resp.follow()
assert Workflow.get(3).name == 'foo (copy 2)'
+
def test_workflows_add_all_actions(pub):
create_superuser(pub)
@@ -2474,6 +2545,7 @@ def test_workflows_add_all_actions(pub):
resp = resp.follow() # redirect to ./
i += 1
+
def test_workflows_check_available_actions(pub):
create_superuser(pub)
@@ -2553,6 +2625,7 @@ def test_workflows_edit_dispatch_action(pub):
assert workflow.possible_status[0].items[0].rules == [
{'value': 'FOOBAR', 'role_id': '1'}, {'value': 'BARFOO', 'role_id': '1'}]
+
def test_workflows_edit_email_action(pub):
create_superuser(pub)
role = create_role()
@@ -2688,6 +2761,7 @@ def test_workflows_edit_email_action(pub):
sendmail = Workflow.get(workflow.id).get_status(st1.id).items[0]
assert sendmail.condition == {'type': 'python', 'value': 'True'}
+
def test_workflows_edit_jump_previous(pub):
create_superuser(pub)
role = create_role()
@@ -2738,6 +2812,7 @@ def test_workflows_edit_jump_previous(pub):
resp = app.get('/backoffice/workflows/1/global-actions/ac1/items/_jump/')
assert not 'Previously Marked Status' in [x[2] for x in resp.form['status'].options]
+
def test_workflows_edit_jump_timeout(pub):
create_superuser(pub)
role = create_role()
@@ -2777,6 +2852,7 @@ def test_workflows_edit_jump_timeout(pub):
resp = app.get('/backoffice/workflows/1/status/1/items/_jump/')
assert resp.text.count('ComputedExpressionWidget') == 1
+
def test_workflows_edit_sms_action(pub):
create_superuser(pub)
role = create_role()
@@ -2803,6 +2879,7 @@ def test_workflows_edit_sms_action(pub):
resp = resp.form.submit('submit')
assert Workflow.get(workflow.id).possible_status[0].items[0].to == ['12345']
+
def test_workflows_edit_display_form_action(pub):
create_superuser(pub)
role = create_role()
@@ -2837,6 +2914,7 @@ def test_workflows_edit_display_form_action(pub):
assert 'You are about to remove the "foobar" field.' in resp.text
assert not 'Warning:' in resp.text
+
def test_workflows_edit_choice_action(pub):
create_superuser(pub)
role = create_role()
@@ -2869,6 +2947,7 @@ def test_workflows_edit_choice_action(pub):
resp = resp.click(href='items/1/', index=0)
assert 'Previously Marked Status' in [x[2] for x in resp.form['status'].options]
+
def test_workflows_edit_choice_action_functions_only(pub):
create_superuser(pub)
role = create_role()
@@ -2899,6 +2978,7 @@ def test_workflows_edit_choice_action_functions_only(pub):
assert 'foobar' not in [x[2] for x in resp.form['by$element0'].options]
assert '_receiver' in [x[0] for x in resp.form['by$element0'].options]
+
def test_workflows_action_subpath(pub):
create_superuser(pub)
role = create_role()
@@ -2917,6 +2997,7 @@ def test_workflows_action_subpath(pub):
resp = app.get('/backoffice/workflows/%s/status/%s/items/1/crash' % (
workflow.id, baz_status.id), status=404)
+
def test_workflows_display_action_ezt_validation(pub):
create_superuser(pub)
role = create_role()
@@ -2959,6 +3040,7 @@ def test_workflows_display_action_ezt_validation(pub):
resp = resp.form.submit('submit')
assert 'syntax error in ezt template' in resp.text
+
def test_workflows_delete_action(pub):
create_superuser(pub)
role = create_role()
@@ -2986,6 +3068,7 @@ def test_workflows_delete_action(pub):
resp = resp.follow()
assert Workflow.get(workflow.id).possible_status[0].items == []
+
def test_workflows_variables(pub):
create_superuser(pub)
create_role()
@@ -3016,6 +3099,7 @@ def test_workflows_variables(pub):
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(pub):
test_workflows_variables(pub)
@@ -3044,6 +3128,7 @@ def test_workflows_variables_edit(pub):
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_variables_with_export_to_model_action(pub):
test_workflows_variables(pub)
@@ -3058,6 +3143,7 @@ def test_workflows_variables_with_export_to_model_action(pub):
resp = app.get('/backoffice/workflows/1/variables/fields/')
resp = resp.click('Edit', href='1/')
+
def test_workflows_backoffice_fields(pub):
create_superuser(pub)
create_role()
@@ -3162,6 +3248,7 @@ def test_workflows_backoffice_fields(pub):
workflow = Workflow.get(workflow.id)
assert workflow.possible_status[0].items[0].fields == [{'field_id': first_field_id, 'value': 'Hello'}]
+
def test_workflows_functions(pub):
create_superuser(pub)
create_role()
@@ -3216,6 +3303,7 @@ def test_workflows_functions(pub):
resp = resp.click('Recipient')
assert not 'delete' in resp.forms[0].fields
+
def test_workflows_functions_vs_visibility(pub):
create_superuser(pub)
create_role()
@@ -3254,6 +3342,7 @@ def test_workflows_functions_vs_visibility(pub):
assert set(Workflow.get(workflow.id).possible_status[2].visibility) == set(
['_receiver', '_other-function'])
+
def test_workflows_global_actions(pub):
create_superuser(pub)
create_role()
@@ -3301,6 +3390,7 @@ def test_workflows_global_actions(pub):
resp = resp.form.submit('delete')
assert not Workflow.get(workflow.id).global_actions
+
def test_workflows_global_actions_edit(pub):
create_superuser(pub)
create_role()
@@ -3358,6 +3448,7 @@ def test_workflows_global_actions_edit(pub):
resp = resp.form.submit('submit')
assert Workflow.get(workflow.id).global_actions[0].triggers[0].roles == ['_receiver']
+
def test_workflows_global_actions_timeout_triggers(pub):
create_superuser(pub)
create_role()
@@ -3405,6 +3496,7 @@ def test_workflows_global_actions_timeout_triggers(pub):
resp = resp.form.submit('submit').follow()
assert Workflow.get(workflow.id).global_actions[0].triggers[0].timeout == '-2'
+
def test_workflows_criticality_levels(pub):
create_superuser(pub)
create_role()
@@ -3465,6 +3557,7 @@ def test_workflows_criticality_levels(pub):
resp = resp.forms[0].submit('delete-level')
assert len(Workflow.get(workflow.id).criticality_levels) == 1
+
def test_workflows_wscall_label(pub):
create_superuser(pub)
create_role()
@@ -3487,6 +3580,7 @@ def test_workflows_wscall_label(pub):
resp = app.get('/backoffice/workflows/%s/status/%s/' % (workflow.id, baz_status.id))
assert 'Webservice (foowscallbar)' in resp.text
+
def test_workflows_inspect_view(pub):
from wcs.workflows import WorkflowVariablesFieldsFormDef
from wcs.wf.form import FormWorkflowStatusItem, WorkflowFormFieldsFormDef
@@ -3558,6 +3652,7 @@ def test_workflows_inspect_view(pub):
app = login(get_app(pub))
resp = app.get('/backoffice/workflows/%s/inspect' % workflow.id)
+
def test_workflows_unused(pub):
create_superuser(pub)
FormDef.wipe()
@@ -3588,6 +3683,7 @@ def test_workflows_unused(pub):
resp = app.get('/backoffice/workflows/')
assert 'Unused workflows' in resp.text
+
def test_users_roles_menu_entries(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -3610,11 +3706,13 @@ def test_users_roles_menu_entries(pub):
assert 'Users' not in [x['label'] for x in resp.json]
assert 'Roles' not in [x['label'] for x in resp.json]
+
def test_users(pub):
create_superuser(pub)
app = login(get_app(pub))
app.get('/backoffice/users/')
+
def test_users_new(pub):
pub.user_class.wipe()
create_superuser(pub)
@@ -3633,6 +3731,7 @@ def test_users_new(pub):
assert pub.user_class.count() == user_count + 1
assert PasswordAccount.count() == account_count
+
def test_users_new_with_account(pub):
pub.user_class.wipe()
create_superuser(pub)
@@ -3653,6 +3752,7 @@ def test_users_new_with_account(pub):
assert pub.user_class.count() == user_count + 1
assert PasswordAccount.count() == account_count + 1
+
def test_users_edit(pub):
pub.user_class.wipe()
create_superuser(pub)
@@ -3667,6 +3767,7 @@ def test_users_edit(pub):
assert resp.location == 'http://example.net/backoffice/users/%s/' % user.id
resp = resp.follow()
+
def test_users_edit_new_account(pub):
pub.user_class.wipe()
PasswordAccount.wipe()
@@ -3687,6 +3788,7 @@ def test_users_edit_new_account(pub):
assert PasswordAccount.count() == account_count + 1
+
def test_users_edit_edit_account(pub):
pub.user_class.wipe()
PasswordAccount.wipe()
@@ -3713,6 +3815,7 @@ def test_users_edit_edit_account(pub):
assert PasswordAccount.has_key('foo')
assert PasswordAccount.get('foo').user_id == user.id
+
def test_users_edit_with_managing_idp(pub):
create_role()
pub.user_class.wipe()
@@ -3743,6 +3846,7 @@ def test_users_edit_with_managing_idp(pub):
resp = app.get('/backoffice/users/%s/' % user.id)
assert not '/edit' in resp.text
+
def test_users_delete(pub):
pub.user_class.wipe()
PasswordAccount.wipe()
@@ -3767,6 +3871,7 @@ def test_users_delete(pub):
assert pub.user_class.count() == user_count - 1
assert PasswordAccount.count() == account_count - 1
+
def test_users_pagination(pub):
pub.user_class.wipe()
PasswordAccount.wipe()
@@ -3792,6 +3897,7 @@ def test_users_pagination(pub):
resp = resp.click('Next Page')
assert 'foo bar 50' in resp.text
+
def test_users_filter(pub):
pub.user_class.wipe()
PasswordAccount.wipe()
@@ -3827,6 +3933,7 @@ def test_users_filter(pub):
assert 'foo bar 10' not in resp.text # simple user
assert 'baz bar 1' in resp.text # user with role
+
def test_users_search(pub):
pub.user_class.wipe()
PasswordAccount.wipe()
@@ -3848,6 +3955,7 @@ def test_users_search(pub):
assert 'bar 10' in resp.text
assert 'Number of filtered users: 10' in resp.text
+
def test_users_new_with_custom_formdef(pub):
pub.user_class.wipe()
formdef = UserFieldsFormDef(pub)
@@ -3874,6 +3982,7 @@ def test_users_new_with_custom_formdef(pub):
assert pub.user_class.count() == user_count + 1
assert PasswordAccount.count() == account_count
+
def test_users_display_roles(pub):
pub.user_class.wipe()
@@ -3887,10 +3996,12 @@ def test_users_display_roles(pub):
assert role.name in resp.text
assert 'Unknown role (XXX)' in resp.text
+
def test_roles(pub):
app = login(get_app(pub))
app.get('/backoffice/roles/')
+
def test_roles_new(pub):
Role.wipe()
app = login(get_app(pub))
@@ -3908,6 +4019,7 @@ def test_roles_new(pub):
assert Role.get(1).name == 'a new role'
assert Role.get(1).details == 'bla bla bla'
+
def test_roles_edit(pub):
Role.wipe()
role = Role(name='foobar')
@@ -3931,6 +4043,7 @@ def test_roles_edit(pub):
assert Role.get(1).details == 'bla bla bla'
assert Role.get(1).emails_to_members == True
+
def test_roles_matching_formdefs(pub):
Role.wipe()
role = Role(name='foo')
@@ -3962,6 +4075,7 @@ def test_roles_matching_formdefs(pub):
assert 'form baz' in resp.text
assert 'form bar' not in resp.text
+
def test_roles_delete(pub):
Role.wipe()
role = Role(name='foobar')
@@ -3976,11 +4090,13 @@ def test_roles_delete(pub):
resp = resp.follow()
assert Role.count() == 0
+
def test_categories(pub):
create_superuser(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/forms/categories/')
+
def test_categories_legacy_urls(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -3991,6 +4107,7 @@ def test_categories_legacy_urls(pub):
resp = app.get('/backoffice/categories/1/')
assert resp.location.endswith('/backoffice/forms/categories/1/')
+
def test_categories_new(pub):
create_superuser(pub)
Category.wipe()
@@ -4017,6 +4134,7 @@ def test_categories_new(pub):
assert Category.get(1).name == 'a new category'
assert Category.get(1).description == 'description of the category'
+
def test_categories_edit(pub):
create_superuser(pub)
Category.wipe()
@@ -4038,6 +4156,7 @@ def test_categories_edit(pub):
assert Category.get(1).description == 'category description'
+
def test_categories_edit_duplicate_name(pub):
Category.wipe()
category = Category(name='foobar')
@@ -4057,6 +4176,7 @@ def test_categories_edit_duplicate_name(pub):
resp = resp.forms[0].submit('cancel')
assert resp.location == 'http://example.net/backoffice/forms/categories/'
+
def test_categories_with_formdefs(pub):
Category.wipe()
category = Category(name='foobar')
@@ -4077,6 +4197,7 @@ def test_categories_with_formdefs(pub):
assert 'form bar' in resp.text
assert 'no form associated to this category' not in resp.text
+
def test_categories_delete(pub):
Category.wipe()
category = Category(name='foobar')
@@ -4123,6 +4244,7 @@ def test_categories_edit_description(pub):
resp2 = resp2.follow()
assert Category.get(1).description == 'updated description'
+
def test_categories_new_duplicate_name(pub):
Category.wipe()
category = Category(name='foobar')
@@ -4135,6 +4257,7 @@ def test_categories_new_duplicate_name(pub):
resp = resp.forms[0].submit('submit')
assert 'This name is already used' in resp.text
+
def test_categories_reorder(pub):
Category.wipe()
category = Category(name='foo')
@@ -4155,6 +4278,7 @@ def test_categories_reorder(pub):
Category.sort_by_position(categories)
assert [x.id for x in categories] == ['3', '1', '2']
+
def test_settings(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4171,6 +4295,7 @@ def test_settings(pub):
app.get('/backoffice/settings/session')
app.get('/backoffice/settings/admin-permissions')
+
def test_settings_disabled_screens(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4187,6 +4312,7 @@ def test_settings_disabled_screens(pub):
assert 'Identification' not in resp.text
assert 'Theme' not in resp.text
+
def test_settings_export_import(pub, studio):
def wipe():
FormDef.wipe()
@@ -4361,6 +4487,7 @@ def test_settings_export_import(pub, studio):
filelist = zipf.namelist()
assert len([x for x in filelist if 'roles/' in x]) == 0
+
def test_settings_themes(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4393,6 +4520,7 @@ def test_settings_themes(pub):
assert 'checked' in resp.text
assert get_current_theme()['name'] == 'test'
+
def test_settings_template(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4413,6 +4541,7 @@ def test_settings_template(pub):
resp = app.get('/backoffice/settings/template')
assert resp.forms[0]['template'].value == orig_value
+
def test_settings_user(pub):
user = create_superuser(pub)
app = login(get_app(pub))
@@ -4467,6 +4596,7 @@ def test_settings_user(pub):
pub.cfg['users']['field_email'] = None
pub.write_cfg()
+
def test_settings_emails(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4498,6 +4628,7 @@ def test_settings_emails(pub):
resp = resp.forms[0].submit()
assert pub.cfg['emails']['email-new-account-approved_subject'] is None
+
def test_settings_texts(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4515,6 +4646,7 @@ def test_settings_texts(pub):
assert resp.location == 'http://example.net/backoffice/settings/texts/'
assert pub.cfg['texts']['text-top-of-login'] == None
+
@pytest.mark.skipif('lasso is None')
def test_settings_auth(pub):
pub.user_class.wipe() # makes sure there are no users
@@ -4545,6 +4677,7 @@ def test_settings_auth(pub):
assert 'identification/password/' in resp.text
assert pub.cfg['identification']['methods'] == ['password']
+
@pytest.mark.skipif('lasso is None')
def test_settings_idp(pub):
# create admin session
@@ -4605,6 +4738,7 @@ def test_settings_idp(pub):
resp = resp.click('Update from remote URL')
assert urlopen.call_count == 2
+
def test_settings_auth_password(pub):
Role.wipe()
@@ -4633,6 +4767,7 @@ def test_settings_auth_password(pub):
resp = resp.click('Bulk Import')
resp = resp.forms[0].submit()
+
def test_settings_filetypes(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4671,6 +4806,7 @@ def test_settings_filetypes(pub):
resp = resp.follow()
assert 'HTML files' not in resp.text
+
def test_settings_filetypes_update(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4713,6 +4849,7 @@ def test_settings_filetypes_update(pub):
'label': 'Text files',
}
+
def test_settings_logs(pub):
# reset logging state
logging.shutdown()
@@ -4733,6 +4870,7 @@ def test_settings_logs(pub):
resp = resp.follow()
assert 'Logs' not in resp.text
+
def test_settings_geolocation(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4749,6 +4887,7 @@ def test_settings_geolocation(pub):
pub.reload_cfg()
assert pub.cfg['misc']['default-position'] == '1.234;-1.234'
+
def test_data_sources(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -4762,6 +4901,7 @@ def test_data_sources(pub):
app.get('/backoffice/forms/data-sources/42/', status=404)
app.get('/backoffice/workflows/data-sources/42/', status=404)
+
def test_data_sources_new(pub):
create_superuser(pub)
NamedDataSource.wipe()
@@ -4807,6 +4947,7 @@ def test_data_sources_new(pub):
assert NamedDataSource.count() == 2
+
def test_data_sources_view(pub):
create_superuser(pub)
NamedDataSource.wipe()
@@ -4952,6 +5093,7 @@ def test_data_sources_edit(pub):
assert NamedDataSource.get(1).description == 'data source description'
+
def test_data_sources_edit_duplicate_name(pub):
create_superuser(pub)
NamedDataSource.wipe()
@@ -4973,6 +5115,7 @@ def test_data_sources_edit_duplicate_name(pub):
resp = resp.forms[0].submit('cancel')
assert resp.location == 'http://example.net/backoffice/settings/data-sources/1/'
+
def test_data_sources_delete(pub):
create_superuser(pub)
NamedDataSource.wipe()
@@ -4995,6 +5138,7 @@ def test_data_sources_delete(pub):
resp = resp.follow()
assert NamedDataSource.count() == 0
+
def test_data_sources_in_use_delete(pub):
create_superuser(pub)
NamedDataSource.wipe()
@@ -5022,6 +5166,7 @@ def test_data_sources_in_use_delete(pub):
resp = resp.click(href='delete')
assert 'delete-button' in resp.text
+
def test_data_sources_edit_slug(pub):
create_superuser(pub)
NamedDataSource.wipe()
@@ -5056,6 +5201,7 @@ def test_data_sources_edit_slug(pub):
resp = resp.forms[0].submit('submit')
assert resp.location == 'http://example.net/backoffice/settings/data-sources/1/'
+
def test_data_sources_in_use_edit_slug(pub):
create_superuser(pub)
NamedDataSource.wipe()
@@ -5086,6 +5232,7 @@ def test_data_sources_in_use_edit_slug(pub):
assert 'form_slug' in resp.text
resp = resp.form.submit('submit')
+
def test_wscalls_new(pub):
create_superuser(pub)
NamedWsCall.wipe()
@@ -5114,6 +5261,7 @@ def test_wscalls_new(pub):
assert NamedWsCall.get('a_new_webservice_call').name == 'a new webservice call'
+
def test_wscalls_view(pub):
create_superuser(pub)
NamedWsCall.wipe()
@@ -5133,6 +5281,7 @@ def test_wscalls_view(pub):
resp = app.get('/backoffice/settings/wscalls/%s/' % wscall.id)
assert 'http://remote.example.net/json' in resp.text
+
def test_wscalls_edit(pub):
test_wscalls_view(pub)
@@ -5175,6 +5324,7 @@ def test_wscalls_delete(pub):
assert resp.location == 'http://example.net/backoffice/settings/wscalls/'
assert NamedWsCall.count() == 0
+
def test_settings_permissions(pub):
create_superuser(pub)
role1 = create_role()
@@ -5226,6 +5376,7 @@ def test_settings_permissions(pub):
assert pub.cfg['admin-permissions']['forms'] == []
assert pub.cfg['admin-permissions']['workflows'] == []
+
def test_settings_theme_preview(pub):
create_superuser(pub)
@@ -5252,6 +5403,7 @@ def test_settings_theme_preview(pub):
resp = resp.form.submit('submit')
assert "The theme preview doesn't support this." in resp.text
+
def test_settings_theme_download_upload(pub):
create_superuser(pub)
@@ -5286,6 +5438,7 @@ def test_settings_theme_download_upload(pub):
assert app.get('/themes/alto/../', status=404)
assert app.get('/themes/xxx/../', status=404)
+
def test_postgresql_settings(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -5322,6 +5475,7 @@ def test_postgresql_settings(pub):
resp = resp.form.submit()
assert pub.cfg['postgresql']['port'] == 5432
+
def test_studio_home(pub, studio):
create_superuser(pub)
app = login(get_app(pub))
@@ -5346,6 +5500,7 @@ def test_studio_home(pub, studio):
resp = app.get('/backoffice/')
assert 'studio' not in resp.text
+
def test_studio_workflows(pub, studio):
create_superuser(pub)
app = login(get_app(pub))
@@ -5355,6 +5510,7 @@ def test_studio_workflows(pub, studio):
assert 'status/deleted/' in resp.text
assert 'This is the default workflow,' in resp.text
+
def test_cards_new(pub, studio):
CardDef.wipe()
create_superuser(pub)
@@ -5369,6 +5525,7 @@ def test_cards_new(pub, studio):
assert CardDef.get(1).workflow_id is None
assert CardDef.get(1).disabled is False
+
def test_cards_duplicate(pub, studio):
test_cards_new(pub, studio)
app = login(get_app(pub))
@@ -5377,6 +5534,7 @@ def test_cards_duplicate(pub, studio):
assert CardDef.get(2).name == 'card title (copy)'
assert CardDef.get(2).disabled is False
+
def test_card_workflow_change(pub, studio):
Workflow.wipe()
workflow = Workflow(name='Workflow Two')
diff --git a/tests/test_api.py b/tests/test_api.py
index 8067d7074..70be68247 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -38,10 +38,12 @@ from wcs.qommon.errors import AccessForbiddenError
from utilities import get_app, create_temporary_pub, clean_temporary_pub
+
def pytest_generate_tests(metafunc):
if 'pub' in metafunc.fixturenames:
metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
+
@pytest.fixture
def pub(request, emails):
pub = create_temporary_pub(sql_mode=(request.param == 'sql'))
@@ -59,6 +61,7 @@ coucou = 1234
return pub
+
def teardown_module(module):
clean_temporary_pub()
@@ -103,39 +106,48 @@ def sign_uri(uri, user=None, format='json'):
hashlib.sha256).digest()))
return urlparse.urlunparse((scheme, netloc, path, params, query, fragment))
+
def test_user_page_redirect(pub):
output = get_app(pub).get('/user')
assert output.headers.get('location') == 'http://example.net/myspace/'
+
def test_user_page_error(pub):
# check we get json as output for errors
output = get_app(pub).get('/api/user/', status=403)
assert output.json['err_desc'] == 'no user specified'
+
def test_user_page_error_when_json_and_no_user(pub):
output = get_app(pub).get('/api/user/?format=json', status=403)
assert output.json['err_desc'] == 'no user specified'
+
def test_get_user_from_api_query_string_error_missing_orig(pub):
output = get_app(pub).get('/api/user/?format=json&signature=xxx', status=403)
assert output.json['err_desc'] == 'missing/multiple orig field'
+
def test_get_user_from_api_query_string_error_invalid_orig(pub):
output = get_app(pub).get('/api/user/?format=json&orig=coin&signature=xxx', status=403)
assert output.json['err_desc'] == 'invalid orig'
+
def test_get_user_from_api_query_string_error_missing_algo(pub):
output = get_app(pub).get('/api/user/?format=json&orig=coucou&signature=xxx', status=403)
assert output.json['err_desc'] == 'missing/multiple algo field'
+
def test_get_user_from_api_query_string_error_invalid_algo(pub):
output = get_app(pub).get('/api/user/?format=json&orig=coucou&signature=xxx&algo=coin', status=403)
assert output.json['err_desc'] == 'invalid algo'
+
def test_get_user_from_api_query_string_error_invalid_signature(pub):
output = get_app(pub).get('/api/user/?format=json&orig=coucou&signature=xxx&algo=sha1', status=403)
assert output.json['err_desc'] == 'invalid signature'
+
def test_get_user_from_api_query_string_error_missing_timestamp(pub):
signature = urllib.quote(
base64.b64encode(
@@ -145,6 +157,7 @@ def test_get_user_from_api_query_string_error_missing_timestamp(pub):
output = get_app(pub).get('/api/user/?format=json&orig=coucou&algo=sha1&signature=%s' % signature, status=403)
assert output.json['err_desc'] == 'missing/multiple timestamp field'
+
def test_get_user_from_api_query_string_error_missing_email(pub):
timestamp = datetime.datetime.utcnow().isoformat()[:19] + 'Z'
query = 'format=json&orig=coucou&algo=sha1×tamp=' + timestamp
@@ -156,6 +169,7 @@ def test_get_user_from_api_query_string_error_missing_email(pub):
output = get_app(pub).get('/api/user/?%s&signature=%s' % (query, signature), status=403)
assert output.json['err_desc'] == 'no user specified'
+
def test_get_user_from_api_query_string_error_unknown_nameid(pub):
timestamp = datetime.datetime.utcnow().isoformat()[:19] + 'Z'
query = 'format=json&orig=coucou&algo=sha1&NameID=xxx×tamp=' + timestamp
@@ -167,6 +181,7 @@ def test_get_user_from_api_query_string_error_unknown_nameid(pub):
output = get_app(pub).get('/api/user/?%s&signature=%s' % (query, signature), status=403)
assert output.json['err_desc'] == 'unknown NameID'
+
def test_get_user_from_api_query_string_error_missing_email_valid_endpoint(pub):
# check it's ok to sign an URL without specifiying an user if the endpoint
# works fine without user.
@@ -182,6 +197,7 @@ def test_get_user_from_api_query_string_error_missing_email_valid_endpoint(pub):
output = get_app(pub).get('/json?%s&signature=%s' % (query, signature))
assert output.json == {'err': 0, 'data': []}
+
def test_get_user_from_api_query_string_error_unknown_nameid_valid_endpoint(pub):
# check the categories and forms endpoints accept an unknown NameID
timestamp = datetime.datetime.utcnow().isoformat()[:19] + 'Z'
@@ -196,6 +212,7 @@ def test_get_user_from_api_query_string_error_unknown_nameid_valid_endpoint(pub)
output = get_app(pub).get('/json?%s&signature=%s' % (query, signature))
assert output.json == {'err': 0, 'data': []}
+
def test_get_user_from_api_query_string_error_success_sha1(pub, local_user):
timestamp = datetime.datetime.utcnow().isoformat()[:19] + 'Z'
query = 'format=json&orig=coucou&algo=sha1&email=' + urllib.quote(local_user.email) + '×tamp=' + timestamp
@@ -207,6 +224,7 @@ def test_get_user_from_api_query_string_error_success_sha1(pub, local_user):
output = get_app(pub).get('/api/user/?%s&signature=%s' % (query, signature))
assert output.json['user_display_name'] == u'Jean Darmette'
+
def test_get_user_from_api_query_string_error_invalid_signature_algo_mismatch(pub, local_user):
timestamp = datetime.datetime.utcnow().isoformat()[:19] + 'Z'
query = 'format=json&orig=coucou&algo=sha256&email=' + urllib.quote(local_user.email) + '×tamp=' + timestamp
@@ -218,6 +236,7 @@ def test_get_user_from_api_query_string_error_invalid_signature_algo_mismatch(pu
output = get_app(pub).get('/api/user/?%s&signature=%s' % (query, signature), status=403)
assert output.json['err_desc'] == 'invalid signature'
+
def test_get_user_from_api_query_string_error_success_sha256(pub, local_user):
timestamp = datetime.datetime.utcnow().isoformat()[:19] + 'Z'
query = 'format=json&orig=coucou&algo=sha256&email=' + urllib.quote(local_user.email) + '×tamp=' + timestamp
@@ -229,6 +248,7 @@ def test_get_user_from_api_query_string_error_success_sha256(pub, local_user):
output = get_app(pub).get('/api/user/?%s&signature=%s' % (query, signature))
assert output.json['user_display_name'] == u'Jean Darmette'
+
def test_sign_url(pub, local_user):
signed_url = sign_url(
'http://example.net/api/user/?format=json&orig=coucou&email=%s' % urllib.quote(local_user.email),
@@ -248,6 +268,7 @@ def test_sign_url(pub, local_user):
url = signed_url[len('http://example.net'):]
output = get_app(pub).get(url, status=403)
+
def test_get_user(pub, local_user):
Role.wipe()
role = Role(name='Foo bar')
@@ -307,6 +328,7 @@ def test_get_user_compat_endpoint(pub, local_user):
output = get_app(pub).get(url)
assert output.json['user_display_name'] == u'Jean Darmette'
+
def test_formdef_list(pub):
Role.wipe()
role = Role(name='Foo bar')
@@ -342,6 +364,7 @@ def test_formdef_list(pub):
assert resp1.json['err'] == 0
assert len(resp1.json['data']) == 0
+
def test_limited_formdef_list(pub, local_user):
Role.wipe()
role = Role(name='Foo bar')
@@ -413,6 +436,7 @@ def test_limited_formdef_list(pub, local_user):
resp = get_app(pub).get('/api/formdefs/')
assert resp.json['data'][0]['required_authentication_contexts'] == ['fedict']
+
def test_formdef_list_redirection(pub):
FormDef.wipe()
formdef = FormDef()
@@ -429,6 +453,7 @@ def test_formdef_list_redirection(pub):
assert resp1.json['data'][0]['redirection'] == True
assert 'count' not in resp1.json['data'][0]
+
def test_backoffice_submission_formdef_list(pub, local_user):
Role.wipe()
role = Role(name='Foo bar')
@@ -493,6 +518,7 @@ def test_backoffice_submission_formdef_list(pub, local_user):
assert resp.json['err'] == 0
assert len(resp.json['data']) == 0
+
def test_formdef_schema(pub):
Workflow.wipe()
workflow = Workflow(name='test')
@@ -601,6 +627,7 @@ def test_formdef_schema(pub):
get_app(pub).get('/api/formdefs/xxx/schema', status=404)
+
def test_post_invalid_json(pub, local_user):
resp = get_app(pub).post('/api/formdefs/test/submit',
params='not a json payload',
@@ -609,6 +636,7 @@ def test_post_invalid_json(pub, local_user):
assert resp.json['err'] == 1
assert resp.json['err_class'] == 'Invalid request'
+
def test_formdef_submit(pub, local_user):
Role.wipe()
role = Role(name='test')
@@ -689,6 +717,7 @@ def test_formdef_submit(pub, local_user):
data_class.wipe()
+
def test_formdef_submit_only_one(pub, local_user):
Role.wipe()
role = Role(name='test')
@@ -726,6 +755,7 @@ def test_formdef_submit_only_one(pub, local_user):
assert data_class.get(resp.json['data']['id']).user_id == str(local_user.id)
assert data_class.count() == 2
+
def test_formdef_submit_with_varname(pub, local_user):
NamedDataSource.wipe()
data_source = NamedDataSource(name='foobar')
@@ -920,6 +950,7 @@ def test_formdef_submit_from_wscall(pub, local_user):
new_formdata = formdef.data_class().get(resp.json['data']['id'])
assert new_formdata.data.get('5') is None
+
def test_categories(pub):
FormDef.wipe()
Category.wipe()
@@ -962,6 +993,7 @@ def test_categories(pub):
resp = get_app(pub).get('/api/categories/')
assert resp.json['data'][0]['description'] == category.description
+
def test_categories_private(pub, local_user):
FormDef.wipe()
Category.wipe()
@@ -1001,6 +1033,7 @@ def test_categories_private(pub, local_user):
resp = get_app(pub).get(sign_uri('http://example.net/api/categories/', local_user))
assert len(resp.json['data']) == 1
+
def test_categories_formdefs(pub, local_user):
FormDef.wipe()
Category.wipe()
@@ -1080,6 +1113,7 @@ def test_categories_formdefs(pub, local_user):
assert resp.json['err'] == 0
assert len(resp.json['data']) == 1
+
def test_categories_full(pub):
test_categories(pub)
resp = get_app(pub).get('/api/categories/?full=on')
@@ -1087,6 +1121,7 @@ def test_categories_full(pub):
assert resp.json['data'][0]['forms'][0]['title'] == 'test'
assert resp.json['data'][0]['forms'][1]['title'] == 'test 2'
+
def test_formdata(pub, local_user):
NamedDataSource.wipe()
data_source = NamedDataSource(name='foobar')
@@ -1187,6 +1222,7 @@ def test_formdata(pub, local_user):
resp2 = get_app(pub).get(sign_uri('/test/%s/' % formdata.id,
user=local_user), status=403)
+
def test_formdata_backoffice_fields(pub, local_user):
test_formdata(pub, local_user)
workflow = Workflow.get(2)
@@ -1205,6 +1241,7 @@ def test_formdata_backoffice_fields(pub, local_user):
resp = get_app(pub).get(sign_uri('/api/forms/test/%s/' % formdata.id, user=local_user))
assert resp.json['workflow']['fields']['backoffice_blah'] == 'Hello world'
+
def test_formdata_edit(pub, local_user):
test_formdata(pub, local_user)
formdef = FormDef.select()[0]
@@ -1256,6 +1293,7 @@ def test_formdata_edit(pub, local_user):
assert formdef.data_class().select()[0].data['0'] == 'bar2@localhost'
assert formdef.data_class().select()[0].status == 'wf-rejected'
+
def test_formdata_with_workflow_data(pub, local_user):
Role.wipe()
role = Role(name='test')
@@ -1298,6 +1336,7 @@ def test_formdata_with_workflow_data(pub, local_user):
assert base64.decodestring(force_bytes(resp.json['workflow']['data']['blah']['content'])) == b'test'
assert base64.decodestring(force_bytes(resp.json['workflow']['data']['blah2']['content'])) == b'test'
+
def test_user_by_nameid(pub, local_user):
resp = get_app(pub).get(sign_uri('/api/users/xyz/', user=local_user),
status=404)
@@ -1306,6 +1345,7 @@ def test_user_by_nameid(pub, local_user):
resp = get_app(pub).get(sign_uri('/api/users/xyz/', user=local_user))
assert str(resp.json['id']) == str(local_user.id)
+
def test_user_roles(pub, local_user):
local_user.name_identifiers = ['xyz']
local_user.store()
@@ -1317,6 +1357,7 @@ def test_user_roles(pub, local_user):
assert len(resp.json['user_roles']) == 1
assert resp.json['user_roles'][0]['name'] == 'Foo bar'
+
def test_user_forms(pub, local_user):
Workflow.wipe()
workflow = Workflow.get_default_workflow()
@@ -1435,6 +1476,7 @@ def test_user_forms(pub, local_user):
assert resp2.json['data'][0] == resp.json['data'][1]
assert resp2.json['data'][1] == resp.json['data'][0]
+
def test_user_forms_limit_offset(pub, local_user):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -1480,6 +1522,7 @@ def test_user_forms_limit_offset(pub, local_user):
assert len(resp.json['data']) == 10
assert [x['form_number_raw'] for x in resp.json['data']] == [str(x) for x in range(50, 40, -1)]
+
def test_user_forms_from_agent(pub, local_user):
Role.wipe()
role = Role(name='Foo bar')
@@ -1532,6 +1575,7 @@ def test_user_forms_from_agent(pub, local_user):
agent_user.store()
get_app(pub).get(sign_uri('/api/users/%s/forms' % local_user.id, user=agent_user), status=403)
+
def test_user_drafts(pub, local_user):
FormDef.wipe()
formdef = FormDef()
@@ -1716,6 +1760,7 @@ def test_api_list_formdata(pub, local_user):
get_app(pub).get(sign_uri('/api/forms/test/list?filter=all&offset=plop', user=local_user), status=400)
get_app(pub).get(sign_uri('/api/forms/test/list?filter=all&limit=plop', user=local_user), status=400)
+
def test_api_anonymized_formdata(pub, local_user, admin_user):
Role.wipe()
role = Role(name='test')
@@ -1820,6 +1865,7 @@ def test_api_anonymized_formdata(pub, local_user, admin_user):
assert 'NameID' in resp.json['evolution'][1]['who']
assert 'name' in resp.json['evolution'][1]['who']
+
def test_api_geojson_formdata(pub, local_user):
Role.wipe()
role = Role(name='test')
@@ -1905,6 +1951,7 @@ def test_api_geojson_formdata(pub, local_user):
formdef.store()
resp = get_app(pub).get(sign_uri('/api/forms/test/geojson', user=local_user), status=404)
+
def test_api_global_geojson(pub, local_user):
Role.wipe()
role = Role(name='test')
@@ -1959,6 +2006,7 @@ def test_api_global_geojson(pub, local_user):
assert 'features' in resp.json
assert len(resp.json['features']) == 20
+
def test_api_global_listing(pub, local_user):
if not pub.is_using_postgresql():
resp = get_app(pub).get(sign_uri('/api/forms/geojson', user=local_user), status=404)
@@ -2027,6 +2075,7 @@ def test_api_global_listing(pub, local_user):
get_app(pub).get(sign_uri('/api/forms/?status=done&limit=plop', user=local_user), status=400)
get_app(pub).get(sign_uri('/api/forms/?status=done&offset=plop', user=local_user), status=400)
+
def test_api_global_listing_ignored_roles(pub, local_user):
test_api_global_listing(pub, local_user)
@@ -2148,6 +2197,7 @@ def ics_data(local_user):
formdata.jump_status('finished')
formdata.store()
+
def test_api_ics_formdata(pub, local_user, ics_data):
role = Role.select()[0]
@@ -2203,6 +2253,7 @@ def test_api_ics_formdata(pub, local_user, ics_data):
assert resp.text.count('DTSTART') == 10
assert resp.text.count('DTEND') == 10
+
def test_api_ics_formdata_http_auth(pub, local_user, ics_data):
role = Role.select()[0]
@@ -2233,6 +2284,7 @@ def test_api_ics_formdata_http_auth(pub, local_user, ics_data):
app.authorization = ('Basic', ('user', 'password2'))
resp = app.get('/api/forms/test/ics/foobar?email=%s' % local_user.email, status=403)
+
def test_roles(pub, local_user):
Role.wipe()
role = Role(name='Hello World')
@@ -2257,6 +2309,7 @@ def test_roles(pub, local_user):
assert resp.json['data'][0]['emails_to_members'] == False
assert resp.json['data'][0]['details'] == 'kouign amann'
+
def test_users(pub, local_user):
resp = get_app(pub).get('/api/users/', status=403)
@@ -2292,6 +2345,7 @@ def test_users(pub, local_user):
resp = get_app(pub).get(sign_uri('/api/users/?q=foobar'))
assert len(resp.json['data']) == 0
+
def test_users_unaccent(pub, local_user):
local_user.name = 'Jean Sénisme'
local_user.store()
@@ -2307,6 +2361,7 @@ def test_users_unaccent(pub, local_user):
resp = get_app(pub).get(sign_uri('/api/users/?q=blah'))
assert len(resp.json['data']) == 0
+
def test_workflow_trigger(pub, local_user):
workflow = Workflow(name='test')
st1 = workflow.add_status('Status1', 'st1')
@@ -2393,6 +2448,7 @@ def test_workflow_trigger_with_condition(pub, local_user):
resp = get_app(pub).post(sign_uri(formdata.get_url() + 'jump/trigger/XXX'))
assert resp.json == {'err': 0, 'url': None}
+
def test_workflow_trigger_jump_once(pub, local_user):
workflow = Workflow(name='test')
st1 = workflow.add_status('Status1', 'st1')
@@ -2514,6 +2570,7 @@ def test_workflow_global_webservice_trigger(pub, local_user):
{'test': 'BAR'}, status=200)
assert formdef.data_class().get(formdata.id).workflow_data == {'plop': {'test': 'BAR'}}
+
def test_tracking_code(pub):
FormDef.wipe()
formdef = FormDef()
@@ -2550,6 +2607,7 @@ def test_tracking_code(pub):
formdata.remove_self()
resp = get_app(pub).get(sign_url('/api/code/%s?orig=coucou' % code.id, '1234'), status=404)
+
def test_validate_expression(pub):
resp = get_app(pub).get('/api/validate-expression?expression=hello')
assert resp.json == {'klass': None, 'msg': ''}
@@ -2570,6 +2628,7 @@ def test_validate_expression(pub):
assert resp.json['klass'] == 'error'
assert resp.json['msg'].startswith('syntax error in Django template: Could not parse the remainder')
+
def test_validate_condition(pub):
resp = get_app(pub).get('/api/validate-condition?type=python&value_python=hello')
assert resp.json == {'klass': None, 'msg': ''}
@@ -2593,6 +2652,7 @@ def test_validate_condition(pub):
assert resp.json['klass'] == 'error'
assert resp.json['msg'] == 'unknown condition type'
+
@pytest.fixture(params=['sql', 'pickle'])
def no_request_pub(request):
pub = create_temporary_pub(sql_mode=bool(request.param == 'sql'))
@@ -2605,11 +2665,13 @@ api.example.com = 1234
''')
return pub
+
def test_get_secret_and_orig(no_request_pub):
secret, orig = get_secret_and_orig('https://api.example.com/endpoint/')
assert secret == '1234'
assert orig == 'example.net'
+
def test_reverse_geocoding(pub):
with mock.patch('wcs.qommon.misc.urlopen') as urlopen:
urlopen.side_effect = lambda *args: StringIO(json.dumps({'address': 'xxx'}))
@@ -2717,6 +2779,7 @@ def test_geocoding(pub):
resp = get_app(pub).get('/api/geocoding?q=test')
assert urlopen.call_args[0][0] == 'http://reverse.example.net/?param=value&format=json&q=test&accept-language=en'
+
def test_cards(pub, local_user):
Role.wipe()
role = Role(name='test')
diff --git a/tests/test_auth_pages.py b/tests/test_auth_pages.py
index a232d1bdd..f64b060ee 100644
--- a/tests/test_auth_pages.py
+++ b/tests/test_auth_pages.py
@@ -24,15 +24,18 @@ def pub():
return pub
+
@pytest.fixture
def pub_2auth(pub):
pub.cfg['identification'] = {'methods': ['password', 'idp']}
pub.write_cfg()
return pub
+
def teardown_module(module):
clean_temporary_pub()
+
def test_login_logout(pub):
resp_initial = get_app(pub).get('/')
resp = login(get_app(pub), username='foo', password='foo').get('/')
@@ -40,6 +43,7 @@ def test_login_logout(pub):
resp = resp.follow()
assert resp.text == resp_initial.text
+
def test_register_account(pub):
resp = get_app(pub).get('/').click('Login').follow()
assert not 'register' in resp.text
@@ -54,6 +58,7 @@ def test_register_account(pub):
assert PasswordAccount.count() == 2
assert pub.user_class.count() == 2
+
def test_login_2auth(pub_2auth):
resp = get_app(pub_2auth).get('/').click('Login').follow()
resp.form['method'] = 'Username / password'
@@ -68,6 +73,7 @@ def test_login_2auth(pub_2auth):
resp = resp.form.submit().follow()
assert 'SSO support is not yet configured' in resp.text
+
def test_register_2auth(pub_2auth):
pub_2auth.cfg['identities'] = {'creation': 'self'}
pub_2auth.write_cfg()
diff --git a/tests/test_backoffice_pages.py b/tests/test_backoffice_pages.py
index f9e55011e..67f5c1edf 100644
--- a/tests/test_backoffice_pages.py
+++ b/tests/test_backoffice_pages.py
@@ -59,6 +59,7 @@ def pytest_generate_tests(metafunc):
if 'pub' in metafunc.fixturenames:
metafunc.parametrize('pub', ['pickle', 'sql', 'pickle-templates'], indirect=True)
+
@pytest.fixture
def pub(request, emails):
pub = create_temporary_pub(
@@ -80,6 +81,7 @@ coucou = 1234
return pub
+
def create_user(pub, is_admin=False):
if pub.user_class.select(lambda x: x.name == 'admin'):
user1 = pub.user_class.select(lambda x: x.name == 'admin')[0]
@@ -106,8 +108,10 @@ def create_user(pub, is_admin=False):
return user1
+
def create_superuser(pub): return create_user(pub, is_admin=True)
+
def create_environment(pub, set_receiver=True):
pub.session_manager.session_class.wipe()
Workflow.wipe()
@@ -178,14 +182,17 @@ def create_environment(pub, set_receiver=True):
formdata.jump_status('new')
formdata.store()
+
def teardown_module(module):
clean_temporary_pub()
+
def test_backoffice_unlogged(pub):
create_superuser(pub)
resp = get_app(pub).get('/backoffice/', status=302)
assert resp.location == 'http://example.net/login/?next=http%3A%2F%2Fexample.net%2Fbackoffice%2F'
+
def test_backoffice_home(pub):
create_superuser(pub)
app = login(get_app(pub))
@@ -194,6 +201,7 @@ def test_backoffice_home(pub):
assert 'Forms Workshop' in resp.text
assert 'Workflows Workshop' in resp.text
+
def test_backoffice_role_user(pub):
create_user(pub)
app = login(get_app(pub))
@@ -224,6 +232,7 @@ def test_backoffice_role_user(pub):
assert not 'Forms Workshop' in resp.text
assert 'Workflows Workshop' in resp.text
+
def test_backoffice_forms(pub):
create_superuser(pub)
create_environment(pub, set_receiver=False)
@@ -284,6 +293,7 @@ def test_backoffice_forms(pub):
assert 'Forms in your care' in resp.text
assert '9 open on 50' in resp.text
+
def test_backoffice_listing(pub):
create_superuser(pub)
create_environment(pub)
@@ -383,6 +393,7 @@ def test_backoffice_listing(pub):
resp = resp.forms[0].submit()
assert resp.text.count('data-link') == 9
+
def test_backoffice_listing_pagination(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -423,6 +434,7 @@ def test_backoffice_listing_pagination(pub):
resp = resp.follow()
assert resp.form['offset'].value == '0'
+
def test_backoffice_listing_order(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -475,6 +487,7 @@ def test_backoffice_listing_order(pub):
ids = [x.strip('/') for x in re.findall(r'data-link="(.*?)"', resp.text)]
assert ids == list(reversed(last_update_time_order))
+
def test_backoffice_listing_anonymised(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -493,6 +506,7 @@ def test_backoffice_listing_anonymised(pub):
resp = app.get('/backoffice/management/form-title/?limit=500')
assert resp.text.count('data-link') == 9
+
def test_backoffice_legacy_urls(pub):
create_superuser(pub)
create_environment(pub)
@@ -507,6 +521,7 @@ def test_backoffice_legacy_urls(pub):
assert resp.location == 'http://example.net/backoffice/management/form-title/listing/foo?bla'
resp = app.get('/backoffice/not-form-title/', status=404)
+
def test_backoffice_columns(pub):
create_superuser(pub)
create_environment(pub)
@@ -521,6 +536,7 @@ def test_backoffice_columns(pub):
assert resp.text.count('data-link') == 17 # 17 rows
assert resp.text.count('FOO BAR') == 0 # no field 1 column
+
def test_backoffice_channel_column(pub):
if not pub.site_options.has_section('variables'):
pub.site_options.add_section('variables')
@@ -540,6 +556,7 @@ def test_backoffice_channel_column(pub):
assert resp.text.count('data-link') == 17 # 17 rows
assert resp.text.count('
Web | ') == 17
+
def test_backoffice_submission_agent_column(pub):
user = create_user(pub)
create_environment(pub)
@@ -578,6 +595,7 @@ def test_backoffice_submission_agent_column(pub):
assert len(resp.text.splitlines()) == 18 # 17 + header line
assert resp.text.count(',agent,') == 17
+
def test_backoffice_image_column(pub):
create_superuser(pub)
create_environment(pub)
@@ -596,6 +614,7 @@ def test_backoffice_image_column(pub):
resp = app.get('/backoffice/management/form-title/')
assert 'download?f=4&thumbnail=1' not in resp.text
+
def test_backoffice_filter(pub):
create_superuser(pub)
create_environment(pub)
@@ -639,6 +658,7 @@ def test_backoffice_filter(pub):
resp = resp.forms[0].submit()
assert resp.text.count('
baz | ') == 0
+
def test_backoffice_default_filter(pub):
create_superuser(pub)
create_environment(pub)
@@ -664,6 +684,7 @@ def test_backoffice_default_filter(pub):
resp = app.get('/backoffice/management/form-title/')
assert 'filter-4-value' in resp.form.fields
+
def test_backoffice_bool_filter(pub):
create_superuser(pub)
create_environment(pub)
@@ -694,6 +715,7 @@ def test_backoffice_bool_filter(pub):
assert resp.text.count('
Yes | ') == 0
assert resp.text.count('
No | ') > 0
+
def test_backoffice_item_filter(pub):
create_superuser(pub)
create_environment(pub)
@@ -766,6 +788,7 @@ def test_backoffice_item_filter(pub):
else:
assert [x['id'] for x in resp2.json['data']] == [u'â', u'b', u'd']
+
def test_backoffice_item_double_filter(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -835,6 +858,7 @@ def test_backoffice_item_double_filter(pub):
assert [x[0] for x in resp.form['filter-4-value'].options] == ['', 'a', 'b']
assert [x[0] for x in resp.form['filter-5-value'].options] == ['', 'A', 'B', 'C']
+
def test_backoffice_bofield_item_filter(pub):
create_superuser(pub)
create_environment(pub)
@@ -966,6 +990,7 @@ def test_backoffice_items_filter(pub):
assert resp.text.count(u'
b, d | ') == 0
assert resp.text.count('data-link') == 0 # no rows
+
def test_backoffice_csv(pub):
create_superuser(pub)
create_environment(pub)
@@ -1026,6 +1051,7 @@ def test_backoffice_csv(pub):
resp_csv = resp.click('Export as CSV File')
assert 'Created' not in resp_csv.text.splitlines()[0]
+
def test_backoffice_export_long_listings(pub):
create_superuser(pub)
create_environment(pub)
@@ -1069,6 +1095,7 @@ def test_backoffice_export_long_listings(pub):
# check error handling
app.get('/afterjobs/whatever', status=404)
+
def test_backoffice_csv_export_channel(pub):
if not pub.site_options.has_section('variables'):
pub.site_options.add_section('variables')
@@ -1091,6 +1118,7 @@ def test_backoffice_csv_export_channel(pub):
assert resp_csv.text.splitlines()[0].split(',')[1] == 'Channel'
assert resp_csv.text.splitlines()[1].split(',')[1] == 'Web'
+
def test_backoffice_csv_export_anonymised(pub):
fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
pub.site_options.write(fd)
@@ -1110,6 +1138,7 @@ def test_backoffice_csv_export_anonymised(pub):
assert resp_csv.text.splitlines()[0].split(',')[-1] == 'Anonymised'
assert resp_csv.text.splitlines()[1].split(',')[-1] == 'No'
+
def test_backoffice_ods(pub):
create_superuser(pub)
create_environment(pub)
@@ -1195,6 +1224,7 @@ def test_backoffice_ods(pub):
assert row.findall('.//{%s}table-cell' % ods.NS['table'])[
string_column].find('{%s}p' % ods.NS['text']).text == 'plop\nplop'
+
@pytest.mark.skipif('xlwt is None')
def test_backoffice_xls(pub):
create_superuser(pub)
@@ -1214,6 +1244,7 @@ def test_backoffice_xls(pub):
resp = resp.click('Excel Export')
assert resp.headers['content-type'].startswith('application/vnd.ms-excel')
+
def test_backoffice_statistics(pub):
create_superuser(pub)
create_environment(pub)
@@ -1235,6 +1266,7 @@ def test_backoffice_statistics(pub):
assert '
Filters
' in resp.text
assert 'End: 2013-01-01' in resp.text
+
def test_backoffice_multi_actions(pub):
create_superuser(pub)
create_environment(pub)
@@ -1344,6 +1376,7 @@ def test_backoffice_multi_actions(pub):
else:
assert formdata.status != 'wf-accepted'
+
def test_backoffice_statistics_status_filter(pub):
create_superuser(pub)
create_environment(pub)
@@ -1382,6 +1415,7 @@ def test_backoffice_statistics_status_filter(pub):
resp = resp.forms[0].submit()
assert 'Total number of records: 50' in resp.text
+
def test_backoffice_statistics_status_select(pub):
create_superuser(pub)
create_environment(pub)
@@ -1430,6 +1464,7 @@ def test_backoffice_statistics_status_select(pub):
resp = resp.click('Statistics')
assert 'filter-2-value' in resp.form.fields
+
def test_backoffice_map(pub):
user = create_user(pub)
create_environment(pub)
@@ -1466,6 +1501,7 @@ def test_backoffice_map(pub):
resp = resp.click('Plot on a Map')
assert 'tile.example.net/' in resp.text
+
def test_backoffice_geojson(pub):
user = create_user(pub)
create_environment(pub)
@@ -1527,6 +1563,7 @@ def test_backoffice_handling(pub):
assert FormDef.get_by_urlname('form-title').data_class().get(number31.id).status == 'wf-accepted'
assert 'HELLO WORLD' in resp.text
+
def test_backoffice_handling_global_action(pub):
create_user(pub)
create_environment(pub)
@@ -1563,6 +1600,7 @@ def test_backoffice_handling_global_action(pub):
assert 'HELLO WORLD GLOBAL ACTION' in resp.text
assert formdef.data_class().get(formdata.id).status == 'wf-finished'
+
def test_backoffice_global_remove_action(pub):
create_user(pub)
create_environment(pub)
@@ -1596,6 +1634,7 @@ def test_backoffice_global_remove_action(pub):
assert resp.request.url == 'http://example.net/backoffice/management/test-global-remove/'
assert 'The form has been deleted.' in resp.text
+
def test_backoffice_submission_context(pub):
user = create_user(pub)
create_environment(pub)
@@ -1632,6 +1671,7 @@ def test_backoffice_submission_context(pub):
assert 'http://www.example.com/summary' in resp.text
assert 'by %s' % user.get_display_name() in resp.text
+
def test_backoffice_geolocation_info(pub):
user = create_user(pub)
create_environment(pub)
@@ -1660,6 +1700,7 @@ def test_backoffice_geolocation_info(pub):
assert 'data-init-lng="2.32"' in resp.text
assert 'data-init-lat="48.83' in resp.text
+
def test_backoffice_info_text(pub):
create_user(pub)
create_environment(pub)
@@ -1752,6 +1793,7 @@ def test_backoffice_info_text(pub):
resp = app.get('/backoffice/management/form-title/%s/' % number31.id)
assert not 'backoffice-description' in resp.text
+
def test_backoffice_handling_post_dispatch(pub):
# check a formdata that has been dispatched to another role is accessible
# by an user with that role.
@@ -1801,6 +1843,7 @@ def test_backoffice_handling_post_dispatch(pub):
assert FormDef.get_by_urlname('form-title').data_class().get(number31.id).status == 'wf-accepted'
assert 'HELLO WORLD' in resp.text
+
def test_global_statisticspub(pub):
create_superuser(pub)
create_environment(pub)
@@ -1814,6 +1857,7 @@ def test_global_statisticspub(pub):
resp = resp.forms[0].submit()
assert 'Total count: 20' in resp.text
+
def test_backoffice_submission(pub):
user = create_user(pub)
create_environment(pub)
@@ -1958,6 +2002,7 @@ def test_backoffice_submission_with_tracking_code(pub):
resp = app.get(formdata_location)
assert not formdata.tracking_code in resp.text
+
def test_backoffice_submission_welco(pub, welco_url):
user = create_user(pub)
create_environment(pub)
@@ -1992,6 +2037,7 @@ def test_backoffice_submission_welco(pub, welco_url):
# check agent name is displayed next to pending submission
assert '(%s)' % user.display_name in resp.text
+
def test_backoffice_submission_initiated_from_welco(pub, welco_url):
user = create_user(pub)
create_environment(pub)
@@ -2046,6 +2092,7 @@ def test_backoffice_submission_initiated_from_welco(pub, welco_url):
assert pq('#steps li.current .label').text() == '1st PAGE'
assert 'Field on 1st page' in resp.text # and in fields
+
def test_backoffice_submission_with_return_url(pub):
user = create_user(pub)
create_environment(pub)
@@ -2082,6 +2129,7 @@ def test_backoffice_submission_with_return_url(pub):
resp = resp.form.submit('submit') # -> to submit
assert resp.location == 'https://example.org'
+
def test_backoffice_parallel_submission(pub):
user = create_user(pub)
create_environment(pub)
@@ -2152,6 +2200,7 @@ def test_backoffice_parallel_submission(pub):
resp4 = resp4.follow()
assert 'This form has already been submitted.' in resp4.text
+
def test_backoffice_submission_dispatch(pub):
user = create_user(pub)
create_environment(pub)
@@ -2215,6 +2264,7 @@ def test_backoffice_submission_dispatch(pub):
# right role
assert resp.location.startswith('http://example.net/backoffice/management/form-title/')
+
def test_backoffice_submission_tracking_code(pub):
user = create_user(pub)
create_environment(pub)
@@ -2254,6 +2304,7 @@ def test_backoffice_submission_tracking_code(pub):
assert 'Check values then click submit.' in resp.text
assert 'test submission' in resp.text
+
def test_backoffice_submission_drafts(pub):
user = create_user(pub)
create_environment(pub)
@@ -2307,6 +2358,7 @@ def test_backoffice_submission_drafts(pub):
# check it kept the same id
assert resp.location == 'http://example.net/backoffice/management/form-title/%s/' % formdata_no
+
def test_backoffice_submission_remove_drafts(pub):
user = create_user(pub)
create_environment(pub)
@@ -2363,6 +2415,7 @@ def test_backoffice_submission_remove_drafts(pub):
resp = app.get('/backoffice/submission/form-title/remove/%s' % formdata.id,
status=403)
+
def test_backoffice_submission_live_condition(pub):
user = create_user(pub)
create_environment(pub)
@@ -2405,6 +2458,7 @@ def test_backoffice_submission_live_condition(pub):
assert '
Bar' in resp.text
assert '
Foo' not in resp.text
+
def test_backoffice_submission_conditional_jump_based_on_bo_field(pub):
user = create_superuser(pub)
Workflow.wipe()
@@ -2468,6 +2522,7 @@ def test_backoffice_submission_conditional_jump_based_on_bo_field(pub):
assert formdef.data_class().count() == 1
assert formdef.data_class().select()[0].status == 'wf-st1'
+
def test_backoffice_submission_sections(pub):
user = create_user(pub)
create_environment(pub)
@@ -2504,6 +2559,7 @@ def test_backoffice_submission_sections(pub):
assert 'Running submission' in resp.text
assert '>#%s' % formdata.id in resp.text
+
def test_backoffice_submission_prefill_user(pub):
user = create_user(pub)
create_environment(pub)
@@ -2550,6 +2606,7 @@ def test_backoffice_submission_prefill_user(pub):
# and check it was not prefilled
assert resp.form['f1'].value == ''
+
def test_backoffice_submission_prefill_user_via_formula(pub):
user = create_user(pub)
create_environment(pub)
@@ -2596,6 +2653,7 @@ def test_backoffice_submission_prefill_user_via_formula(pub):
# and check it was not prefilled
assert resp.form['f1'].value == ''
+
def test_backoffice_submission_prefill_user_multiple_pages(pub):
user = create_user(pub)
create_environment(pub)
@@ -2685,6 +2743,7 @@ def test_backoffice_submission_prefill_user_multiple_pages(pub):
assert formdef.data_class().count() == 1
assert formdef.data_class().select()[0].user_id is None
+
def test_backoffice_submission_multiple_page_restore_on_validation(pub):
user = create_user(pub)
create_environment(pub)
@@ -2723,6 +2782,7 @@ def test_backoffice_submission_multiple_page_restore_on_validation(pub):
resp = resp.follow()
assert 'Check values then click submit.' in resp.text
+
def test_backoffice_submission_substitution_vars(pub):
user = create_user(pub)
create_environment(pub)
@@ -2774,6 +2834,7 @@ def test_backoffice_submission_substitution_vars(pub):
resp = resp.form.submit('submit')
assert 'dj-PLOP-an-bar-go' in resp.text
+
def test_backoffice_submission_manual_channel(pub):
user = create_user(pub)
create_environment(pub)
@@ -2812,6 +2873,7 @@ def test_backoffice_submission_manual_channel(pub):
assert data_class.get(formdata_no).backoffice_submission is True
assert data_class.get(formdata_no).submission_channel == 'mail'
+
def test_backoffice_submission_no_manual_channel_with_welco(pub, welco_url):
user = create_user(pub)
create_environment(pub)
@@ -2824,6 +2886,7 @@ def test_backoffice_submission_no_manual_channel_with_welco(pub, welco_url):
resp = app.get('/backoffice/submission/%s/' % formdef.url_name)
assert 'submission_channel' not in resp.form.fields
+
def test_backoffice_submission_with_nameid_and_channel(pub, local_user):
user = create_user(pub)
create_environment(pub)
@@ -2862,6 +2925,7 @@ def test_backoffice_submission_with_nameid_and_channel(pub, local_user):
assert formdata.submission_channel == 'mail'
assert formdata.status == 'wf-new'
+
def test_backoffice_wscall_failure_display(http_requests, pub):
user = create_user(pub)
create_environment(pub)
@@ -2912,6 +2976,7 @@ def test_backoffice_wscall_failure_display(http_requests, pub):
assert (' with the number %s.' % number31.get_display_id()) in resp.text
assert not 'Error during webservice call' in resp.text
+
def test_backoffice_wscall_error_email(http_requests, pub, emails):
pub.cfg['debug'] = {'error_email': 'errors@localhost.invalid'}
pub.write_cfg()
@@ -2966,6 +3031,7 @@ def test_backoffice_wscall_error_email(http_requests, pub, emails):
assert '/form-title/%s/' % number31.id in error_email['payload']
assert error_email['msg']['References']
+
def test_backoffice_wscall_attachment(http_requests, pub):
create_user(pub)
create_environment(pub)
@@ -3033,6 +3099,7 @@ def test_backoffice_wscall_attachment(http_requests, pub):
resp = resp.follow()
assert resp.text == '
'
+
def test_backoffice_wfedit(pub):
user = create_user(pub)
create_environment(pub)
@@ -3077,6 +3144,7 @@ def test_backoffice_wfedit(pub):
assert form_class().get(number31.id).data['2'] == 'bar'
number31.store()
+
def test_backoffice_wfedit_submission(pub):
user = create_user(pub)
create_environment(pub)
@@ -3127,6 +3195,7 @@ def test_backoffice_wfedit_submission(pub):
number31.store()
assert formdata_count == form_class.count()
+
def test_backoffice_wfedit_and_backoffice_fields(pub):
user = create_user(pub)
create_environment(pub)
@@ -3169,6 +3238,7 @@ def test_backoffice_wfedit_and_backoffice_fields(pub):
resp = resp.follow()
assert form_class().get(number31.id).data['bo1'] == 'plop'
+
def test_backoffice_wfedit_and_data_source_with_user_info(pub):
user = create_user(pub)
create_environment(pub)
@@ -3220,6 +3290,7 @@ def test_backoffice_wfedit_and_data_source_with_user_info(pub):
assert urlopen.call_count == 2
resp = resp.follow()
+
def test_global_listing(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -3338,6 +3409,7 @@ def test_global_listing(pub):
assert resp.text[resp.text.index('
blah xxx' in resp.text
+
def test_management_views_with_no_formdefs(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -3398,6 +3471,7 @@ def test_management_views_with_no_formdefs(pub):
resp = app.get('/backoffice/management/listing')
assert 'This site is currently empty.' in resp.text
+
def test_category_in_global_listing(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -3437,6 +3511,7 @@ def test_category_in_global_listing(pub):
assert 'management/other-form/' in resp.text
assert not 'management/form-title/' in resp.text
+
def test_datetime_in_global_listing(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -3477,6 +3552,7 @@ def test_datetime_in_global_listing(pub):
resp = resp.forms['listing-settings'].submit()
assert resp.text[resp.text.index('Misc<' in partial_resp.text
assert partial_resp.text.index('>Misc<') < partial_resp.text.index('>cat1<')
+
def test_count_open(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -3735,6 +3816,7 @@ def test_count_open(pub):
resp = login(get_app(pub)).get('/backoffice/management/count?callback=toto')
assert "20" in resp.text
+
def test_count_backoffice_drafts(pub):
user = create_user(pub)
create_environment(pub)
@@ -3769,6 +3851,7 @@ def test_count_backoffice_drafts(pub):
resp = login(get_app(pub)).get('/backoffice/submission/count?mode=existing')
assert resp.json['count'] == 2
+
def test_menu_json(pub):
user = create_user(pub)
create_environment(pub)
@@ -3782,6 +3865,7 @@ def test_menu_json(pub):
assert resp.text == 'foo(%s);' % menu_json_str
assert resp.headers['content-type'] == 'application/javascript'
+
def test_per_user_view(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -3842,6 +3926,7 @@ def test_per_user_view(pub):
resp = app.get('/backoffice/management/users/%s/' % user.id)
assert resp.text.count('' in resp.text
+
def test_backoffice_backoffice_submission_in_listings(pub):
create_superuser(pub)
create_environment(pub)
@@ -3918,6 +4005,7 @@ def test_backoffice_backoffice_submission_in_listings(pub):
resp = app.get('/backoffice/management/form-title/')
assert 'backoffice-submission' in resp.text
+
def test_backoffice_backoffice_submission_in_global_listing(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -3938,6 +4026,7 @@ def test_backoffice_backoffice_submission_in_global_listing(pub):
resp = app.get('/backoffice/management/listing?limit=100')
assert 'backoffice-submission' in resp.text
+
def test_backoffice_advisory_lock(pub):
create_superuser(pub)
create_environment(pub)
@@ -4008,6 +4097,7 @@ def test_backoffice_advisory_lock(pub):
assert not 'advisory-lock' in app2.get('/backoffice/management/form-title/')
assert 'advisory-lock' in app.get('/backoffice/management/form-title/')
+
def test_backoffice_advisory_lock_related_formdatas(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -4078,6 +4168,7 @@ def test_backoffice_advisory_lock_related_formdatas(pub):
session = pub.session_manager.session_class.select(lambda x: x.user == user.id)[0]
assert 'formdata-other-form-%d' % other_formdata.id in session.visiting_objects.keys()
+
def test_backoffice_resubmit(pub):
user = create_user(pub)
create_environment(pub)
@@ -4140,6 +4231,7 @@ def test_backoffice_resubmit(pub):
assert 'Original form' in resp.text
assert formdata.get_url(backoffice=True) in resp.text
+
def test_backoffice_workflow_display_form(pub):
user = create_user(pub)
create_environment(pub)
@@ -4199,6 +4291,7 @@ def test_backoffice_workflow_display_form(pub):
assert formdef.data_class().get(formdata.id).workflow_data == {
'blah_var_str': 'blah', 'blah_var_radio': 'c', 'blah_var_radio_raw': 'c'}
+
def test_backoffice_workflow_form_with_conditions(pub):
user = create_user(pub)
create_environment(pub)
@@ -4313,6 +4406,7 @@ def test_backoffice_workflow_form_with_conditions(pub):
assert formdef.data_class().get(formdata.id).workflow_data == {'blah_var_str': 'xxx2', 'blah_var_str2': None}
+
def test_backoffice_workflow_form_with_live_data_source(pub):
user = create_user(pub)
create_environment(pub)
@@ -4368,6 +4462,7 @@ def test_backoffice_workflow_form_with_live_data_source(pub):
live_resp = app.post(live_url + '?modified_field_id=1', params=resp.form.submit_fields())
assert live_resp.json['result']['2']['items'] == [{u'text': u'hello', u'id': u'C'}, {u'text': u'world', u'id': u'D'}]
+
def test_backoffice_criticality_in_formdef_listing(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -4412,6 +4507,7 @@ def test_backoffice_criticality_in_formdef_listing(pub):
assert resp.text.index(formdata1_str) < resp.text.index(formdata3_str)
assert resp.text.index(formdata1_str) > resp.text.index(formdata4_str)
+
def test_backoffice_criticality_in_global_listing(pub):
if not pub.is_using_postgresql():
pytest.skip('this requires SQL')
@@ -4457,6 +4553,7 @@ def test_backoffice_criticality_in_global_listing(pub):
assert resp.text.index(formdata1_str) < resp.text.index(formdata3_str)
assert resp.text.index(formdata1_str) > resp.text.index(formdata4_str)
+
def test_backoffice_criticality_formdata_view(pub):
user = create_user(pub)
create_environment(pub)
@@ -4496,6 +4593,7 @@ class IHateUnicode(object):
def __repr__(self):
return 'ok'
+
@pytest.fixture
def local_user():
get_publisher().user_class.wipe()
@@ -4506,6 +4604,7 @@ def local_user():
user.store()
return user
+
def test_inspect_page(pub, local_user):
create_user(pub)
create_environment(pub)
@@ -4667,6 +4766,7 @@ def test_inspect_page(pub, local_user):
assert 'syntax error' in resp.text
assert 'Invalid block tag' in resp.text
+
def test_workflow_jump_previous(pub):
user = create_user(pub)
create_environment(pub)
@@ -4776,6 +4876,7 @@ def test_workflow_jump_previous(pub):
formdata.jump_status('_previous') # pop ()
assert formdata.status == 'wf-%s' % st1.id
+
def test_workflow_jump_previous_on_submit(pub):
user = create_user(pub)
create_environment(pub)
@@ -4835,6 +4936,7 @@ def test_workflow_jump_previous_on_submit(pub):
assert formdef.data_class().get(formdata.id).status == 'wf-north'
assert not formdef.data_class().get(formdata.id).workflow_data['_markers_stack']
+
def test_workflow_jump_previous_auto(pub):
user = create_user(pub)
create_environment(pub)
@@ -4888,6 +4990,7 @@ def test_workflow_jump_previous_auto(pub):
assert formdata.status == 'wf-south'
assert formdata.workflow_data['_markers_stack'] == [{'status_id': 'north'}]
+
def test_backoffice_fields(pub):
user = create_user(pub)
create_environment(pub)
@@ -4938,6 +5041,7 @@ def test_backoffice_fields(pub):
assert 'Backoffice Data' in resp.text
assert 'Not set' in resp.text
+
def test_backoffice_logged_errors(pub):
Workflow.wipe()
workflow = Workflow.get_default_workflow()
@@ -5027,6 +5131,7 @@ def test_backoffice_logged_errors(pub):
resp = resp2.click('Failed to evaluate condition')
assert not 'href="http://example.net/backoffice/management/test/' in resp.text
+
def test_backoffice_formdata_named_wscall(http_requests, pub):
user = create_user(pub)
create_environment(pub)
@@ -5083,6 +5188,7 @@ def test_backoffice_formdata_named_wscall(http_requests, pub):
resp = app.get('/backoffice/submission/test/')
assert resp.html.find('div', {'data-field-id': '7'}).text.strip() == 'dja-bar-ngo'
+
def test_backoffice_session_var(pub):
open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w').write('''[options]
query_string_allowed_vars = foo,bar
@@ -5118,6 +5224,7 @@ query_string_allowed_vars = foo,bar
resp = resp.follow()
assert resp.html.find('div', {'data-field-id': '7'}).text.strip() == 'django'
+
def test_backoffice_display_message(pub):
user = create_user(pub)
create_environment(pub)
@@ -5186,6 +5293,7 @@ def test_backoffice_display_message(pub):
assert 'message-to-all' in resp.text
assert resp.text.index('message-to-all') > resp.text.index('message-to-receiver')
+
def test_backoffice_forms_condition_on_button(pub):
create_superuser(pub)
create_environment(pub, set_receiver=True)
@@ -5248,6 +5356,7 @@ def test_backoffice_forms_condition_on_button(pub):
resp = resp.follow()
assert '8 open on 50' in resp.text # only the accepted ones
+
def test_workflow_inspect_page(pub):
create_superuser(pub)
create_environment(pub, set_receiver=True)
@@ -5273,6 +5382,7 @@ def test_workflow_inspect_page(pub):
resp = app.get('/backoffice/workflows/%s/inspect' % workflow.id)
assert '23 hours' in resp.text
+
def test_workflow_comment_required(pub):
user = create_user(pub)
create_environment(pub)
@@ -5322,6 +5432,7 @@ def test_workflow_comment_required(pub):
assert 'widget-with-error' not in resp.text
assert 'HELLO WORLD 2' in resp.text
+
def test_carddata_management(pub, studio):
CardDef.wipe()
user = create_user(pub)
@@ -5373,6 +5484,7 @@ def test_carddata_management(pub, studio):
resp = resp.click('foo')
assert resp.text.count('[foo]')
@@ -30,6 +34,7 @@ def test_simple_qualifier():
template.generate(output, {'foo': 'bar'})
assert output.getvalue() == 'bar
'
+
def test_simple_qualifier_missing_variable():
template = Template()
template.parse('[foo]
')
@@ -37,6 +42,7 @@ def test_simple_qualifier_missing_variable():
template.generate(output, {})
assert output.getvalue() == '[foo]
'
+
def test_if_any():
template = Template()
template.parse('[if-any foo]bar[end]
')
@@ -56,6 +62,7 @@ def test_if_any():
template.generate(output, {'foo': False})
assert output.getvalue() == 'bar
'
+
def test_if_any_else():
template = Template()
template.parse('[if-any foo]bar[else]baz[end]
')
@@ -68,6 +75,7 @@ def test_if_any_else():
template.generate(output, {})
assert output.getvalue() == 'baz
'
+
def test_is():
template = Template()
template.parse('[is foo "bar"]bar[end]
')
@@ -87,6 +95,7 @@ def test_is():
template.generate(output, {'foo': 'bar'})
assert output.getvalue() == 'bar
'
+
def test_callable_qualifier():
template = Template()
template.parse('[foo]
')
@@ -94,6 +103,7 @@ def test_callable_qualifier():
template.generate(output, {'foo': lambda x: x.write('bar')})
assert output.getvalue() == 'bar
'
+
def test_date_qualifier(pub):
template = Template()
template.parse('[foo]
')
@@ -107,6 +117,7 @@ def test_date_qualifier(pub):
template.generate(output, {'foo': datetime.date(2019, 1, 2)})
assert output.getvalue() == '02/01/2019
'
+
def test_datetime_qualifier(pub):
template = Template()
template.parse('[foo]
')
@@ -120,6 +131,7 @@ def test_datetime_qualifier(pub):
template.generate(output, {'foo': datetime.datetime(2019, 1, 2, 14, 4)})
assert output.getvalue() == '02/01/2019 14:04
'
+
def test_unclosed_block():
template = Template()
with pytest.raises(UnclosedBlocksError):
@@ -129,6 +141,7 @@ def test_unclosed_block():
except UnclosedBlocksError as e:
assert e.column == 19 and e.line == 0
+
def test_unmatched_end():
template = Template()
with pytest.raises(UnmatchedEndError):
@@ -138,6 +151,7 @@ def test_unmatched_end():
except UnmatchedEndError as e:
assert e.column == 15 and e.line == 0
+
def test_unmatched_else():
template = Template()
with pytest.raises(UnmatchedElseError):
@@ -147,6 +161,7 @@ def test_unmatched_else():
except UnmatchedElseError as e:
assert e.column == 3 and e.line == 0
+
def test_missing_is_arg():
template = Template()
with pytest.raises(ArgCountSyntaxError):
@@ -156,6 +171,7 @@ def test_missing_is_arg():
except ArgCountSyntaxError as e:
assert e.column == 5 and e.line == 1
+
def test_array_index():
template = Template()
template.parse('[foo.0]
')
@@ -169,6 +185,7 @@ def test_array_index():
template.generate(output, {'foo': ['bar']})
assert output.getvalue() == '[foo.bar]
'
+
def test_array_subindex():
template = Template()
template.parse('[foo.0.1]
')
@@ -176,6 +193,7 @@ def test_array_subindex():
template.generate(output, {'foo': [['bar', 'baz']]})
assert output.getvalue() == 'baz
'
+
def test_dict_index():
template = Template()
template.parse('[foo.a]
')
@@ -189,6 +207,7 @@ def test_dict_index():
template.generate(output, {'foo': {'a': 'bar'}})
assert output.getvalue() == '[foo.b]
'
+
def test_ezt_script(pub):
os.mkdir(os.path.join(pub.app_dir, 'scripts'))
fd = open(os.path.join(pub.app_dir, 'scripts', 'hello_world.py'), 'w')
@@ -209,6 +228,7 @@ def test_ezt_script(pub):
template.generate(output, vars)
assert output.getvalue() == 'Hello fred
'
+
def test_re_parse():
assert _re_parse.split('[a]') == ['', 'a', None, '']
assert _re_parse.split('[a] [b]') == \
diff --git a/tests/test_fields.py b/tests/test_fields.py
index e33bd8474..129b742a7 100644
--- a/tests/test_fields.py
+++ b/tests/test_fields.py
@@ -16,6 +16,7 @@ from wcs.formdef import FormDef
from utilities import create_temporary_pub, MockSubstitutionVariables
+
def setup_module(module):
cleanup()
global pub
@@ -24,19 +25,23 @@ def setup_module(module):
pub._set_request(req)
req.session = sessions.Session(id=1)
+
def teardown_module(module):
global pub
shutil.rmtree(pub.APP_DIR)
+
def test_fill_admin_form():
for klass in fields.field_classes:
form = Form(use_tokens=False)
klass().fill_admin_form(form)
+
def test_get_admin_attributes():
for klass in fields.field_classes:
klass().get_admin_attributes()
+
def test_add_to_form():
for klass in fields.field_classes:
form = Form(use_tokens=False)
@@ -46,6 +51,7 @@ def test_add_to_form():
else:
klass(label='foo').add_to_form(form)
+
def test_string():
# sample string
assert fields.StringField().get_view_value('foo') == 'foo'
@@ -74,6 +80,7 @@ def test_string():
assert str(fields.StringField().get_rst_view_value(url)) == url
assert fields.StringField().get_csv_value(url) == [url]
+
def test_text():
assert fields.TextField().get_view_short_value('foo'*10) == ('foo'*10)[:25] + ' (...)'
assert fields.TextField().get_view_value('foo') == 'foo
'
@@ -92,15 +99,18 @@ def test_text():
assert 'cols="12"' in str(form.render())
assert 'rows="12"' in str(form.render())
+
def test_email():
assert fields.EmailField().get_view_value('foo@localhost') == \
'foo@localhost'
assert fields.EmailField().get_rst_view_value('foo@localhost') == 'foo@localhost'
+
def test_bool():
assert fields.BoolField().get_view_value(True) == 'Yes'
assert fields.BoolField().get_view_value(False) == 'No'
+
def test_bool_stats():
formdef = FormDef()
formdef.url_name = 'title'
@@ -114,6 +124,7 @@ def test_bool_stats():
stats = formdef.fields[0].stats(formdatas)
assert re.findall('Yes.*75.*No.*25', str(stats))
+
def test_items():
assert fields.ItemsField(items=['a', 'b', 'c']).get_view_value(['a', 'b']) == 'a, b'
assert fields.ItemsField(items=['a', 'b', 'c']).get_csv_value(['a', 'b']) == ['a', 'b', '']
@@ -129,13 +140,16 @@ def test_items():
assert field.get_options() == [('1', 'foo', '1'), ('2', 'bar', '2')]
assert field.get_options() == [('1', 'foo', '1'), ('2', 'bar', '2')] # twice for cached behaviour
+
def test_password():
assert fields.PasswordField().get_view_value('xxx') == '●'*8
+
def test_file():
upload = Upload('/foo/bar', content_type='text/plain')
assert fields.FileField().get_csv_value(upload) == ['/foo/bar']
+
def test_page():
formdef = FormDef()
formdef.fields = []
@@ -148,9 +162,11 @@ def test_page():
assert page.is_visible({'1': 'bar'}, formdef) is True
assert page.is_visible({'1': 'baz'}, formdef) is False
+
def test_table():
assert 'prefill' not in fields.TableField().get_admin_attributes()
+
def test_title():
field = fields.TitleField(label='Foobar')
form = Form(use_tokens=False)
@@ -195,6 +211,7 @@ def test_title():
assert '<i>Foobaré</i>' in str(form.render())
assert field.unhtmled_label == 'Foobaré'
+
def test_subtitle():
field = fields.SubtitleField(label='Foobar')
form = Form(use_tokens=False)
@@ -239,6 +256,7 @@ def test_subtitle():
assert '<i>Foobaré</i>' in str(form.render())
assert field.unhtmled_label == 'Foobaré'
+
def test_comment():
field = fields.CommentField(label='Foobar')
form = Form(use_tokens=False)
@@ -285,6 +303,7 @@ def test_comment():
field = fields.CommentField(label='Foobaré
')
assert field.unhtmled_label == 'Foobaré'
+
def test_map():
assert fields.MapField().get_json_value('42.2;10.2') == {'lat': 42.2, 'lon': 10.2}
assert fields.MapField().get_json_value('-42.2;10.2') == {'lat': -42.2, 'lon': 10.2}
@@ -292,6 +311,7 @@ def test_map():
assert fields.MapField().get_json_value('') == None
assert fields.MapField().get_json_value('foobar') == None
+
def test_item_render():
items_kwargs = []
items_kwargs.append({'items': ['aa', 'ab', 'ac']})
@@ -357,6 +377,7 @@ def test_item_render():
assert str(form.render()).count('') == 1 # ---
assert str(form.render()).count('