0002-misc-split-backoffice-pages-tests.patch
tests/backoffice_pages/test_all.py | ||
---|---|---|
7231 | 7231 |
assert resp.location == 'http://example.net/backoffice/management/form-title/%s/#' % formdata.id |
7232 | 7232 | |
7233 | 7233 | |
7234 |
def test_backoffice_custom_view(pub): |
|
7235 |
create_superuser(pub) |
|
7236 |
create_environment(pub) |
|
7237 | ||
7238 |
app = login(get_app(pub)) |
|
7239 |
resp = app.get('/backoffice/management/form-title/') |
|
7240 |
assert resp.text.count('<span>User Label</span>') == 1 |
|
7241 |
assert resp.text.count('<tr') == 18 |
|
7242 | ||
7243 |
# columns |
|
7244 |
resp.forms['listing-settings']['user-label'].checked = False |
|
7245 |
resp = resp.forms['listing-settings'].submit() |
|
7246 |
# filters |
|
7247 |
resp.forms['listing-settings']['filter-2'].checked = True |
|
7248 |
resp = resp.forms['listing-settings'].submit() |
|
7249 | ||
7250 |
resp.forms['listing-settings']['filter-2-value'] = 'baz' |
|
7251 |
resp = resp.forms['listing-settings'].submit() |
|
7252 | ||
7253 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
7254 |
assert resp.text.count('<tr') == 9 |
|
7255 | ||
7256 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
7257 |
resp = resp.forms['save-custom-view'].submit() |
|
7258 |
assert resp.location.endswith('/user-custom-test-view/') |
|
7259 |
resp = resp.follow() |
|
7260 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
7261 |
assert resp.text.count('<tr') == 9 |
|
7262 | ||
7263 |
resp.forms['listing-settings']['filter-2-value'] = 'foo' |
|
7264 |
resp = resp.forms['listing-settings'].submit() |
|
7265 |
assert resp.text.count('<tr') == 6 |
|
7266 |
assert resp.forms['save-custom-view']['update'].checked is True |
|
7267 |
resp = resp.forms['save-custom-view'].submit() |
|
7268 |
assert resp.location.endswith('/user-custom-test-view/') |
|
7269 |
resp = resp.follow() |
|
7270 |
assert resp.text.count('<tr') == 6 |
|
7271 | ||
7272 |
resp = app.get('/backoffice/management/other-form/') |
|
7273 |
assert 'custom test view' not in resp |
|
7274 | ||
7275 |
# check it's not possible to create a view without any columns |
|
7276 |
for field_key in resp.forms['listing-settings'].fields: |
|
7277 |
if not field_key: |
|
7278 |
continue |
|
7279 |
if field_key.startswith('filter'): |
|
7280 |
continue |
|
7281 |
if resp.forms['listing-settings'][field_key].attrs.get('type') != 'checkbox': |
|
7282 |
continue |
|
7283 |
resp.forms['listing-settings'][field_key].checked = False |
|
7284 |
resp = resp.forms['listing-settings'].submit() |
|
7285 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
7286 |
resp = resp.forms['save-custom-view'].submit().follow() |
|
7287 |
assert 'Views must have at least one column.' in resp.text |
|
7288 | ||
7289 | ||
7290 |
def test_backoffice_custom_view_delete(pub): |
|
7291 |
create_superuser(pub) |
|
7292 |
create_environment(pub) |
|
7293 | ||
7294 |
app = login(get_app(pub)) |
|
7295 |
resp = app.get('/backoffice/management/form-title/') |
|
7296 | ||
7297 |
# columns |
|
7298 |
resp.forms['listing-settings']['user-label'].checked = False |
|
7299 |
resp = resp.forms['listing-settings'].submit() |
|
7300 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
7301 |
resp = resp.forms['save-custom-view'].submit() |
|
7302 |
assert resp.location.endswith('/user-custom-test-view/') |
|
7303 |
resp = resp.follow() |
|
7304 |
resp = resp.click('Delete') |
|
7305 |
resp = resp.form.submit() |
|
7306 |
assert resp.location.endswith('/management/form-title/') |
|
7307 |
resp = resp.follow() |
|
7308 |
assert 'custom test view' not in resp.text |
|
7309 | ||
7310 | ||
7311 |
def test_backoffice_custom_map_view(pub): |
|
7312 |
test_backoffice_custom_view(pub) |
|
7313 | ||
7314 |
formdef = FormDef.get_by_urlname('form-title') |
|
7315 |
formdef.geolocations = {'base': 'Geolocafoobar'} |
|
7316 |
formdef.store() |
|
7317 | ||
7318 |
app = login(get_app(pub)) |
|
7319 |
resp = app.get('/backoffice/management/form-title/') |
|
7320 |
resp = resp.click('custom test view') |
|
7321 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
7322 |
assert resp.text.count('<tr') == 6 |
|
7323 |
resp = resp.click('Plot on a Map') |
|
7324 |
assert resp.forms['listing-settings']['filter-2-value'].value == 'foo' |
|
7325 | ||
7326 | ||
7327 |
def test_backoffice_custom_view_reserved_slug(pub): |
|
7328 |
create_superuser(pub) |
|
7329 |
create_environment(pub) |
|
7330 | ||
7331 |
app = login(get_app(pub)) |
|
7332 |
resp = app.get('/backoffice/management/form-title/') |
|
7333 | ||
7334 |
resp.forms['listing-settings']['user-label'].checked = False |
|
7335 |
resp = resp.forms['listing-settings'].submit() |
|
7336 |
resp.forms['save-custom-view']['title'] = 'user custom test view' |
|
7337 |
resp = resp.forms['save-custom-view'].submit() |
|
7338 |
# check slug not created with "user" as prefix |
|
7339 |
assert resp.location.endswith('/user-userx-custom-test-view/') |
|
7340 |
resp = resp.follow() |
|
7341 | ||
7342 | ||
7343 |
def test_backoffice_custom_view_visibility(pub): |
|
7344 |
create_environment(pub) |
|
7345 |
create_superuser(pub) |
|
7346 | ||
7347 |
formdef = FormDef.get_by_urlname('form-title') |
|
7348 |
agent = pub.user_class(name='agent') |
|
7349 |
agent.roles = [formdef.workflow_roles['_receiver']] |
|
7350 |
agent.store() |
|
7351 | ||
7352 |
account = PasswordAccount(id='agent') |
|
7353 |
account.set_password('agent') |
|
7354 |
account.user_id = agent.id |
|
7355 |
account.store() |
|
7356 | ||
7357 |
app = login(get_app(pub), username='agent', password='agent') |
|
7358 |
resp = app.get('/backoffice/management/form-title/') |
|
7359 | ||
7360 |
# columns |
|
7361 |
resp.forms['listing-settings']['user-label'].checked = False |
|
7362 |
resp = resp.forms['listing-settings'].submit() |
|
7363 | ||
7364 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
7365 | ||
7366 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
7367 |
assert 'visibility' not in resp.forms['save-custom-view'].fields |
|
7368 |
resp = resp.forms['save-custom-view'].submit() |
|
7369 |
assert resp.location.endswith('/user-custom-test-view/') |
|
7370 |
resp = resp.follow() |
|
7371 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
7372 | ||
7373 |
# second agent |
|
7374 |
agent2 = pub.user_class(name='agent2') |
|
7375 |
agent2.roles = [formdef.workflow_roles['_receiver']] |
|
7376 |
agent2.store() |
|
7377 | ||
7378 |
account = PasswordAccount(id='agent2') |
|
7379 |
account.set_password('agent2') |
|
7380 |
account.user_id = agent2.id |
|
7381 |
account.store() |
|
7382 | ||
7383 |
app = login(get_app(pub), username='agent2', password='agent2') |
|
7384 |
resp = app.get('/backoffice/management/form-title/') |
|
7385 |
assert 'custom test view' not in resp |
|
7386 | ||
7387 |
# shared custom view |
|
7388 |
app = login(get_app(pub)) |
|
7389 |
resp = app.get('/backoffice/management/form-title/') |
|
7390 |
resp = resp.forms['listing-settings'].submit() |
|
7391 |
resp.forms['save-custom-view']['title'] = 'shared view' |
|
7392 |
resp.forms['save-custom-view']['visibility'] = 'any' |
|
7393 |
resp = resp.forms['save-custom-view'].submit() |
|
7394 | ||
7395 |
app = login(get_app(pub), username='agent2', password='agent2') |
|
7396 |
resp = app.get('/backoffice/management/form-title/') |
|
7397 |
resp = resp.click('shared view') |
|
7398 | ||
7399 |
# don't allow a second "any" view with same slug |
|
7400 |
app = login(get_app(pub)) |
|
7401 |
resp = app.get('/backoffice/management/form-title/') |
|
7402 |
resp = resp.forms['listing-settings'].submit() |
|
7403 |
resp.forms['save-custom-view']['title'] = 'shared view' |
|
7404 |
resp.forms['save-custom-view']['visibility'] = 'any' |
|
7405 |
resp = resp.forms['save-custom-view'].submit() |
|
7406 |
assert set([(x.slug, x.visibility) for x in get_publisher().custom_view_class.select()]) == set( |
|
7407 |
[('custom-test-view', 'owner'), ('shared-view', 'any'), ('shared-view-2', 'any')]) |
|
7408 | ||
7409 | ||
7410 |
def test_backoffice_missing_custom_view(pub): |
|
7411 |
create_superuser(pub) |
|
7412 |
create_environment(pub, set_receiver=False) |
|
7413 |
app = login(get_app(pub)) |
|
7414 |
resp = app.get('/backoffice/management/form-title/user-plop/') |
|
7415 |
assert resp.location == 'http://example.net/backoffice/management/form-title/' |
|
7416 |
resp = resp.follow() |
|
7417 |
assert 'A missing or invalid custom view was referenced' in resp |
|
7418 | ||
7419 |
resp = app.get('/backoffice/management/form-title/user-plop/1/') |
|
7420 |
assert resp.location == 'http://example.net/backoffice/management/form-title/1/' |
|
7421 | ||
7422 |
resp = app.get('/backoffice/management/form-title/user-plop/1/?plop') |
|
7423 |
assert resp.location == 'http://example.net/backoffice/management/form-title/1/?plop' |
|
7424 | ||
7425 | ||
7426 |
def test_carddata_custom_view(pub, studio): |
|
7427 |
CardDef.wipe() |
|
7428 |
user = create_user(pub) |
|
7429 |
app = login(get_app(pub)) |
|
7430 |
carddef = CardDef() |
|
7431 |
carddef.name = 'foo' |
|
7432 |
carddef.fields = [ |
|
7433 |
fields.StringField(id='1', label='Test', type='string', varname='foo'), |
|
7434 |
] |
|
7435 |
carddef.backoffice_submission_roles = user.roles |
|
7436 |
carddef.workflow_roles = {'_editor': user.roles[0]} |
|
7437 |
carddef.store() |
|
7438 |
carddef.data_class().wipe() |
|
7439 | ||
7440 |
for i in range(50): |
|
7441 |
carddata = carddef.data_class()() |
|
7442 |
carddata.data = {'1': 'FOO %s' % i} |
|
7443 |
carddata.just_created() |
|
7444 |
carddata.store() |
|
7445 | ||
7446 |
resp = app.get('/backoffice/data/foo/') |
|
7447 |
if pub.is_using_postgresql(): |
|
7448 |
assert resp.text.count('<tr') == 21 # header + rows of data |
|
7449 |
else: |
|
7450 |
# no pagination |
|
7451 |
assert resp.text.count('<tr') == 51 # header + rows of data |
|
7452 | ||
7453 |
resp = resp.forms['listing-settings'].submit() |
|
7454 |
resp.forms['save-custom-view']['title'] = 'card view' |
|
7455 |
resp = resp.forms['save-custom-view'].submit() |
|
7456 |
assert resp.location.endswith('/user-card-view/') |
|
7457 |
resp = resp.follow() |
|
7458 | ||
7459 | ||
7460 |
def test_backoffice_custom_view_keep_filters(pub): |
|
7461 |
create_superuser(pub) |
|
7462 |
create_environment(pub) |
|
7463 | ||
7464 |
app = login(get_app(pub)) |
|
7465 |
resp = app.get('/backoffice/management/form-title/') |
|
7466 |
assert resp.text.count('<span>User Label</span>') == 1 |
|
7467 |
assert resp.text.count('<tr') == 18 |
|
7468 | ||
7469 |
# filters |
|
7470 |
resp.forms['listing-settings']['filter-2'].checked = True |
|
7471 |
resp = resp.forms['listing-settings'].submit() |
|
7472 | ||
7473 |
resp.forms['listing-settings']['filter-2-value'] = 'baz' |
|
7474 |
resp = resp.forms['listing-settings'].submit() |
|
7475 | ||
7476 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
7477 |
resp = resp.forms['save-custom-view'].submit() |
|
7478 | ||
7479 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/') |
|
7480 |
assert 'filter-2-value' in resp.forms['listing-settings'].fields |
|
7481 |
assert 'filter-3-value' not in resp.forms['listing-settings'].fields |
|
7482 | ||
7483 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A') |
|
7484 |
assert 'filter-2-value' not in resp.forms['listing-settings'].fields |
|
7485 |
assert 'filter-3-value' in resp.forms['listing-settings'].fields |
|
7486 | ||
7487 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A&keep-view-filters=on') |
|
7488 |
assert 'filter-2-value' in resp.forms['listing-settings'].fields |
|
7489 |
assert 'filter-3-value' in resp.forms['listing-settings'].fields |
|
7490 | ||
7491 | ||
7492 | 7234 |
def test_backoffice_table_varname_filter(pub): |
7493 | 7235 |
create_superuser(pub) |
7494 | 7236 |
create_environment(pub) |
tests/backoffice_pages/test_custom_view.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
import os |
|
3 | ||
4 |
import pytest |
|
5 | ||
6 |
try: |
|
7 |
import xlwt |
|
8 |
except ImportError: |
|
9 |
xlwt = None |
|
10 | ||
11 |
from quixote import get_publisher |
|
12 |
from wcs.qommon.ident.password_accounts import PasswordAccount |
|
13 |
from wcs.qommon.http_request import HTTPRequest |
|
14 |
from wcs.carddef import CardDef |
|
15 |
from wcs.formdef import FormDef |
|
16 |
from wcs import fields |
|
17 | ||
18 |
from utilities import (get_app, login, create_temporary_pub, clean_temporary_pub) |
|
19 |
from test_all import create_user, create_superuser |
|
20 | ||
21 | ||
22 |
def pytest_generate_tests(metafunc): |
|
23 |
if 'pub' in metafunc.fixturenames: |
|
24 |
metafunc.parametrize('pub', ['pickle', 'sql', 'pickle-templates'], indirect=True) |
|
25 | ||
26 | ||
27 |
@pytest.fixture |
|
28 |
def pub(request, emails): |
|
29 |
pub = create_temporary_pub( |
|
30 |
sql_mode=bool('sql' in request.param), |
|
31 |
templates_mode=bool('templates' in request.param) |
|
32 |
) |
|
33 | ||
34 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
|
35 |
pub.set_app_dir(req) |
|
36 |
pub.cfg['identification'] = {'methods': ['password']} |
|
37 |
pub.cfg['language'] = {'language': 'en'} |
|
38 |
pub.write_cfg() |
|
39 |
fd = open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') |
|
40 |
fd.write(''' |
|
41 |
[api-secrets] |
|
42 |
coucou = 1234 |
|
43 |
''') |
|
44 |
fd.close() |
|
45 | ||
46 |
return pub |
|
47 | ||
48 | ||
49 |
def teardown_module(module): |
|
50 |
clean_temporary_pub() |
|
51 | ||
52 | ||
53 |
def test_backoffice_custom_view(pub): |
|
54 |
create_superuser(pub) |
|
55 | ||
56 |
FormDef.wipe() |
|
57 |
pub.custom_view_class.wipe() |
|
58 |
formdef = FormDef() |
|
59 |
formdef.name = 'form title' |
|
60 |
formdef.fields = [ |
|
61 |
fields.ItemField( |
|
62 |
id='1', label='field', type='item', |
|
63 |
items=['foo', 'bar', 'baz'], |
|
64 |
display_locations=['validation', 'summary', 'listings']), |
|
65 |
] |
|
66 |
formdef.workflow_roles = {'_receiver': 1} |
|
67 |
formdef.store() |
|
68 | ||
69 |
formdef.data_class().wipe() |
|
70 |
for i in range(3): |
|
71 |
formdata = formdef.data_class()() |
|
72 |
formdata.data = {} |
|
73 |
if i == 0: |
|
74 |
formdata.data['1'] = 'foo' |
|
75 |
formdata.data['1_display'] = 'foo' |
|
76 |
else: |
|
77 |
formdata.data['1'] = 'baz' |
|
78 |
formdata.data['1_display'] = 'baz' |
|
79 |
formdata.jump_status('new') |
|
80 |
formdata.store() |
|
81 | ||
82 |
formdef = FormDef() |
|
83 |
formdef.workflow_roles = {'_receiver': 1} |
|
84 |
formdef.name = 'other form' |
|
85 |
formdef.fields = [] |
|
86 |
formdef.store() |
|
87 | ||
88 |
app = login(get_app(pub)) |
|
89 |
resp = app.get('/backoffice/management/form-title/') |
|
90 |
assert resp.text.count('<span>User Label</span>') == 1 |
|
91 |
assert resp.text.count('<tr') == 4 |
|
92 | ||
93 |
# columns |
|
94 |
resp.forms['listing-settings']['user-label'].checked = False |
|
95 |
resp = resp.forms['listing-settings'].submit() |
|
96 |
# filters |
|
97 |
resp.forms['listing-settings']['filter-1'].checked = True |
|
98 |
resp = resp.forms['listing-settings'].submit() |
|
99 | ||
100 |
resp.forms['listing-settings']['filter-1-value'] = 'baz' |
|
101 |
resp = resp.forms['listing-settings'].submit() |
|
102 | ||
103 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
104 |
assert resp.text.count('<tr') == 3 |
|
105 | ||
106 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
107 |
resp = resp.forms['save-custom-view'].submit() |
|
108 |
assert resp.location.endswith('/user-custom-test-view/') |
|
109 |
resp = resp.follow() |
|
110 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
111 |
assert resp.text.count('<tr') == 3 |
|
112 | ||
113 |
resp.forms['listing-settings']['filter-1-value'] = 'foo' |
|
114 |
resp = resp.forms['listing-settings'].submit() |
|
115 |
assert resp.text.count('<tr') == 2 |
|
116 |
assert resp.forms['save-custom-view']['update'].checked is True |
|
117 |
resp = resp.forms['save-custom-view'].submit() |
|
118 |
assert resp.location.endswith('/user-custom-test-view/') |
|
119 |
resp = resp.follow() |
|
120 |
assert resp.text.count('<tr') == 2 |
|
121 | ||
122 |
resp = app.get('/backoffice/management/other-form/') |
|
123 |
assert 'custom test view' not in resp |
|
124 | ||
125 |
# check it's not possible to create a view without any columns |
|
126 |
for field_key in resp.forms['listing-settings'].fields: |
|
127 |
if not field_key: |
|
128 |
continue |
|
129 |
if field_key.startswith('filter'): |
|
130 |
continue |
|
131 |
if resp.forms['listing-settings'][field_key].attrs.get('type') != 'checkbox': |
|
132 |
continue |
|
133 |
resp.forms['listing-settings'][field_key].checked = False |
|
134 |
resp = resp.forms['listing-settings'].submit() |
|
135 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
136 |
resp = resp.forms['save-custom-view'].submit().follow() |
|
137 |
assert 'Views must have at least one column.' in resp.text |
|
138 | ||
139 | ||
140 |
def test_backoffice_custom_view_delete(pub): |
|
141 |
create_superuser(pub) |
|
142 | ||
143 |
FormDef.wipe() |
|
144 |
pub.custom_view_class.wipe() |
|
145 |
formdef = FormDef() |
|
146 |
formdef.name = 'form title' |
|
147 |
formdef.fields = [] |
|
148 |
formdef.store() |
|
149 | ||
150 |
app = login(get_app(pub)) |
|
151 |
resp = app.get('/backoffice/management/form-title/') |
|
152 | ||
153 |
# columns |
|
154 |
resp.forms['listing-settings']['user-label'].checked = False |
|
155 |
resp = resp.forms['listing-settings'].submit() |
|
156 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
157 |
resp = resp.forms['save-custom-view'].submit() |
|
158 |
assert resp.location.endswith('/user-custom-test-view/') |
|
159 |
resp = resp.follow() |
|
160 |
resp = resp.click('Delete') |
|
161 |
resp = resp.form.submit() |
|
162 |
assert resp.location.endswith('/management/form-title/') |
|
163 |
resp = resp.follow() |
|
164 |
assert 'custom test view' not in resp.text |
|
165 | ||
166 | ||
167 |
def test_backoffice_custom_map_view(pub): |
|
168 |
create_superuser(pub) |
|
169 | ||
170 |
FormDef.wipe() |
|
171 |
pub.custom_view_class.wipe() |
|
172 |
formdef = FormDef() |
|
173 |
formdef.name = 'form title' |
|
174 |
formdef.fields = [ |
|
175 |
fields.StringField( |
|
176 |
id='1', label='1st field', type='string', |
|
177 |
display_locations=['validation', 'summary', 'listings']), |
|
178 |
] |
|
179 |
formdef.geolocations = {'base': 'Geolocafoobar'} |
|
180 |
formdef.store() |
|
181 | ||
182 |
app = login(get_app(pub)) |
|
183 |
resp = app.get('/backoffice/management/form-title/') |
|
184 |
resp = resp.forms['listing-settings'].submit() |
|
185 |
resp.forms['listing-settings']['filter-1'].checked = True |
|
186 |
resp = resp.forms['listing-settings'].submit() |
|
187 |
resp.forms['listing-settings']['filter-1-value'] = 'baz' |
|
188 |
resp = resp.forms['listing-settings'].submit() |
|
189 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
190 |
resp.forms['save-custom-view']['visibility'] = 'any' |
|
191 |
resp = resp.forms['save-custom-view'].submit() |
|
192 | ||
193 |
resp = app.get('/backoffice/management/form-title/') |
|
194 |
resp = resp.click('custom test view') |
|
195 |
resp = resp.click('Plot on a Map') |
|
196 |
assert resp.forms['listing-settings']['filter-1-value'].value == 'baz' |
|
197 | ||
198 | ||
199 |
def test_backoffice_custom_view_reserved_slug(pub): |
|
200 |
create_superuser(pub) |
|
201 | ||
202 |
FormDef.wipe() |
|
203 |
pub.custom_view_class.wipe() |
|
204 |
formdef = FormDef() |
|
205 |
formdef.name = 'form title' |
|
206 |
formdef.fields = [] |
|
207 |
formdef.store() |
|
208 | ||
209 |
app = login(get_app(pub)) |
|
210 |
resp = app.get('/backoffice/management/form-title/') |
|
211 | ||
212 |
resp.forms['listing-settings']['user-label'].checked = False |
|
213 |
resp = resp.forms['listing-settings'].submit() |
|
214 |
resp.forms['save-custom-view']['title'] = 'user custom test view' |
|
215 |
resp = resp.forms['save-custom-view'].submit() |
|
216 |
# check slug not created with "user" as prefix |
|
217 |
assert resp.location.endswith('/user-userx-custom-test-view/') |
|
218 |
resp = resp.follow() |
|
219 | ||
220 | ||
221 |
def test_backoffice_custom_view_visibility(pub): |
|
222 |
create_superuser(pub) |
|
223 | ||
224 |
FormDef.wipe() |
|
225 |
pub.custom_view_class.wipe() |
|
226 |
formdef = FormDef() |
|
227 |
formdef.name = 'form title' |
|
228 |
formdef.fields = [] |
|
229 |
formdef.workflow_roles = {'_receiver': 1} |
|
230 |
formdef.store() |
|
231 | ||
232 |
agent = pub.user_class(name='agent') |
|
233 |
agent.roles = [formdef.workflow_roles['_receiver']] |
|
234 |
agent.store() |
|
235 | ||
236 |
account = PasswordAccount(id='agent') |
|
237 |
account.set_password('agent') |
|
238 |
account.user_id = agent.id |
|
239 |
account.store() |
|
240 | ||
241 |
app = login(get_app(pub), username='agent', password='agent') |
|
242 |
resp = app.get('/backoffice/management/form-title/') |
|
243 | ||
244 |
# columns |
|
245 |
resp.forms['listing-settings']['user-label'].checked = False |
|
246 |
resp = resp.forms['listing-settings'].submit() |
|
247 | ||
248 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
249 | ||
250 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
251 |
assert 'visibility' not in resp.forms['save-custom-view'].fields |
|
252 |
resp = resp.forms['save-custom-view'].submit() |
|
253 |
assert resp.location.endswith('/user-custom-test-view/') |
|
254 |
resp = resp.follow() |
|
255 |
assert resp.text.count('<span>User Label</span>') == 0 |
|
256 | ||
257 |
# second agent |
|
258 |
agent2 = pub.user_class(name='agent2') |
|
259 |
agent2.roles = [formdef.workflow_roles['_receiver']] |
|
260 |
agent2.store() |
|
261 | ||
262 |
account = PasswordAccount(id='agent2') |
|
263 |
account.set_password('agent2') |
|
264 |
account.user_id = agent2.id |
|
265 |
account.store() |
|
266 | ||
267 |
app = login(get_app(pub), username='agent2', password='agent2') |
|
268 |
resp = app.get('/backoffice/management/form-title/') |
|
269 |
assert 'custom test view' not in resp |
|
270 | ||
271 |
# shared custom view |
|
272 |
app = login(get_app(pub)) |
|
273 |
resp = app.get('/backoffice/management/form-title/') |
|
274 |
resp = resp.forms['listing-settings'].submit() |
|
275 |
resp.forms['save-custom-view']['title'] = 'shared view' |
|
276 |
resp.forms['save-custom-view']['visibility'] = 'any' |
|
277 |
resp = resp.forms['save-custom-view'].submit() |
|
278 | ||
279 |
app = login(get_app(pub), username='agent2', password='agent2') |
|
280 |
resp = app.get('/backoffice/management/form-title/') |
|
281 |
resp = resp.click('shared view') |
|
282 | ||
283 |
# don't allow a second "any" view with same slug |
|
284 |
app = login(get_app(pub)) |
|
285 |
resp = app.get('/backoffice/management/form-title/') |
|
286 |
resp = resp.forms['listing-settings'].submit() |
|
287 |
resp.forms['save-custom-view']['title'] = 'shared view' |
|
288 |
resp.forms['save-custom-view']['visibility'] = 'any' |
|
289 |
resp = resp.forms['save-custom-view'].submit() |
|
290 |
assert set([(x.slug, x.visibility) for x in get_publisher().custom_view_class.select()]) == set( |
|
291 |
[('custom-test-view', 'owner'), ('shared-view', 'any'), ('shared-view-2', 'any')]) |
|
292 | ||
293 | ||
294 |
def test_backoffice_missing_custom_view(pub): |
|
295 |
create_superuser(pub) |
|
296 | ||
297 |
FormDef.wipe() |
|
298 |
pub.custom_view_class.wipe() |
|
299 |
formdef = FormDef() |
|
300 |
formdef.name = 'form title' |
|
301 |
formdef.fields = [] |
|
302 |
formdef.store() |
|
303 | ||
304 |
app = login(get_app(pub)) |
|
305 |
resp = app.get('/backoffice/management/form-title/user-plop/') |
|
306 |
assert resp.location == 'http://example.net/backoffice/management/form-title/' |
|
307 |
resp = resp.follow() |
|
308 |
assert 'A missing or invalid custom view was referenced' in resp |
|
309 | ||
310 |
resp = app.get('/backoffice/management/form-title/user-plop/1/') |
|
311 |
assert resp.location == 'http://example.net/backoffice/management/form-title/1/' |
|
312 | ||
313 |
resp = app.get('/backoffice/management/form-title/user-plop/1/?plop') |
|
314 |
assert resp.location == 'http://example.net/backoffice/management/form-title/1/?plop' |
|
315 | ||
316 | ||
317 |
def test_carddata_custom_view(pub, studio): |
|
318 |
CardDef.wipe() |
|
319 |
user = create_user(pub) |
|
320 |
app = login(get_app(pub)) |
|
321 |
carddef = CardDef() |
|
322 |
carddef.name = 'foo' |
|
323 |
carddef.fields = [ |
|
324 |
fields.StringField(id='1', label='Test', type='string', varname='foo'), |
|
325 |
] |
|
326 |
carddef.backoffice_submission_roles = user.roles |
|
327 |
carddef.workflow_roles = {'_editor': user.roles[0]} |
|
328 |
carddef.store() |
|
329 |
carddef.data_class().wipe() |
|
330 | ||
331 |
for i in range(50): |
|
332 |
carddata = carddef.data_class()() |
|
333 |
carddata.data = {'1': 'FOO %s' % i} |
|
334 |
carddata.just_created() |
|
335 |
carddata.store() |
|
336 | ||
337 |
resp = app.get('/backoffice/data/foo/') |
|
338 |
if pub.is_using_postgresql(): |
|
339 |
assert resp.text.count('<tr') == 21 # header + rows of data |
|
340 |
else: |
|
341 |
# no pagination |
|
342 |
assert resp.text.count('<tr') == 51 # header + rows of data |
|
343 | ||
344 |
resp = resp.forms['listing-settings'].submit() |
|
345 |
resp.forms['save-custom-view']['title'] = 'card view' |
|
346 |
resp = resp.forms['save-custom-view'].submit() |
|
347 |
assert resp.location.endswith('/user-card-view/') |
|
348 |
resp = resp.follow() |
|
349 | ||
350 | ||
351 |
def test_backoffice_custom_view_keep_filters(pub): |
|
352 |
create_superuser(pub) |
|
353 |
datasource = { |
|
354 |
'type': 'formula', |
|
355 |
'value': repr([('A', 'aa'), ('B', 'bb'), ('C', 'cc')]) |
|
356 |
} |
|
357 |
FormDef.wipe() |
|
358 |
pub.custom_view_class.wipe() |
|
359 |
formdef = FormDef() |
|
360 |
formdef.name = 'form title' |
|
361 |
formdef.fields = [ |
|
362 |
fields.StringField( |
|
363 |
id='1', label='1st field', type='string', |
|
364 |
display_locations=['validation', 'summary', 'listings']), |
|
365 |
fields.ItemField( |
|
366 |
id='2', label='2nd field', type='item', |
|
367 |
data_source=datasource, varname='foo'), |
|
368 |
] |
|
369 |
formdef.store() |
|
370 | ||
371 |
app = login(get_app(pub)) |
|
372 |
resp = app.get('/backoffice/management/form-title/') |
|
373 | ||
374 |
# filters |
|
375 |
resp.forms['listing-settings']['filter-1'].checked = True |
|
376 |
resp = resp.forms['listing-settings'].submit() |
|
377 |
resp.forms['listing-settings']['filter-1-value'] = 'baz' |
|
378 |
resp = resp.forms['listing-settings'].submit() |
|
379 |
resp.forms['save-custom-view']['title'] = 'custom test view' |
|
380 |
resp = resp.forms['save-custom-view'].submit() |
|
381 | ||
382 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/') |
|
383 |
assert 'filter-1-value' in resp.forms['listing-settings'].fields |
|
384 |
assert 'filter-2-value' not in resp.forms['listing-settings'].fields |
|
385 | ||
386 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A') |
|
387 |
assert 'filter-1-value' not in resp.forms['listing-settings'].fields |
|
388 |
assert 'filter-2-value' in resp.forms['listing-settings'].fields |
|
389 | ||
390 |
resp = app.get('/backoffice/management/form-title/user-custom-test-view/?filter-foo=A&keep-view-filters=on') |
|
391 |
assert 'filter-1-value' in resp.forms['listing-settings'].fields |
|
392 |
assert 'filter-2-value' in resp.forms['listing-settings'].fields |
|
0 |
- |