tests: also test backoffice pages against postgresql backend
This commit is contained in:
parent
7ba6aa59f9
commit
a3977d1715
|
@ -15,14 +15,15 @@ from wcs.workflows import Workflow
|
|||
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)
|
||||
|
@ -30,12 +31,13 @@ def setup_module(module):
|
|||
pub.cfg['language'] = {'language': 'en'}
|
||||
pub.write_cfg()
|
||||
|
||||
def create_superuser():
|
||||
return pub
|
||||
|
||||
def create_superuser(pub):
|
||||
global user1
|
||||
if pub.user_class.has_key('admin'):
|
||||
if pub.user_class.select(lambda x: x.name == 'admin'):
|
||||
return
|
||||
user1 = pub.user_class(name='admin')
|
||||
user1.id = 'admin'
|
||||
user1.is_admin = True
|
||||
user1.store()
|
||||
|
||||
|
@ -82,30 +84,32 @@ def create_environment(set_receiver=True):
|
|||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'other form'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
formdef.data_class().wipe()
|
||||
for i in range(20):
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.receipt_time = datetime.datetime(2014, 1, 1).timetuple()
|
||||
formdata.store()
|
||||
|
||||
def teardown_module(module):
|
||||
shutil.rmtree(pub.APP_DIR)
|
||||
clean_temporary_pub()
|
||||
|
||||
def test_backoffice_unlogged():
|
||||
create_superuser()
|
||||
def test_backoffice_unlogged(pub):
|
||||
create_superuser(pub)
|
||||
resp = get_app(pub).get('/backoffice/', status=302)
|
||||
resp = resp.follow()
|
||||
assert resp.location == 'http://example.net/login/'
|
||||
|
||||
def test_backoffice_home():
|
||||
create_superuser()
|
||||
def test_backoffice_home(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/')
|
||||
assert 'Management' in resp.body
|
||||
|
||||
def test_backoffice_forms():
|
||||
create_superuser()
|
||||
def test_backoffice_forms(pub):
|
||||
create_superuser(pub)
|
||||
create_environment(set_receiver=False)
|
||||
|
||||
# 1st time with user not handling those forms
|
||||
|
@ -123,8 +127,8 @@ def test_backoffice_forms():
|
|||
assert 'Forms in your care' in resp.body
|
||||
assert '17 open on 50' in resp.body
|
||||
|
||||
def test_backoffice_listing():
|
||||
create_superuser()
|
||||
def test_backoffice_listing(pub):
|
||||
create_superuser(pub)
|
||||
create_environment()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/form-title/')
|
||||
|
@ -134,16 +138,25 @@ def test_backoffice_listing():
|
|||
resp = app.get('/backoffice/form-title/')
|
||||
resp.forms[0]['filter'] = 'all'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.body.count('data-link') == 50 # not using sql -> no pagination
|
||||
if getattr(pub, 'pgconn', None):
|
||||
assert resp.body.count('data-link') == 20
|
||||
else:
|
||||
# not using sql -> no pagination
|
||||
assert resp.body.count('data-link') == 50
|
||||
|
||||
# check status filter <select>
|
||||
resp = app.get('/backoffice/form-title/')
|
||||
resp.forms[0]['filter'] = 'done'
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.body.count('data-link') == 33
|
||||
if getattr(pub, 'pgconn', None):
|
||||
assert resp.body.count('data-link') == 20
|
||||
resp = resp.click('Next Page')
|
||||
assert resp.body.count('data-link') == 13
|
||||
else:
|
||||
assert resp.body.count('data-link') == 33
|
||||
|
||||
def test_backoffice_columns():
|
||||
create_superuser()
|
||||
def test_backoffice_columns(pub):
|
||||
create_superuser(pub)
|
||||
create_environment()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/form-title/')
|
||||
|
@ -154,8 +167,8 @@ def test_backoffice_columns():
|
|||
assert resp.body.count('data-link') == 17 # 17 rows
|
||||
assert resp.body.count('FOO BAR') == 0 # no field 1 column
|
||||
|
||||
def test_backoffice_csv():
|
||||
create_superuser()
|
||||
def test_backoffice_csv(pub):
|
||||
create_superuser(pub)
|
||||
create_environment()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/form-title/')
|
||||
|
@ -169,8 +182,8 @@ def test_backoffice_csv():
|
|||
resp = resp.click('CSV Export')
|
||||
assert len(resp.body.splitlines()) == 51
|
||||
|
||||
def test_backoffice_ods():
|
||||
create_superuser()
|
||||
def test_backoffice_ods(pub):
|
||||
create_superuser(pub)
|
||||
create_environment()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/form-title/')
|
||||
|
@ -179,8 +192,8 @@ def test_backoffice_ods():
|
|||
assert 'filename=form-title.ods' in resp.headers['content-disposition']
|
||||
assert resp.body[:2] == 'PK' # ods has a zip container
|
||||
|
||||
def test_backoffice_statistics():
|
||||
create_superuser()
|
||||
def test_backoffice_statistics(pub):
|
||||
create_superuser(pub)
|
||||
create_environment()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/form-title/')
|
||||
|
@ -197,8 +210,8 @@ def test_backoffice_statistics():
|
|||
resp = resp.forms[0].submit()
|
||||
assert 'Total number of records: 0' in resp.body
|
||||
|
||||
def test_backoffice_handling():
|
||||
create_superuser()
|
||||
def test_backoffice_handling(pub):
|
||||
create_superuser(pub)
|
||||
create_environment()
|
||||
form_class = FormDef.get_by_urlname('form-title').data_class()
|
||||
app = login(get_app(pub))
|
||||
|
@ -208,11 +221,11 @@ def test_backoffice_handling():
|
|||
resp.forms[0]['comment'] = 'HELLO WORLD'
|
||||
resp = resp.forms[0].submit('button_accept')
|
||||
resp = resp.follow()
|
||||
assert form_class.get(31).status == 'wf-accepted'
|
||||
assert FormDef.get_by_urlname('form-title').data_class().get(31).status == 'wf-accepted'
|
||||
assert 'HELLO WORLD' in resp.body
|
||||
|
||||
def test_global_statistics():
|
||||
create_superuser()
|
||||
def test_global_statisticspub(pub):
|
||||
create_superuser(pub)
|
||||
create_environment()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/')
|
||||
|
|
Loading…
Reference in New Issue