misc: split backoffice pages tests

This commit is contained in:
Lauréline Guérin 2020-10-13 15:37:02 +02:00
parent 111569ff59
commit 5bb8b78512
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 380 additions and 258 deletions

View File

@ -7248,264 +7248,6 @@ def test_backoffice_after_submit_location(pub):
assert resp.location == 'http://example.net/backoffice/management/form-title/%s/#' % formdata.id
def test_backoffice_custom_view(pub):
create_superuser(pub)
create_environment(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
assert resp.text.count('<span>User Label</span>') == 1
assert resp.text.count('<tr') == 18
# columns
resp.forms['listing-settings']['user-label'].checked = False
resp = resp.forms['listing-settings'].submit()
# filters
resp.forms['listing-settings']['filter-2'].checked = True
resp = resp.forms['listing-settings'].submit()
resp.forms['listing-settings']['filter-2-value'] = 'baz'
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<span>User Label</span>') == 0
assert resp.text.count('<tr') == 9
resp.forms['save-custom-view']['title'] = 'custom test view'
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-custom-test-view/')
resp = resp.follow()
assert resp.text.count('<span>User Label</span>') == 0
assert resp.text.count('<tr') == 9
resp.forms['listing-settings']['filter-2-value'] = 'foo'
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<tr') == 6
assert resp.forms['save-custom-view']['update'].checked is True
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-custom-test-view/')
resp = resp.follow()
assert resp.text.count('<tr') == 6
resp = app.get('/backoffice/management/other-form/')
assert 'custom test view' not in resp
# check it's not possible to create a view without any columns
for field_key in resp.forms['listing-settings'].fields:
if not field_key:
continue
if field_key.startswith('filter'):
continue
if resp.forms['listing-settings'][field_key].attrs.get('type') != 'checkbox':
continue
resp.forms['listing-settings'][field_key].checked = False
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'custom test view'
resp = resp.forms['save-custom-view'].submit().follow()
assert 'Views must have at least one column.' in resp.text
def test_backoffice_custom_view_delete(pub):
create_superuser(pub)
create_environment(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
# columns
resp.forms['listing-settings']['user-label'].checked = False
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'custom test view'
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-custom-test-view/')
resp = resp.follow()
resp = resp.click('Delete')
resp = resp.form.submit()
assert resp.location.endswith('/management/form-title/')
resp = resp.follow()
assert 'custom test view' not in resp.text
def test_backoffice_custom_map_view(pub):
test_backoffice_custom_view(pub)
formdef = FormDef.get_by_urlname('form-title')
formdef.geolocations = {'base': 'Geolocafoobar'}
formdef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
resp = resp.click('custom test view')
assert resp.text.count('<span>User Label</span>') == 0
assert resp.text.count('<tr') == 6
resp = resp.click('Plot on a Map')
assert resp.forms['listing-settings']['filter-2-value'].value == 'foo'
def test_backoffice_custom_view_reserved_slug(pub):
create_superuser(pub)
create_environment(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
resp.forms['listing-settings']['user-label'].checked = False
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'user custom test view'
resp = resp.forms['save-custom-view'].submit()
# check slug not created with "user" as prefix
assert resp.location.endswith('/user-userx-custom-test-view/')
resp = resp.follow()
def test_backoffice_custom_view_visibility(pub):
create_environment(pub)
create_superuser(pub)
formdef = FormDef.get_by_urlname('form-title')
agent = pub.user_class(name='agent')
agent.roles = [formdef.workflow_roles['_receiver']]
agent.store()
account = PasswordAccount(id='agent')
account.set_password('agent')
account.user_id = agent.id
account.store()
app = login(get_app(pub), username='agent', password='agent')
resp = app.get('/backoffice/management/form-title/')
# columns
resp.forms['listing-settings']['user-label'].checked = False
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<span>User Label</span>') == 0
resp.forms['save-custom-view']['title'] = 'custom test view'
assert 'visibility' not in resp.forms['save-custom-view'].fields
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-custom-test-view/')
resp = resp.follow()
assert resp.text.count('<span>User Label</span>') == 0
# second agent
agent2 = pub.user_class(name='agent2')
agent2.roles = [formdef.workflow_roles['_receiver']]
agent2.store()
account = PasswordAccount(id='agent2')
account.set_password('agent2')
account.user_id = agent2.id
account.store()
app = login(get_app(pub), username='agent2', password='agent2')
resp = app.get('/backoffice/management/form-title/')
assert 'custom test view' not in resp
# shared custom view
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'shared view'
resp.forms['save-custom-view']['visibility'] = 'any'
resp = resp.forms['save-custom-view'].submit()
app = login(get_app(pub), username='agent2', password='agent2')
resp = app.get('/backoffice/management/form-title/')
resp = resp.click('shared view')
# don't allow a second "any" view with same slug
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'shared view'
resp.forms['save-custom-view']['visibility'] = 'any'
resp = resp.forms['save-custom-view'].submit()
assert set([(x.slug, x.visibility) for x in get_publisher().custom_view_class.select()]) == set(
[('custom-test-view', 'owner'), ('shared-view', 'any'), ('shared-view-2', 'any')])
def test_backoffice_missing_custom_view(pub):
create_superuser(pub)
create_environment(pub, set_receiver=False)
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/user-plop/')
assert resp.location == 'http://example.net/backoffice/management/form-title/'
resp = resp.follow()
assert 'A missing or invalid custom view was referenced' in resp
resp = app.get('/backoffice/management/form-title/user-plop/1/')
assert resp.location == 'http://example.net/backoffice/management/form-title/1/'
resp = app.get('/backoffice/management/form-title/user-plop/1/?plop')
assert resp.location == 'http://example.net/backoffice/management/form-title/1/?plop'
def test_carddata_custom_view(pub, studio):
CardDef.wipe()
user = create_user(pub)
app = login(get_app(pub))
carddef = CardDef()
carddef.name = 'foo'
carddef.fields = [
fields.StringField(id='1', label='Test', type='string', varname='foo'),
]
carddef.backoffice_submission_roles = user.roles
carddef.workflow_roles = {'_editor': user.roles[0]}
carddef.store()
carddef.data_class().wipe()
for i in range(50):
carddata = carddef.data_class()()
carddata.data = {'1': 'FOO %s' % i}
carddata.just_created()
carddata.store()
resp = app.get('/backoffice/data/foo/')
if pub.is_using_postgresql():
assert resp.text.count('<tr') == 21 # header + rows of data
else:
# no pagination
assert resp.text.count('<tr') == 51 # header + rows of data
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'card view'
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-card-view/')
resp = resp.follow()
def test_backoffice_custom_view_keep_filters(pub):
create_superuser(pub)
create_environment(pub)
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
assert resp.text.count('<span>User Label</span>') == 1
assert resp.text.count('<tr') == 18
# filters
resp.forms['listing-settings']['filter-2'].checked = True
resp = resp.forms['listing-settings'].submit()
resp.forms['listing-settings']['filter-2-value'] = 'baz'
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'custom test view'
resp = resp.forms['save-custom-view'].submit()
resp = app.get('/backoffice/management/form-title/user-custom-test-view/')
assert 'filter-2-value' in resp.forms['listing-settings'].fields
assert 'filter-3-value' not in resp.forms['listing-settings'].fields
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A')
assert 'filter-2-value' not in resp.forms['listing-settings'].fields
assert 'filter-3-value' in resp.forms['listing-settings'].fields
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A&keep-view-filters=on')
assert 'filter-2-value' in resp.forms['listing-settings'].fields
assert 'filter-3-value' in resp.forms['listing-settings'].fields
def test_backoffice_table_varname_filter(pub):
create_superuser(pub)
create_environment(pub)

View File

@ -0,0 +1,380 @@
# -*- coding: utf-8 -*-
import os
import pytest
try:
import xlwt
except ImportError:
xlwt = None
from quixote import get_publisher
from wcs.qommon.ident.password_accounts import PasswordAccount
from wcs.qommon.http_request import HTTPRequest
from wcs.carddef import CardDef
from wcs.formdef import FormDef
from wcs import fields
from utilities import (get_app, login, create_temporary_pub, clean_temporary_pub)
from test_all import create_user, create_superuser
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(
sql_mode=bool('sql' in request.param),
templates_mode=bool('templates' in request.param)
)
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
pub.set_app_dir(req)
pub.cfg['identification'] = {'methods': ['password']}
pub.cfg['language'] = {'language': 'en'}
pub.write_cfg()
fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w')
fd.write('''
[api-secrets]
coucou = 1234
''')
fd.close()
return pub
def teardown_module(module):
clean_temporary_pub()
def test_backoffice_custom_view(pub):
create_superuser(pub)
FormDef.wipe()
pub.custom_view_class.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = [
fields.ItemField(
id='1', label='field', type='item',
items=['foo', 'bar', 'baz'],
display_locations=['validation', 'summary', 'listings']),
]
formdef.workflow_roles = {'_receiver': 1}
formdef.store()
formdef.data_class().wipe()
for i in range(3):
formdata = formdef.data_class()()
formdata.data = {}
if i == 0:
formdata.data['1'] = 'foo'
formdata.data['1_display'] = 'foo'
else:
formdata.data['1'] = 'baz'
formdata.data['1_display'] = 'baz'
formdata.jump_status('new')
formdata.store()
formdef = FormDef()
formdef.workflow_roles = {'_receiver': 1}
formdef.name = 'other form'
formdef.fields = []
formdef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
assert resp.text.count('<span>User Label</span>') == 1
assert resp.text.count('<tr') == 4
# columns
resp.forms['listing-settings']['user-label'].checked = False
resp = resp.forms['listing-settings'].submit()
# filters
resp.forms['listing-settings']['filter-1'].checked = True
resp = resp.forms['listing-settings'].submit()
resp.forms['listing-settings']['filter-1-value'] = 'baz'
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<span>User Label</span>') == 0
assert resp.text.count('<tr') == 3
resp.forms['save-custom-view']['title'] = 'custom test view'
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-custom-test-view/')
resp = resp.follow()
assert resp.text.count('<span>User Label</span>') == 0
assert resp.text.count('<tr') == 3
resp.forms['listing-settings']['filter-1-value'] = 'foo'
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<tr') == 2
assert resp.forms['save-custom-view']['update'].checked is True
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-custom-test-view/')
resp = resp.follow()
assert resp.text.count('<tr') == 2
resp = app.get('/backoffice/management/other-form/')
assert 'custom test view' not in resp
# check it's not possible to create a view without any columns
for field_key in resp.forms['listing-settings'].fields:
if not field_key:
continue
if field_key.startswith('filter'):
continue
if resp.forms['listing-settings'][field_key].attrs.get('type') != 'checkbox':
continue
resp.forms['listing-settings'][field_key].checked = False
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'custom test view'
resp = resp.forms['save-custom-view'].submit().follow()
assert 'Views must have at least one column.' in resp.text
def test_backoffice_custom_view_delete(pub):
create_superuser(pub)
FormDef.wipe()
pub.custom_view_class.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = []
formdef.store()
custom_view = pub.custom_view_class()
custom_view.title = 'custom test view'
custom_view.formdef = formdef
custom_view.visibility = 'any'
custom_view.columns = {'list': [{'id': 'id'}]}
custom_view.filters = {}
custom_view.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/custom-test-view/')
resp = resp.click('Delete')
resp = resp.form.submit()
assert resp.location.endswith('/management/form-title/')
resp = resp.follow()
assert 'custom test view' not in resp.text
def test_backoffice_custom_map_view(pub):
user = create_superuser(pub)
FormDef.wipe()
pub.custom_view_class.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = [
fields.StringField(
id='1', label='1st field', type='string',
display_locations=['validation', 'summary', 'listings']),
]
formdef.geolocations = {'base': 'Geolocafoobar'}
formdef.store()
custom_view = pub.custom_view_class()
custom_view.title = 'custom test view'
custom_view.formdef = formdef
custom_view.visibility = 'any'
custom_view.columns = {'list': [{'id': '1'}]}
custom_view.filters = {'filter-1': True, 'filter-1-value': 'baz'}
custom_view.user = user
custom_view.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/custom-test-view/')
resp = resp.click('Plot on a Map')
assert resp.forms['listing-settings']['filter-1-value'].value == 'baz'
def test_backoffice_custom_view_reserved_slug(pub):
create_superuser(pub)
FormDef.wipe()
pub.custom_view_class.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = []
formdef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
resp.forms['listing-settings']['user-label'].checked = False
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'user custom test view'
resp = resp.forms['save-custom-view'].submit()
# check slug not created with "user" as prefix
assert resp.location.endswith('/user-userx-custom-test-view/')
resp = resp.follow()
def test_backoffice_custom_view_visibility(pub):
create_superuser(pub)
FormDef.wipe()
pub.custom_view_class.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = []
formdef.workflow_roles = {'_receiver': 1}
formdef.store()
agent = pub.user_class(name='agent')
agent.roles = [formdef.workflow_roles['_receiver']]
agent.store()
account = PasswordAccount(id='agent')
account.set_password('agent')
account.user_id = agent.id
account.store()
app = login(get_app(pub), username='agent', password='agent')
resp = app.get('/backoffice/management/form-title/')
# columns
resp.forms['listing-settings']['user-label'].checked = False
resp = resp.forms['listing-settings'].submit()
assert resp.text.count('<span>User Label</span>') == 0
resp.forms['save-custom-view']['title'] = 'custom test view'
assert 'visibility' not in resp.forms['save-custom-view'].fields
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-custom-test-view/')
resp = resp.follow()
assert resp.text.count('<span>User Label</span>') == 0
# second agent
agent2 = pub.user_class(name='agent2')
agent2.roles = [formdef.workflow_roles['_receiver']]
agent2.store()
account = PasswordAccount(id='agent2')
account.set_password('agent2')
account.user_id = agent2.id
account.store()
app = login(get_app(pub), username='agent2', password='agent2')
resp = app.get('/backoffice/management/form-title/')
assert 'custom test view' not in resp
# shared custom view
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'shared view'
resp.forms['save-custom-view']['visibility'] = 'any'
resp = resp.forms['save-custom-view'].submit()
app = login(get_app(pub), username='agent2', password='agent2')
resp = app.get('/backoffice/management/form-title/')
resp = resp.click('shared view')
# don't allow a second "any" view with same slug
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/')
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'shared view'
resp.forms['save-custom-view']['visibility'] = 'any'
resp = resp.forms['save-custom-view'].submit()
assert set([(x.slug, x.visibility) for x in get_publisher().custom_view_class.select()]) == set(
[('custom-test-view', 'owner'), ('shared-view', 'any'), ('shared-view-2', 'any')])
def test_backoffice_missing_custom_view(pub):
create_superuser(pub)
FormDef.wipe()
pub.custom_view_class.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = []
formdef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/user-plop/')
assert resp.location == 'http://example.net/backoffice/management/form-title/'
resp = resp.follow()
assert 'A missing or invalid custom view was referenced' in resp
resp = app.get('/backoffice/management/form-title/user-plop/1/')
assert resp.location == 'http://example.net/backoffice/management/form-title/1/'
resp = app.get('/backoffice/management/form-title/user-plop/1/?plop')
assert resp.location == 'http://example.net/backoffice/management/form-title/1/?plop'
def test_carddata_custom_view(pub, studio):
user = create_user(pub)
CardDef.wipe()
pub.custom_view_class.wipe()
carddef = CardDef()
carddef.name = 'foo'
carddef.fields = [
fields.StringField(id='1', label='Test', type='string', varname='foo'),
]
carddef.backoffice_submission_roles = user.roles
carddef.workflow_roles = {'_editor': user.roles[0]}
carddef.store()
app = login(get_app(pub))
resp = app.get('/backoffice/data/foo/')
resp = resp.forms['listing-settings'].submit()
resp.forms['save-custom-view']['title'] = 'card view'
resp = resp.forms['save-custom-view'].submit()
assert resp.location.endswith('/user-card-view/')
resp = resp.follow()
def test_backoffice_custom_view_keep_filters(pub):
user = create_superuser(pub)
datasource = {
'type': 'formula',
'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')])
}
FormDef.wipe()
pub.custom_view_class.wipe()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = [
fields.StringField(
id='1', label='1st field', type='string',
display_locations=['validation', 'summary', 'listings']),
fields.ItemField(
id='2', label='2nd field', type='item',
data_source=datasource, varname='foo'),
]
formdef.store()
custom_view = pub.custom_view_class()
custom_view.title = 'custom test view'
custom_view.formdef = formdef
custom_view.visibility = 'owner'
custom_view.columns = {'list': [{'id': '1'}]}
custom_view.filters = {'filter-1': True, 'filter-1-value': 'baz'}
custom_view.user = user
custom_view.store()
app = login(get_app(pub))
resp = app.get('/backoffice/management/form-title/user-custom-test-view/')
assert 'filter-1-value' in resp.forms['listing-settings'].fields
assert 'filter-2-value' not in resp.forms['listing-settings'].fields
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A')
assert 'filter-1-value' not in resp.forms['listing-settings'].fields
assert 'filter-2-value' in resp.forms['listing-settings'].fields
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A&keep-view-filters=on')
assert 'filter-1-value' in resp.forms['listing-settings'].fields
assert 'filter-2-value' in resp.forms['listing-settings'].fields