0008-tests-simplify-pub-fixtures-as-sql-is-the-new-defaul.patch
tests/admin_pages/test_all.py | ||
---|---|---|
10 | 10 | |
11 | 11 |
@pytest.fixture |
12 | 12 |
def pub(request): |
13 |
pub = create_temporary_pub(sql_mode=True)
|
|
13 |
pub = create_temporary_pub() |
|
14 | 14 | |
15 | 15 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
16 | 16 |
pub.set_app_dir(req) |
tests/admin_pages/test_api_access.py | ||
---|---|---|
25 | 25 | |
26 | 26 |
@pytest.fixture |
27 | 27 |
def pub(request): |
28 |
pub = create_temporary_pub(sql_mode=True)
|
|
28 |
pub = create_temporary_pub() |
|
29 | 29 | |
30 | 30 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
31 | 31 |
pub.set_app_dir(req) |
tests/admin_pages/test_block.py | ||
---|---|---|
17 | 17 | |
18 | 18 |
@pytest.fixture |
19 | 19 |
def pub(request): |
20 |
pub = create_temporary_pub(sql_mode=True)
|
|
20 |
pub = create_temporary_pub() |
|
21 | 21 | |
22 | 22 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
23 | 23 |
pub.set_app_dir(req) |
tests/admin_pages/test_card.py | ||
---|---|---|
19 | 19 |
from .test_all import create_superuser |
20 | 20 | |
21 | 21 | |
22 |
def pub_fixture(**kwargs): |
|
23 |
pub = create_temporary_pub(**kwargs) |
|
22 |
@pytest.fixture |
|
23 |
def pub(emails): |
|
24 |
pub = create_temporary_pub() |
|
24 | 25 | |
25 | 26 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
26 | 27 |
pub.set_app_dir(req) |
... | ... | |
31 | 32 |
return pub |
32 | 33 | |
33 | 34 | |
34 |
@pytest.fixture |
|
35 |
def pub(request, emails): |
|
36 |
return pub_fixture(sql_mode=True) |
|
37 | ||
38 | ||
39 | 35 |
def teardown_module(module): |
40 | 36 |
clean_temporary_pub() |
41 | 37 |
tests/admin_pages/test_carddefcategory.py | ||
---|---|---|
11 | 11 | |
12 | 12 |
@pytest.fixture |
13 | 13 |
def pub(request): |
14 |
pub = create_temporary_pub(sql_mode=True)
|
|
14 |
pub = create_temporary_pub() |
|
15 | 15 | |
16 | 16 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
17 | 17 |
pub.set_app_dir(req) |
tests/admin_pages/test_category.py | ||
---|---|---|
10 | 10 | |
11 | 11 |
@pytest.fixture |
12 | 12 |
def pub(request): |
13 |
pub = create_temporary_pub(sql_mode=True)
|
|
13 |
pub = create_temporary_pub() |
|
14 | 14 | |
15 | 15 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
16 | 16 |
pub.set_app_dir(req) |
tests/admin_pages/test_datasource.py | ||
---|---|---|
21 | 21 |
from .test_all import create_superuser |
22 | 22 | |
23 | 23 | |
24 |
def pub_fixture(**kwargs): |
|
25 |
pub = create_temporary_pub(**kwargs) |
|
24 |
@pytest.fixture |
|
25 |
def pub(emails): |
|
26 |
pub = create_temporary_pub() |
|
26 | 27 | |
27 | 28 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
28 | 29 |
pub.set_app_dir(req) |
... | ... | |
33 | 34 |
return pub |
34 | 35 | |
35 | 36 | |
36 |
@pytest.fixture |
|
37 |
def pub(request, emails): |
|
38 |
return pub_fixture(sql_mode=True) |
|
39 | ||
40 | ||
41 | 37 |
def teardown_module(module): |
42 | 38 |
clean_temporary_pub() |
43 | 39 |
tests/admin_pages/test_deprecations.py | ||
---|---|---|
29 | 29 | |
30 | 30 |
@pytest.fixture |
31 | 31 |
def pub(request): |
32 |
pub = create_temporary_pub(sql_mode=True)
|
|
32 |
pub = create_temporary_pub() |
|
33 | 33 | |
34 | 34 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
35 | 35 |
pub.set_app_dir(req) |
tests/admin_pages/test_form.py | ||
---|---|---|
23 | 23 |
from .test_all import create_role, create_superuser |
24 | 24 | |
25 | 25 | |
26 |
def pub_fixture(**kwargs): |
|
27 |
pub = create_temporary_pub(**kwargs) |
|
26 |
@pytest.fixture |
|
27 |
def pub(emails): |
|
28 |
pub = create_temporary_pub() |
|
28 | 29 | |
29 | 30 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
30 | 31 |
pub.set_app_dir(req) |
... | ... | |
35 | 36 |
return pub |
36 | 37 | |
37 | 38 | |
38 |
@pytest.fixture |
|
39 |
def pub(request, emails): |
|
40 |
return pub_fixture(sql_mode=True) |
|
41 | ||
42 | ||
43 | 39 |
def teardown_module(module): |
44 | 40 |
clean_temporary_pub() |
45 | 41 |
tests/admin_pages/test_logged_errors.py | ||
---|---|---|
13 | 13 | |
14 | 14 |
@pytest.fixture |
15 | 15 |
def pub(request): |
16 |
pub = create_temporary_pub(sql_mode=True)
|
|
16 |
pub = create_temporary_pub() |
|
17 | 17 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
18 | 18 |
pub.set_app_dir(req) |
19 | 19 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/admin_pages/test_role.py | ||
---|---|---|
9 | 9 | |
10 | 10 |
@pytest.fixture |
11 | 11 |
def pub(request): |
12 |
pub = create_temporary_pub(sql_mode=True)
|
|
12 |
pub = create_temporary_pub() |
|
13 | 13 | |
14 | 14 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
15 | 15 |
pub.set_app_dir(req) |
tests/admin_pages/test_settings.py | ||
---|---|---|
32 | 32 | |
33 | 33 | |
34 | 34 |
@pytest.fixture |
35 |
def pub(request):
|
|
36 |
pub = create_temporary_pub(sql_mode=True)
|
|
35 |
def pub(): |
|
36 |
pub = create_temporary_pub() |
|
37 | 37 | |
38 | 38 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
39 | 39 |
pub.set_app_dir(req) |
tests/admin_pages/test_studio.py | ||
---|---|---|
17 | 17 |
from .test_all import create_superuser |
18 | 18 | |
19 | 19 | |
20 |
def pub_fixture(**kwargs): |
|
21 |
pub = create_temporary_pub(**kwargs) |
|
20 |
@pytest.fixture |
|
21 |
def pub(): |
|
22 |
pub = create_temporary_pub() |
|
22 | 23 | |
23 | 24 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
24 | 25 |
pub.set_app_dir(req) |
... | ... | |
29 | 30 |
return pub |
30 | 31 | |
31 | 32 | |
32 |
@pytest.fixture |
|
33 |
def pub(request): |
|
34 |
return pub_fixture(sql_mode=True) |
|
35 | ||
36 | ||
37 |
@pytest.fixture |
|
38 |
def sql_pub(request): |
|
39 |
return pub_fixture(sql_mode=True) |
|
40 | ||
41 | ||
42 | 33 |
def teardown_module(module): |
43 | 34 |
clean_temporary_pub() |
44 | 35 | |
... | ... | |
98 | 89 |
assert '../settings/' not in resp.text |
99 | 90 | |
100 | 91 | |
101 |
def test_studio_home_recent_errors(sql_pub): |
|
102 |
pub = sql_pub |
|
92 |
def test_studio_home_recent_errors(pub): |
|
103 | 93 |
create_superuser(pub) |
104 | 94 | |
105 | 95 |
app = login(get_app(pub)) |
... | ... | |
135 | 125 |
assert 'logged-errors/%s/' % errors[5].id in resp |
136 | 126 | |
137 | 127 | |
138 |
def test_studio_home_recent_changes(sql_pub): |
|
139 |
pub = sql_pub |
|
128 |
def test_studio_home_recent_changes(pub): |
|
140 | 129 |
create_superuser(pub) |
141 | 130 | |
142 | 131 |
BlockDef.wipe() |
tests/admin_pages/test_user.py | ||
---|---|---|
11 | 11 | |
12 | 12 |
@pytest.fixture |
13 | 13 |
def pub(request): |
14 |
pub = create_temporary_pub(sql_mode=True)
|
|
14 |
pub = create_temporary_pub() |
|
15 | 15 | |
16 | 16 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
17 | 17 |
pub.set_app_dir(req) |
tests/admin_pages/test_workflow.py | ||
---|---|---|
32 | 32 | |
33 | 33 |
@pytest.fixture |
34 | 34 |
def pub(request): |
35 |
pub = create_temporary_pub(sql_mode=True)
|
|
35 |
pub = create_temporary_pub() |
|
36 | 36 | |
37 | 37 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
38 | 38 |
pub.set_app_dir(req) |
tests/admin_pages/test_wscall.py | ||
---|---|---|
13 | 13 | |
14 | 14 |
@pytest.fixture |
15 | 15 |
def pub(request): |
16 |
pub = create_temporary_pub(sql_mode=True)
|
|
16 |
pub = create_temporary_pub() |
|
17 | 17 | |
18 | 18 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
19 | 19 |
pub.set_app_dir(req) |
tests/api/test_access.py | ||
---|---|---|
19 | 19 | |
20 | 20 | |
21 | 21 |
@pytest.fixture |
22 |
def pub(request, emails):
|
|
23 |
pub = create_temporary_pub(sql_mode=True)
|
|
22 |
def pub(emails): |
|
23 |
pub = create_temporary_pub() |
|
24 | 24 | |
25 | 25 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
26 | 26 |
pub.set_app_dir(req) |
... | ... | |
72 | 72 |
return user |
73 | 73 | |
74 | 74 | |
75 |
@pytest.fixture(params=['sql', 'pickle'])
|
|
76 |
def no_request_pub(request):
|
|
77 |
pub = create_temporary_pub(sql_mode=bool(request.param == 'sql'))
|
|
75 |
@pytest.fixture |
|
76 |
def no_request_pub(): |
|
77 |
pub = create_temporary_pub() |
|
78 | 78 |
pub.app_dir = os.path.join(pub.APP_DIR, 'example.net') |
79 | 79 |
pub.set_config() |
80 | 80 |
tests/api/test_all.py | ||
---|---|---|
15 | 15 | |
16 | 16 | |
17 | 17 |
@pytest.fixture |
18 |
def pub(request, emails):
|
|
19 |
pub = create_temporary_pub(sql_mode=True)
|
|
18 |
def pub(emails): |
|
19 |
pub = create_temporary_pub() |
|
20 | 20 | |
21 | 21 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
22 | 22 |
pub.set_app_dir(req) |
tests/api/test_carddef.py | ||
---|---|---|
28 | 28 | |
29 | 29 | |
30 | 30 |
@pytest.fixture |
31 |
def pub(request, emails):
|
|
32 |
pub = create_temporary_pub(sql_mode=True)
|
|
31 |
def pub(emails): |
|
32 |
pub = create_temporary_pub() |
|
33 | 33 | |
34 | 34 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
35 | 35 |
pub.set_app_dir(req) |
tests/api/test_category.py | ||
---|---|---|
12 | 12 | |
13 | 13 | |
14 | 14 |
@pytest.fixture |
15 |
def pub(request, emails):
|
|
16 |
pub = create_temporary_pub(sql_mode=True)
|
|
15 |
def pub(emails): |
|
16 |
pub = create_temporary_pub() |
|
17 | 17 | |
18 | 18 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
19 | 19 |
pub.set_app_dir(req) |
tests/api/test_custom_view.py | ||
---|---|---|
17 | 17 | |
18 | 18 | |
19 | 19 |
@pytest.fixture |
20 |
def pub(request, emails):
|
|
21 |
pub = create_temporary_pub(sql_mode=True)
|
|
20 |
def pub(emails): |
|
21 |
pub = create_temporary_pub() |
|
22 | 22 | |
23 | 23 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
24 | 24 |
pub.set_app_dir(req) |
tests/api/test_export_import.py | ||
---|---|---|
21 | 21 | |
22 | 22 |
@pytest.fixture |
23 | 23 |
def pub(): |
24 |
pub = create_temporary_pub(sql_mode=True)
|
|
24 |
pub = create_temporary_pub() |
|
25 | 25 |
with open(os.path.join(pub.app_dir, 'site-options.cfg'), 'w') as fd: |
26 | 26 |
fd.write( |
27 | 27 |
'''\ |
tests/api/test_formdata.py | ||
---|---|---|
30 | 30 | |
31 | 31 | |
32 | 32 |
@pytest.fixture |
33 |
def pub(request, emails):
|
|
34 |
pub = create_temporary_pub(sql_mode=True)
|
|
33 |
def pub(emails): |
|
34 |
pub = create_temporary_pub() |
|
35 | 35 | |
36 | 36 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
37 | 37 |
pub.set_app_dir(req) |
tests/api/test_formdef.py | ||
---|---|---|
27 | 27 | |
28 | 28 | |
29 | 29 |
@pytest.fixture |
30 |
def pub(request, emails):
|
|
31 |
pub = create_temporary_pub(sql_mode=True)
|
|
30 |
def pub(emails): |
|
31 |
pub = create_temporary_pub() |
|
32 | 32 | |
33 | 33 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
34 | 34 |
pub.set_app_dir(req) |
tests/api/test_statistics.py | ||
---|---|---|
17 | 17 | |
18 | 18 |
@pytest.fixture |
19 | 19 |
def pub(): |
20 |
pub = create_temporary_pub(sql_mode=True)
|
|
20 |
pub = create_temporary_pub() |
|
21 | 21 |
BlockDef.wipe() |
22 | 22 |
Category.wipe() |
23 | 23 |
FormDef.wipe() |
tests/api/test_user.py | ||
---|---|---|
20 | 20 | |
21 | 21 | |
22 | 22 |
@pytest.fixture |
23 |
def pub(request, emails):
|
|
24 |
pub = create_temporary_pub(sql_mode=True)
|
|
23 |
def pub(emails): |
|
24 |
pub = create_temporary_pub() |
|
25 | 25 | |
26 | 26 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
27 | 27 |
pub.set_app_dir(req) |
tests/api/test_workflow.py | ||
---|---|---|
17 | 17 | |
18 | 18 | |
19 | 19 |
@pytest.fixture |
20 |
def pub(request, emails):
|
|
21 |
pub = create_temporary_pub(sql_mode=True)
|
|
20 |
def pub(emails): |
|
21 |
pub = create_temporary_pub() |
|
22 | 22 | |
23 | 23 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
24 | 24 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_all.py | ||
---|---|---|
30 | 30 | |
31 | 31 | |
32 | 32 |
@pytest.fixture |
33 |
def pub(request, emails):
|
|
34 |
pub = create_temporary_pub(sql_mode=True)
|
|
33 |
def pub(emails): |
|
34 |
pub = create_temporary_pub() |
|
35 | 35 | |
36 | 36 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
37 | 37 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_carddata.py | ||
---|---|---|
18 | 18 | |
19 | 19 | |
20 | 20 |
@pytest.fixture |
21 |
def pub(request, emails):
|
|
22 |
pub = create_temporary_pub(sql_mode=True)
|
|
21 |
def pub(emails): |
|
22 |
pub = create_temporary_pub() |
|
23 | 23 | |
24 | 24 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
25 | 25 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_columns.py | ||
---|---|---|
17 | 17 | |
18 | 18 | |
19 | 19 |
@pytest.fixture |
20 |
def pub(request, emails):
|
|
21 |
pub = create_temporary_pub(sql_mode=True)
|
|
20 |
def pub(emails): |
|
21 |
pub = create_temporary_pub() |
|
22 | 22 | |
23 | 23 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
24 | 24 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_custom_view.py | ||
---|---|---|
15 | 15 | |
16 | 16 | |
17 | 17 |
@pytest.fixture |
18 |
def pub(request, emails):
|
|
19 |
pub = create_temporary_pub(sql_mode=True)
|
|
18 |
def pub(emails): |
|
19 |
pub = create_temporary_pub() |
|
20 | 20 | |
21 | 21 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
22 | 22 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_export.py | ||
---|---|---|
20 | 20 | |
21 | 21 | |
22 | 22 |
@pytest.fixture |
23 |
def pub(request, emails):
|
|
24 |
pub = create_temporary_pub(sql_mode=True)
|
|
23 |
def pub(emails): |
|
24 |
pub = create_temporary_pub() |
|
25 | 25 | |
26 | 26 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
27 | 27 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_filters.py | ||
---|---|---|
17 | 17 | |
18 | 18 | |
19 | 19 |
@pytest.fixture |
20 |
def pub(request, emails):
|
|
21 |
pub = create_temporary_pub(sql_mode=True)
|
|
20 |
def pub(emails): |
|
21 |
pub = create_temporary_pub() |
|
22 | 22 | |
23 | 23 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
24 | 24 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_form_inspect.py | ||
---|---|---|
19 | 19 | |
20 | 20 | |
21 | 21 |
@pytest.fixture |
22 |
def pub(request, emails):
|
|
23 |
pub = create_temporary_pub(sql_mode=True)
|
|
22 |
def pub(emails): |
|
23 |
pub = create_temporary_pub() |
|
24 | 24 | |
25 | 25 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
26 | 26 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/backoffice_pages/test_sort.py | ||
---|---|---|
16 | 16 | |
17 | 17 | |
18 | 18 |
@pytest.fixture |
19 |
def pub(request, emails):
|
|
20 |
pub = create_temporary_pub(sql_mode=True)
|
|
19 |
def pub(emails): |
|
20 |
pub = create_temporary_pub() |
|
21 | 21 | |
22 | 22 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
23 | 23 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_statistics.py | ||
---|---|---|
11 | 11 | |
12 | 12 | |
13 | 13 |
@pytest.fixture |
14 |
def pub(request, emails):
|
|
15 |
pub = create_temporary_pub(sql_mode=True)
|
|
14 |
def pub(emails): |
|
15 |
pub = create_temporary_pub() |
|
16 | 16 | |
17 | 17 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
18 | 18 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_submission.py | ||
---|---|---|
18 | 18 | |
19 | 19 | |
20 | 20 |
@pytest.fixture |
21 |
def pub(request, emails):
|
|
22 |
pub = create_temporary_pub(sql_mode=True)
|
|
21 |
def pub(emails): |
|
22 |
pub = create_temporary_pub() |
|
23 | 23 | |
24 | 24 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
25 | 25 |
pub.set_app_dir(req) |
tests/backoffice_pages/test_workflow_inspect.py | ||
---|---|---|
15 | 15 | |
16 | 16 | |
17 | 17 |
@pytest.fixture |
18 |
def pub(request, emails):
|
|
19 |
pub = create_temporary_pub(sql_mode=True)
|
|
18 |
def pub(emails): |
|
19 |
pub = create_temporary_pub() |
|
20 | 20 | |
21 | 21 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
22 | 22 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/form_pages/test_all.py | ||
---|---|---|
65 | 65 |
metafunc.parametrize('pub', ['sql', 'sql-lazy'], indirect=True) |
66 | 66 | |
67 | 67 | |
68 |
def pub_fixture(**kwargs): |
|
69 |
pub = create_temporary_pub(**kwargs) |
|
68 |
@pytest.fixture |
|
69 |
def pub(request): |
|
70 |
pub = create_temporary_pub(lazy_mode=bool('lazy' in request.param)) |
|
70 | 71 |
pub.cfg['identification'] = {'methods': ['password']} |
71 | 72 |
pub.cfg['language'] = {'language': 'en'} |
72 | 73 |
pub.write_cfg() |
... | ... | |
78 | 79 |
return pub |
79 | 80 | |
80 | 81 | |
81 |
@pytest.fixture |
|
82 |
def pub(request, emails): |
|
83 |
return pub_fixture(sql_mode=bool('sql' in request.param), lazy_mode=bool('lazy' in request.param)) |
|
84 | ||
85 | ||
86 |
@pytest.fixture |
|
87 |
def sql_pub(request, emails): |
|
88 |
return pub_fixture(sql_mode=True) |
|
89 | ||
90 | ||
91 | 82 |
@pytest.fixture |
92 | 83 |
def error_email(pub): |
93 | 84 |
pub.cfg['debug'] = {'error_email': 'errors@localhost.invalid'} |
... | ... | |
4732 | 4723 |
assert len(orders.keys()) > 1 |
4733 | 4724 | |
4734 | 4725 | |
4735 |
def test_form_autosave(sql_pub): |
|
4736 |
pub = sql_pub |
|
4726 |
def test_form_autosave(pub): |
|
4737 | 4727 |
formdef = create_formdef() |
4738 | 4728 |
formdef.fields = [ |
4739 | 4729 |
fields.PageField(id='0', label='1st page', type='page'), |
tests/form_pages/test_block.py | ||
---|---|---|
25 | 25 |
@pytest.fixture |
26 | 26 |
def pub(request, emails): |
27 | 27 |
pub = create_temporary_pub( |
28 |
sql_mode=bool('sql' in request.param), |
|
29 | 28 |
lazy_mode=bool('lazy' in request.param), |
30 | 29 |
) |
31 | 30 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/form_pages/test_computed_field.py | ||
---|---|---|
16 | 16 | |
17 | 17 | |
18 | 18 |
@pytest.fixture |
19 |
def pub(request, emails):
|
|
20 |
pub = create_temporary_pub(sql_mode=True)
|
|
19 |
def pub(emails): |
|
20 |
pub = create_temporary_pub() |
|
21 | 21 |
pub.cfg['identification'] = {'methods': ['password']} |
22 | 22 |
pub.cfg['language'] = {'language': 'en'} |
23 | 23 |
pub.write_cfg() |
tests/form_pages/test_file_field.py | ||
---|---|---|
28 | 28 |
@pytest.fixture |
29 | 29 |
def pub(request): |
30 | 30 |
pub = create_temporary_pub( |
31 |
sql_mode=bool('sql' in request.param), |
|
32 | 31 |
lazy_mode=bool('lazy' in request.param), |
33 | 32 |
) |
34 | 33 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/form_pages/test_formdata.py | ||
---|---|---|
35 | 35 |
@pytest.fixture |
36 | 36 |
def pub(request, emails): |
37 | 37 |
pub = create_temporary_pub( |
38 |
sql_mode=bool('sql' in request.param), |
|
39 | 38 |
lazy_mode=bool('lazy' in request.param), |
40 | 39 |
) |
41 | 40 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/form_pages/test_live.py | ||
---|---|---|
27 | 27 |
@pytest.fixture |
28 | 28 |
def pub(request): |
29 | 29 |
pub = create_temporary_pub( |
30 |
sql_mode=bool('sql' in request.param), |
|
31 | 30 |
lazy_mode=bool('lazy' in request.param), |
32 | 31 |
) |
33 | 32 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/test_auth_pages.py | ||
---|---|---|
9 | 9 | |
10 | 10 |
@pytest.fixture |
11 | 11 |
def pub(): |
12 |
pub = create_temporary_pub(sql_mode=True)
|
|
12 |
pub = create_temporary_pub() |
|
13 | 13 |
pub.cfg['identification'] = {'methods': ['password']} |
14 | 14 |
pub.cfg['language'] = {'language': 'en'} |
15 | 15 |
pub.write_cfg() |
tests/test_carddef.py | ||
---|---|---|
17 | 17 | |
18 | 18 |
@pytest.fixture |
19 | 19 |
def pub(request): |
20 |
pub = create_temporary_pub(sql_mode=True)
|
|
20 |
pub = create_temporary_pub() |
|
21 | 21 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
22 | 22 |
pub.set_app_dir(req) |
23 | 23 |
pub.cfg['language'] = {'language': 'en'} |
tests/test_categories.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
global pub |
18 | 18 | |
19 |
pub = create_temporary_pub(sql_mode=True)
|
|
19 |
pub = create_temporary_pub() |
|
20 | 20 | |
21 | 21 | |
22 | 22 |
def teardown_module(module): |
tests/test_convert_to_sql.py | ||
---|---|---|
85 | 85 | |
86 | 86 |
@pytest.fixture() |
87 | 87 |
def pub(request): |
88 |
pub = create_temporary_pub(sql_mode=False)
|
|
88 |
pub = create_temporary_pub(pickle_mode=True)
|
|
89 | 89 |
yield pub |
90 | 90 |
clean_temporary_pub() |
91 | 91 | |
... | ... | |
125 | 125 | |
126 | 126 | |
127 | 127 |
def test_already_migrated_fails(): |
128 |
create_temporary_pub(sql_mode=True)
|
|
128 |
create_temporary_pub() |
|
129 | 129 |
with pytest.raises(CommandError) as excinfo: |
130 | 130 |
call_command('convert_to_sql', '-d', 'example.net', '--database', 'foobar') |
131 | 131 |
assert str(excinfo.value) == 'tenant already using postgresql' |
tests/test_ctl.py | ||
---|---|---|
28 | 28 | |
29 | 29 |
@pytest.fixture |
30 | 30 |
def pub(): |
31 |
yield create_temporary_pub() |
|
32 |
clean_temporary_pub() |
|
33 | ||
34 | ||
35 |
@pytest.fixture |
|
36 |
def sql_pub(): |
|
37 |
yield create_temporary_pub(sql_mode=True) |
|
38 |
clean_temporary_pub() |
|
39 | ||
40 | ||
41 |
@pytest.fixture |
|
42 |
def two_pubs(request): |
|
43 |
pub = create_temporary_pub(sql_mode=True) |
|
31 |
pub = create_temporary_pub() |
|
44 | 32 |
pub.cfg['language'] = {'language': 'en'} |
45 | 33 |
pub.write_cfg() |
46 |
return pub |
|
34 |
yield pub |
|
35 |
clean_temporary_pub() |
|
47 | 36 | |
48 | 37 | |
49 | 38 |
def teardown_module(module): |
... | ... | |
84 | 73 |
assert os.path.islink(required_link) and os.path.exists(required_link) |
85 | 74 | |
86 | 75 | |
87 |
def test_migrate(two_pubs):
|
|
76 |
def test_migrate(pub):
|
|
88 | 77 |
CmdMigrate().handle() |
89 | 78 | |
90 | 79 | |
91 |
def test_migrate_schemas(two_pubs):
|
|
80 |
def test_migrate_schemas(pub):
|
|
92 | 81 |
CmdMigrateSchemas().handle() |
93 | 82 | |
94 | 83 | |
... | ... | |
222 | 211 | |
223 | 212 | |
224 | 213 |
def test_delete_tenant_with_sql(freezer): |
225 |
pub = create_temporary_pub(sql_mode=True)
|
|
214 |
pub = create_temporary_pub() |
|
226 | 215 |
delete_cmd = CmdDeleteTenant() |
227 | 216 | |
228 | 217 |
assert os.path.isdir(pub.app_dir) |
... | ... | |
249 | 238 |
assert len(cur.fetchall()) == 1 |
250 | 239 | |
251 | 240 |
clean_temporary_pub() |
252 |
pub = create_temporary_pub(sql_mode=True)
|
|
241 |
pub = create_temporary_pub() |
|
253 | 242 | |
254 | 243 |
sub_options = sub_options_class(True) |
255 | 244 |
delete_cmd.delete_tenant(pub, sub_options, []) |
... | ... | |
276 | 265 |
assert cur.fetchall() |
277 | 266 | |
278 | 267 |
clean_temporary_pub() |
279 |
pub = create_temporary_pub(sql_mode=True)
|
|
268 |
pub = create_temporary_pub() |
|
280 | 269 | |
281 | 270 |
cleanup_connection() |
282 | 271 |
sub_options = sub_options_class(True) |
... | ... | |
301 | 290 |
pgconn.close() |
302 | 291 | |
303 | 292 |
clean_temporary_pub() |
304 |
pub = create_temporary_pub(sql_mode=True)
|
|
293 |
pub = create_temporary_pub() |
|
305 | 294 |
cleanup_connection() |
306 | 295 | |
307 | 296 |
sub_options = sub_options_class(False) |
... | ... | |
375 | 364 |
clean_temporary_pub() |
376 | 365 | |
377 | 366 | |
378 |
def test_rebuild_indexes(two_pubs):
|
|
367 |
def test_rebuild_indexes(pub):
|
|
379 | 368 |
form = FormDef() |
380 | 369 |
form.name = 'example' |
381 | 370 |
form.store() |
382 | 371 | |
383 |
assert os.listdir(os.path.join(two_pubs.app_dir, 'formdefs-url_name')) == ['example']
|
|
372 |
assert os.listdir(os.path.join(pub.app_dir, 'formdefs-url_name')) == ['example']
|
|
384 | 373 | |
385 |
os.unlink(os.path.join(two_pubs.app_dir, 'formdefs-url_name', 'example'))
|
|
386 |
os.symlink('../formdefs/1', os.path.join(two_pubs.app_dir, 'formdefs-url_name', 'XXX'))
|
|
387 |
rebuild_vhost_indexes(two_pubs, destroy=False)
|
|
388 |
assert 'example' in os.listdir(os.path.join(two_pubs.app_dir, 'formdefs-url_name'))
|
|
389 |
assert 'XXX' in os.listdir(os.path.join(two_pubs.app_dir, 'formdefs-url_name'))
|
|
374 |
os.unlink(os.path.join(pub.app_dir, 'formdefs-url_name', 'example'))
|
|
375 |
os.symlink('../formdefs/1', os.path.join(pub.app_dir, 'formdefs-url_name', 'XXX'))
|
|
376 |
rebuild_vhost_indexes(pub, destroy=False)
|
|
377 |
assert 'example' in os.listdir(os.path.join(pub.app_dir, 'formdefs-url_name'))
|
|
378 |
assert 'XXX' in os.listdir(os.path.join(pub.app_dir, 'formdefs-url_name'))
|
|
390 | 379 | |
391 |
rebuild_vhost_indexes(two_pubs, destroy=True)
|
|
392 |
assert os.listdir(os.path.join(two_pubs.app_dir, 'formdefs-url_name')) == ['example']
|
|
380 |
rebuild_vhost_indexes(pub, destroy=True)
|
|
381 |
assert os.listdir(os.path.join(pub.app_dir, 'formdefs-url_name')) == ['example']
|
|
393 | 382 | |
394 | 383 | |
395 | 384 |
def test_runscript(pub): |
... | ... | |
499 | 488 |
sys.argv = old_argv |
500 | 489 | |
501 | 490 | |
502 |
def test_dbshell(sql_pub):
|
|
491 |
def test_dbshell(pub): |
|
503 | 492 | |
504 | 493 |
with pytest.raises(CommandError): |
505 | 494 |
call_command('dbshell') # missing tenant name |
... | ... | |
508 | 497 |
call.side_effect = lambda *args, **kwargs: 0 |
509 | 498 |
call_command('dbshell', '--domain', 'example.net') |
510 | 499 |
assert call.call_args[0][-1][0] == 'psql' |
511 |
assert call.call_args[0][-1][-1] == sql_pub.cfg['postgresql']['database']
|
|
500 |
assert call.call_args[0][-1][-1] == pub.cfg['postgresql']['database'] |
|
512 | 501 | |
513 | 502 | |
514 | 503 |
def test_makemessages(pub): |
tests/test_datasource.py | ||
---|---|---|
23 | 23 | |
24 | 24 |
@pytest.fixture |
25 | 25 |
def pub(request): |
26 |
pub = create_temporary_pub(sql_mode=True)
|
|
26 |
pub = create_temporary_pub() |
|
27 | 27 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
28 | 28 |
pub.set_app_dir(req) |
29 | 29 |
tests/test_datasource_users.py | ||
---|---|---|
10 | 10 | |
11 | 11 |
@pytest.fixture |
12 | 12 |
def pub(): |
13 |
pub = create_temporary_pub(sql_mode=True)
|
|
13 |
pub = create_temporary_pub() |
|
14 | 14 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
15 | 15 |
pub.set_app_dir(req) |
16 | 16 |
return pub |
tests/test_fc_auth.py | ||
---|---|---|
54 | 54 |
def setup_module(module): |
55 | 55 |
cleanup() |
56 | 56 |
global pub |
57 |
pub = create_temporary_pub(sql_mode=True)
|
|
57 |
pub = create_temporary_pub() |
|
58 | 58 | |
59 | 59 | |
60 | 60 |
def setup_user_profile(pub): |
tests/test_formdata.py | ||
---|---|---|
41 | 41 | |
42 | 42 | |
43 | 43 |
@pytest.fixture |
44 |
def pub(request):
|
|
45 |
pub = create_temporary_pub(sql_mode=True)
|
|
44 |
def pub(): |
|
45 |
pub = create_temporary_pub() |
|
46 | 46 | |
47 | 47 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
48 | 48 |
pub.set_app_dir(req) |
tests/test_formdef.py | ||
---|---|---|
29 | 29 | |
30 | 30 | |
31 | 31 |
@pytest.fixture |
32 |
def pub(request):
|
|
33 |
pub = create_temporary_pub(sql_mode=True)
|
|
32 |
def pub(): |
|
33 |
pub = create_temporary_pub() |
|
34 | 34 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
35 | 35 |
pub.set_app_dir(req) |
36 | 36 |
pub.cfg['language'] = {'language': 'en'} |
tests/test_logged_errors.py | ||
---|---|---|
5 | 5 | |
6 | 6 |
@pytest.fixture |
7 | 7 |
def pub(request): |
8 |
return create_temporary_pub(sql_mode=True)
|
|
8 |
return create_temporary_pub() |
|
9 | 9 | |
10 | 10 | |
11 | 11 |
def teardown_module(module): |
tests/test_mail_templates.py | ||
---|---|---|
283 | 283 | |
284 | 284 | |
285 | 285 |
def test_workflow_send_mail_template_with_sql(superuser, emails): |
286 |
pub = create_temporary_pub(sql_mode=True)
|
|
286 |
pub = create_temporary_pub() |
|
287 | 287 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
288 | 288 |
pub.set_app_dir(req) |
289 | 289 |
pub._set_request(req) |
tests/test_publisher.py | ||
---|---|---|
560 | 560 | |
561 | 561 | |
562 | 562 |
def test_clean_loggederrors_no_sql(): |
563 |
pub = create_temporary_pub(sql_mode=False)
|
|
563 |
pub = create_temporary_pub(pickle_mode=True)
|
|
564 | 564 | |
565 | 565 |
# do nothing, no error |
566 | 566 |
pub.clean_loggederrors() |
567 | 567 | |
568 | 568 | |
569 | 569 |
def test_clean_loggederrors(): |
570 |
pub = create_temporary_pub(sql_mode=True)
|
|
570 |
pub = create_temporary_pub() |
|
571 | 571 | |
572 | 572 |
error1 = pub.loggederror_class() |
573 | 573 |
error1.first_occurence_timestamp = datetime.datetime.now() - datetime.timedelta(seconds=1) |
tests/test_register.py | ||
---|---|---|
12 | 12 | |
13 | 13 |
@pytest.fixture |
14 | 14 |
def pub(request): |
15 |
pub = create_temporary_pub(sql_mode=True)
|
|
15 |
pub = create_temporary_pub() |
|
16 | 16 | |
17 | 17 |
req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'}) |
18 | 18 |
pub.set_app_dir(req) |
tests/test_rootdirectory.py | ||
---|---|---|
29 | 29 | |
30 | 30 |
@pytest.fixture |
31 | 31 |
def pickle_pub(): |
32 |
yield create_temporary_pub(sql_mode=False)
|
|
32 |
yield create_temporary_pub(pickle_mode=True)
|
|
33 | 33 |
clean_temporary_pub() |
34 | 34 | |
35 | 35 |
tests/test_saml_auth.py | ||
---|---|---|
44 | 44 | |
45 | 45 | |
46 | 46 |
@pytest.fixture |
47 |
def pub(request):
|
|
48 |
pub = create_temporary_pub(sql_mode=True)
|
|
47 |
def pub(): |
|
48 |
pub = create_temporary_pub() |
|
49 | 49 | |
50 | 50 |
if not pub.cfg: |
51 | 51 |
pub.cfg = {} |
tests/test_snapshots.py | ||
---|---|---|
24 | 24 | |
25 | 25 | |
26 | 26 |
@pytest.fixture |
27 |
def pub(request, emails): |
|
28 |
pub = create_temporary_pub( |
|
29 |
sql_mode=True, |
|
30 |
lazy_mode=True, |
|
31 |
) |
|
27 |
def pub(emails): |
|
28 |
pub = create_temporary_pub(lazy_mode=True) |
|
32 | 29 |
pub.cfg['identification'] = {'methods': ['password']} |
33 | 30 |
pub.cfg['language'] = {'language': 'en'} |
34 | 31 |
pub.write_cfg() |
tests/test_sql.py | ||
---|---|---|
22 | 22 | |
23 | 23 |
@pytest.fixture |
24 | 24 |
def pub(request): |
25 |
return create_temporary_pub(sql_mode=True)
|
|
25 |
return create_temporary_pub() |
|
26 | 26 | |
27 | 27 | |
28 | 28 |
@pytest.fixture |
tests/test_token.py | ||
---|---|---|
13 | 13 | |
14 | 14 |
@pytest.fixture |
15 | 15 |
def pub(request): |
16 |
return create_temporary_pub(sql_mode=True)
|
|
16 |
return create_temporary_pub() |
|
17 | 17 | |
18 | 18 | |
19 | 19 |
def test_migrate_to_sql(pub): |
tests/test_tracking_code.py | ||
---|---|---|
7 | 7 | |
8 | 8 |
@pytest.fixture |
9 | 9 |
def pub(request): |
10 |
return create_temporary_pub(sql_mode=True)
|
|
10 |
return create_temporary_pub() |
|
11 | 11 | |
12 | 12 | |
13 | 13 |
def teardown_module(module): |
tests/test_upload_storage.py | ||
---|---|---|
23 | 23 |
@pytest.fixture |
24 | 24 |
def pub(request, emails): |
25 | 25 |
pub = create_temporary_pub( |
26 |
sql_mode=bool('sql' in request.param), |
|
27 | 26 |
lazy_mode=bool('lazy' in request.param), |
28 | 27 |
) |
29 | 28 |
pub.cfg['identification'] = {'methods': ['password']} |
tests/test_wscall.py | ||
---|---|---|
180 | 180 |
@pytest.mark.parametrize('notify_on_errors', [True, False]) |
181 | 181 |
@pytest.mark.parametrize('record_on_errors', [True, False]) |
182 | 182 |
def test_webservice_on_error_with_sql(http_requests, emails, notify_on_errors, record_on_errors): |
183 |
pub = create_temporary_pub(sql_mode=True)
|
|
183 |
pub = create_temporary_pub() |
|
184 | 184 |
pub.cfg['debug'] = {'error_email': 'errors@localhost.invalid'} |
185 | 185 |
pub.write_cfg() |
186 | 186 |
tests/utilities.py | ||
---|---|---|
43 | 43 |
known_elements = KnownElements() |
44 | 44 | |
45 | 45 | |
46 |
def create_temporary_pub(sql_mode=True, legacy_theme_mode=False, lazy_mode=False):
|
|
46 |
def create_temporary_pub(pickle_mode=False, legacy_theme_mode=False, lazy_mode=False):
|
|
47 | 47 |
if get_publisher(): |
48 | 48 |
get_publisher().cleanup() |
49 | 49 |
cleanup() |
... | ... | |
51 | 51 |
APP_DIR = known_elements.legacy_theme_app_dir |
52 | 52 |
elif lazy_mode and known_elements.lazy_app_dir: |
53 | 53 |
APP_DIR = known_elements.lazy_app_dir |
54 |
elif sql_mode and known_elements.sql_app_dir and not lazy_mode: |
|
55 |
APP_DIR = known_elements.sql_app_dir |
|
56 |
elif not (legacy_theme_mode or lazy_mode or sql_mode) and known_elements.pickle_app_dir: |
|
54 |
elif pickle_mode and known_elements.pickle_app_dir: |
|
57 | 55 |
APP_DIR = known_elements.pickle_app_dir |
56 |
elif not (legacy_theme_mode or lazy_mode or pickle_mode) and known_elements.sql_app_dir: |
|
57 |
APP_DIR = known_elements.sql_app_dir |
|
58 | 58 |
else: |
59 | 59 |
APP_DIR = tempfile.mkdtemp() |
60 | 60 |
if legacy_theme_mode: |
61 | 61 |
known_elements.legacy_theme_app_dir = APP_DIR |
62 | 62 |
elif lazy_mode: |
63 | 63 |
known_elements.lazy_app_dir = APP_DIR |
64 |
elif sql_mode and not lazy_mode: |
|
65 |
known_elements.sql_app_dir = APP_DIR |
|
66 |
else: |
|
64 |
elif pickle_mode: |
|
67 | 65 |
known_elements.pickle_app_dir = APP_DIR |
66 |
else: |
|
67 |
known_elements.sql_app_dir = APP_DIR |
|
68 | 68 | |
69 | 69 |
compat.CompatWcsPublisher.APP_DIR = APP_DIR |
70 | 70 |
compat.CompatWcsPublisher.DATA_DIR = os.path.abspath( |
... | ... | |
76 | 76 |
pub.app_dir = os.path.join(APP_DIR, 'example.net') |
77 | 77 |
pub.site_charset = 'utf-8' |
78 | 78 | |
79 |
if sql_mode:
|
|
79 |
if not pickle_mode:
|
|
80 | 80 |
pub.user_class = sql.SqlUser |
81 | 81 |
pub.role_class = sql.Role |
82 | 82 |
pub.token_class = sql.Token |
... | ... | |
117 | 117 |
fd.write('workflow-resubmit-action = true\n') |
118 | 118 |
if lazy_mode: |
119 | 119 |
fd.write('force-lazy-mode = true\n') |
120 |
if sql_mode: |
|
121 |
fd.write('postgresql = true\n') |
|
122 | 120 | |
123 | 121 |
# make sure site options are not cached |
124 | 122 |
pub.site_options = None |
... | ... | |
138 | 136 |
pub.write_cfg() |
139 | 137 | |
140 | 138 |
if not created: |
141 |
if sql_mode:
|
|
139 |
if not pickle_mode:
|
|
142 | 140 |
pub.cfg['postgresql'] = {'database': known_elements.sql_db_name, 'user': os.environ['USER']} |
143 | 141 |
pub.loggederror_class.wipe() |
144 | 142 |
pub.write_cfg() |
... | ... | |
146 | 144 | |
147 | 145 |
os.symlink(os.path.join(os.path.dirname(__file__), 'templates'), os.path.join(pub.app_dir, 'templates')) |
148 | 146 | |
149 |
if sql_mode:
|
|
147 |
if not pickle_mode:
|
|
150 | 148 |
conn = psycopg2.connect(user=os.environ['USER'], dbname='postgres') |
151 | 149 |
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) |
152 | 150 |
i = 0 |
tests/workflow/test_all.py | ||
---|---|---|
92 | 92 |
clean_temporary_pub() |
93 | 93 | |
94 | 94 | |
95 |
def pub_fixture(**kwargs): |
|
96 |
pub = create_temporary_pub(**kwargs) |
|
95 |
@pytest.fixture |
|
96 |
def pub(): |
|
97 |
pub = create_temporary_pub() |
|
97 | 98 |
pub.cfg['language'] = {'language': 'en'} |
98 | 99 |
pub.cfg['identification'] = {'methods': ['password']} |
99 | 100 |
pub.write_cfg() |
... | ... | |
106 | 107 |
return pub |
107 | 108 | |
108 | 109 | |
109 |
@pytest.fixture |
|
110 |
def pub(request): |
|
111 |
return pub_fixture() |
|
112 | ||
113 | ||
114 |
@pytest.fixture |
|
115 |
def two_pubs(request): |
|
116 |
return pub_fixture(sql_mode=True) |
|
117 | ||
118 | ||
119 |
@pytest.fixture |
|
120 |
def sql_pub(request): |
|
121 |
return pub_fixture(sql_mode=True) |
|
122 | ||
123 | ||
124 | 110 |
@pytest.fixture |
125 | 111 |
def admin_user(): |
126 | 112 |
get_publisher().user_class.wipe() |
... | ... | |
372 | 358 |
assert item.check_condition(formdata) is False |
373 | 359 | |
374 | 360 | |
375 |
def test_jump_bad_python_condition(two_pubs):
|
|
361 |
def test_jump_bad_python_condition(pub):
|
|
376 | 362 |
FormDef.wipe() |
377 | 363 |
formdef = FormDef() |
378 | 364 |
formdef.name = 'foobar' |
379 | 365 |
formdef.store() |
380 |
two_pubs.substitutions.feed(formdef)
|
|
366 |
pub.substitutions.feed(formdef)
|
|
381 | 367 |
formdef.data_class().wipe() |
382 | 368 |
formdata = formdef.data_class()() |
383 | 369 |
item = JumpWorkflowStatusItem() |
384 | 370 | |
385 | 371 |
item.condition = {'type': 'python', 'value': 'form_var_foobar == 0'} |
386 | 372 |
assert item.check_condition(formdata) is False |
387 |
assert two_pubs.loggederror_class.count() == 1
|
|
388 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
373 |
assert pub.loggederror_class.count() == 1
|
|
374 |
logged_error = pub.loggederror_class.select()[0]
|
|
389 | 375 |
assert logged_error.summary == 'Failed to evaluate condition' |
390 | 376 |
assert logged_error.exception_class == 'NameError' |
391 | 377 |
assert logged_error.exception_message == "name 'form_var_foobar' is not defined" |
392 | 378 |
assert logged_error.expression == 'form_var_foobar == 0' |
393 | 379 |
assert logged_error.expression_type == 'python' |
394 | 380 | |
395 |
two_pubs.loggederror_class.wipe()
|
|
381 |
pub.loggederror_class.wipe()
|
|
396 | 382 |
item.condition = {'type': 'python', 'value': '~ invalid ~'} |
397 | 383 |
assert item.check_condition(formdata) is False |
398 |
assert two_pubs.loggederror_class.count() == 1
|
|
399 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
384 |
assert pub.loggederror_class.count() == 1
|
|
385 |
logged_error = pub.loggederror_class.select()[0]
|
|
400 | 386 |
assert logged_error.summary == 'Failed to evaluate condition' |
401 | 387 |
assert logged_error.exception_class == 'SyntaxError' |
402 | 388 |
assert logged_error.exception_message == 'unexpected EOF while parsing (<string>, line 1)' |
... | ... | |
404 | 390 |
assert logged_error.expression_type == 'python' |
405 | 391 | |
406 | 392 | |
407 |
def test_jump_django_conditions(two_pubs):
|
|
393 |
def test_jump_django_conditions(pub):
|
|
408 | 394 |
FormDef.wipe() |
409 | 395 |
formdef = FormDef() |
410 | 396 |
formdef.name = 'foobar' |
... | ... | |
414 | 400 |
formdef.store() |
415 | 401 |
formdata = formdef.data_class()() |
416 | 402 |
formdata.data = {'1': 'hello'} |
417 |
two_pubs.substitutions.feed(formdata)
|
|
403 |
pub.substitutions.feed(formdata)
|
|
418 | 404 |
item = JumpWorkflowStatusItem() |
419 | 405 | |
420 | 406 |
item.condition = {'type': 'django', 'value': '1 < 2'} |
... | ... | |
429 | 415 |
item.condition = {'type': 'django', 'value': 'form_var_foo|first|upper == "X"'} |
430 | 416 |
assert item.check_condition(formdata) is False |
431 | 417 | |
432 |
assert two_pubs.loggederror_class.count() == 0
|
|
418 |
assert pub.loggederror_class.count() == 0
|
|
433 | 419 | |
434 | 420 |
item.condition = {'type': 'django', 'value': '~ invalid ~'} |
435 | 421 |
assert item.check_condition(formdata) is False |
436 |
assert two_pubs.loggederror_class.count() == 1
|
|
437 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
422 |
assert pub.loggederror_class.count() == 1
|
|
423 |
logged_error = pub.loggederror_class.select()[0]
|
|
438 | 424 |
assert logged_error.summary == 'Failed to evaluate condition' |
439 | 425 |
assert logged_error.exception_class == 'TemplateSyntaxError' |
440 | 426 |
assert logged_error.exception_message == "Could not parse the remainder: '~' from '~'" |
... | ... | |
573 | 559 |
assert formdata.workflow_roles == {'_receiver': [role.id]} |
574 | 560 | |
575 | 561 | |
576 |
def test_dispatch_auto(two_pubs):
|
|
562 |
def test_dispatch_auto(pub):
|
|
577 | 563 |
formdef = FormDef() |
578 | 564 |
formdef.name = 'baz' |
579 | 565 |
formdef.fields = [ |
... | ... | |
586 | 572 |
item.dispatch_type = 'automatic' |
587 | 573 | |
588 | 574 |
formdata = formdef.data_class()() |
589 |
two_pubs.substitutions.reset()
|
|
590 |
two_pubs.substitutions.feed(formdata)
|
|
575 |
pub.substitutions.reset()
|
|
576 |
pub.substitutions.feed(formdata)
|
|
591 | 577 |
item.perform(formdata) |
592 | 578 |
assert not formdata.workflow_roles |
593 | 579 | |
594 |
two_pubs.role_class.wipe()
|
|
595 |
role1 = two_pubs.role_class('xxx1')
|
|
580 |
pub.role_class.wipe()
|
|
581 |
role1 = pub.role_class('xxx1')
|
|
596 | 582 |
role1.store() |
597 |
role2 = two_pubs.role_class('xxx2')
|
|
583 |
role2 = pub.role_class('xxx2')
|
|
598 | 584 |
role2.store() |
599 | 585 | |
600 | 586 |
for variable in ('form_var_foo', '{{form_var_foo}}'): |
... | ... | |
607 | 593 |
{'role_id': role1.id, 'value': '42'}, |
608 | 594 |
] |
609 | 595 | |
610 |
two_pubs.substitutions.reset()
|
|
611 |
two_pubs.substitutions.feed(formdata)
|
|
596 |
pub.substitutions.reset()
|
|
597 |
pub.substitutions.feed(formdata)
|
|
612 | 598 |
item.perform(formdata) |
613 | 599 |
assert not formdata.workflow_roles |
614 | 600 | |
615 | 601 |
# no match |
616 | 602 |
formdata.data = {'1': 'XXX'} |
617 |
two_pubs.substitutions.reset()
|
|
618 |
two_pubs.substitutions.feed(formdata)
|
|
603 |
pub.substitutions.reset()
|
|
604 |
pub.substitutions.feed(formdata)
|
|
619 | 605 |
item.perform(formdata) |
620 | 606 |
assert not formdata.workflow_roles |
621 | 607 | |
622 | 608 |
# match |
623 | 609 |
formdata.data = {'1': 'foo'} |
624 |
two_pubs.substitutions.reset()
|
|
625 |
two_pubs.substitutions.feed(formdata)
|
|
610 |
pub.substitutions.reset()
|
|
611 |
pub.substitutions.feed(formdata)
|
|
626 | 612 |
item.perform(formdata) |
627 | 613 |
assert formdata.workflow_roles == {'_receiver': [role1.id]} |
628 | 614 | |
629 | 615 |
# other match |
630 | 616 |
formdata.data = {'1': 'bar'} |
631 |
two_pubs.substitutions.reset()
|
|
632 |
two_pubs.substitutions.feed(formdata)
|
|
617 |
pub.substitutions.reset()
|
|
618 |
pub.substitutions.feed(formdata)
|
|
633 | 619 |
item.perform(formdata) |
634 | 620 |
assert formdata.workflow_roles == {'_receiver': [role2.id]} |
635 | 621 | |
636 | 622 |
# integer match |
637 |
two_pubs.substitutions.reset()
|
|
623 |
pub.substitutions.reset()
|
|
638 | 624 |
# cannot store an integer in formdata.data, we mock substitutions: |
639 |
two_pubs.substitutions.feed({'form_var_foo': 42})
|
|
625 |
pub.substitutions.feed({'form_var_foo': 42})
|
|
640 | 626 |
item.perform(formdata) |
641 | 627 |
assert formdata.workflow_roles == {'_receiver': [role1.id]} |
642 | 628 | |
... | ... | |
647 | 633 |
item.rules = [ |
648 | 634 |
{'role_id': 'foobar', 'value': 'foo'}, |
649 | 635 |
] |
650 |
two_pubs.substitutions.reset()
|
|
651 |
two_pubs.substitutions.feed(formdata)
|
|
636 |
pub.substitutions.reset()
|
|
637 |
pub.substitutions.feed(formdata)
|
|
652 | 638 |
item.perform(formdata) |
653 | 639 |
assert not formdata.workflow_roles |
654 |
assert two_pubs.loggederror_class.count() == 1
|
|
655 |
error = two_pubs.loggederror_class.select()[0]
|
|
640 |
assert pub.loggederror_class.count() == 1
|
|
641 |
error = pub.loggederror_class.select()[0]
|
|
656 | 642 |
assert error.tech_id == '%s-_default-error-in-dispatch-missing-role-foobar' % formdef.id |
657 | 643 |
assert error.formdef_id == formdef.id |
658 | 644 |
assert error.workflow_id == '_default' |
... | ... | |
660 | 646 |
assert error.occurences_count == 1 |
661 | 647 | |
662 | 648 | |
663 |
def test_dispatch_computed(two_pubs):
|
|
649 |
def test_dispatch_computed(pub):
|
|
664 | 650 |
formdef = FormDef() |
665 | 651 |
formdef.name = 'baz' |
666 | 652 |
formdef.store() |
667 | 653 | |
668 |
two_pubs.role_class.wipe()
|
|
669 |
role = two_pubs.role_class(name='xxx')
|
|
654 |
pub.role_class.wipe()
|
|
655 |
role = pub.role_class(name='xxx')
|
|
670 | 656 |
role.slug = 'yyy' |
671 | 657 |
role.store() |
672 | 658 | |
... | ... | |
707 | 693 |
item.role_id = '="foobar"' |
708 | 694 |
item.perform(formdata) |
709 | 695 |
assert not formdata.workflow_roles |
710 |
assert two_pubs.loggederror_class.count() == 1
|
|
711 |
error = two_pubs.loggederror_class.select()[0]
|
|
696 |
assert pub.loggederror_class.count() == 1
|
|
697 |
error = pub.loggederror_class.select()[0]
|
|
712 | 698 |
assert error.tech_id == '%s-_default-error-in-dispatch-missing-role-foobar' % formdef.id |
713 | 699 |
assert error.formdef_id == formdef.id |
714 | 700 |
assert error.workflow_id == '_default' |
... | ... | |
716 | 702 |
assert error.occurences_count == 1 |
717 | 703 | |
718 | 704 |
# unknown role, with template |
719 |
two_pubs.loggederror_class.wipe()
|
|
705 |
pub.loggederror_class.wipe()
|
|
720 | 706 |
formdata = formdef.data_class()() |
721 | 707 |
item.role_key = '_receiver' |
722 | 708 |
item.role_id = '{{ "foobar" }}' |
723 | 709 |
item.perform(formdata) |
724 | 710 |
assert not formdata.workflow_roles |
725 |
assert two_pubs.loggederror_class.count() == 1
|
|
726 |
error = two_pubs.loggederror_class.select()[0]
|
|
711 |
assert pub.loggederror_class.count() == 1
|
|
712 |
error = pub.loggederror_class.select()[0]
|
|
727 | 713 |
assert ( |
728 | 714 |
error.tech_id == '%s-_default-error-in-dispatch-missing-role-foobar-from-foobar-template' % formdef.id |
729 | 715 |
) |
... | ... | |
780 | 766 |
assert formdata.workflow_roles == {} |
781 | 767 | |
782 | 768 | |
783 |
def test_roles(two_pubs): |
|
784 |
pub = two_pubs |
|
769 |
def test_roles(pub): |
|
785 | 770 |
pub.role_class.wipe() |
786 | 771 |
role = pub.role_class(name='xxx') |
787 | 772 |
role.store() |
... | ... | |
974 | 959 |
assert pub.user_class.get(user.id).roles == [] |
975 | 960 | |
976 | 961 | |
977 |
def test_anonymise(two_pubs):
|
|
962 |
def test_anonymise(pub):
|
|
978 | 963 |
# build a backoffice field |
979 | 964 |
Workflow.wipe() |
980 | 965 |
wf = Workflow(name='wf with backoffice field') |
... | ... | |
1028 | 1013 |
assert formdef.data_class().get(formdata.id).evolution[0].who is None |
1029 | 1014 | |
1030 | 1015 | |
1031 |
def test_remove(two_pubs):
|
|
1016 |
def test_remove(pub):
|
|
1032 | 1017 |
formdef = FormDef() |
1033 | 1018 |
formdef.name = 'baz' |
1034 | 1019 |
formdef.store() |
... | ... | |
1048 | 1033 |
formdata.store() |
1049 | 1034 | |
1050 | 1035 |
item = RemoveWorkflowStatusItem() |
1051 |
req = two_pubs.get_request()
|
|
1036 |
req = pub.get_request()
|
|
1052 | 1037 |
req.response.filter['in_backoffice'] = True |
1053 | 1038 |
assert formdef.data_class().count() == 1 |
1054 | 1039 |
with pytest.raises(AbortActionException) as e: |
... | ... | |
1059 | 1044 |
assert req.session.message |
1060 | 1045 | |
1061 | 1046 | |
1062 |
def test_stop_on_remove(two_pubs, emails):
|
|
1047 |
def test_stop_on_remove(pub, emails):
|
|
1063 | 1048 |
workflow = Workflow(name='stop-on-remove') |
1064 | 1049 |
st1 = workflow.add_status('Status1', 'st1') |
1065 | 1050 | |
... | ... | |
1077 | 1062 |
workflow.store() |
1078 | 1063 | |
1079 | 1064 |
formdef = FormDef() |
1080 |
formdef.name = 'baz%s' % id(two_pubs)
|
|
1065 |
formdef.name = 'baz%s' % id(pub)
|
|
1081 | 1066 |
formdef.fields = [] |
1082 | 1067 |
formdef.workflow_id = workflow.id |
1083 | 1068 |
assert formdef.get_workflow().id == workflow.id |
... | ... | |
1227 | 1212 |
assert formdata.evolution[-1].display_parts()[-1] == '<div><p>hello</p></div>' |
1228 | 1213 | |
1229 | 1214 | |
1230 |
def test_register_comment_attachment(two_pubs):
|
|
1231 |
two_pubs.substitutions.feed(MockSubstitutionVariables())
|
|
1215 |
def test_register_comment_attachment(pub):
|
|
1216 |
pub.substitutions.feed(MockSubstitutionVariables())
|
|
1232 | 1217 | |
1233 | 1218 |
formdef = FormDef() |
1234 | 1219 |
formdef.name = 'baz' |
... | ... | |
1258 | 1243 | |
1259 | 1244 |
item.comment = '{{ attachments.testfile.url }}' |
1260 | 1245 | |
1261 |
two_pubs.substitutions.feed(formdata)
|
|
1246 |
pub.substitutions.feed(formdata)
|
|
1262 | 1247 |
item.perform(formdata) |
1263 | 1248 |
url1 = formdata.evolution[-1].parts[-1].content |
1264 |
assert two_pubs.loggederror_class.count() == 1
|
|
1265 |
error = two_pubs.loggederror_class.select()[0]
|
|
1249 |
assert pub.loggederror_class.count() == 1
|
|
1250 |
error = pub.loggederror_class.select()[0]
|
|
1266 | 1251 |
assert error.kind == 'deprecated_usage' |
1267 | 1252 |
assert error.occurences_count == 1 |
1268 | 1253 | |
1269 |
two_pubs.substitutions.feed(formdata)
|
|
1254 |
pub.substitutions.feed(formdata)
|
|
1270 | 1255 |
item.comment = '{{ form_attachments.testfile.url }}' |
1271 | 1256 |
item.perform(formdata) |
1272 | 1257 |
url2 = formdata.evolution[-1].parts[-1].content |
1273 |
assert two_pubs.loggederror_class.count() == 1
|
|
1274 |
error = two_pubs.loggederror_class.select()[0]
|
|
1258 |
assert pub.loggederror_class.count() == 1
|
|
1259 |
error = pub.loggederror_class.select()[0]
|
|
1275 | 1260 |
assert error.kind == 'deprecated_usage' |
1276 | 1261 |
assert error.occurences_count == 1 |
1277 | 1262 | |
... | ... | |
1296 | 1281 |
item.condition = {'type': 'django', 'value': 'form_attachments.missing'} |
1297 | 1282 |
assert item.check_condition(formdata) is False |
1298 | 1283 | |
1299 |
two_pubs.substitutions.feed(formdata)
|
|
1284 |
pub.substitutions.feed(formdata)
|
|
1300 | 1285 |
item.comment = '[attachments.testfile.url]' |
1301 | 1286 |
item.perform(formdata) |
1302 | 1287 |
url3 = formdata.evolution[-1].parts[-1].content |
1303 |
assert two_pubs.loggederror_class.count() == 1
|
|
1304 |
error = two_pubs.loggederror_class.select()[0]
|
|
1288 |
assert pub.loggederror_class.count() == 1
|
|
1289 |
error = pub.loggederror_class.select()[0]
|
|
1305 | 1290 |
assert error.kind == 'deprecated_usage' |
1306 | 1291 |
assert error.occurences_count == 2 |
1307 |
two_pubs.substitutions.feed(formdata)
|
|
1292 |
pub.substitutions.feed(formdata)
|
|
1308 | 1293 |
item.comment = '[form_attachments.testfile.url]' |
1309 | 1294 |
item.perform(formdata) |
1310 | 1295 |
url4 = formdata.evolution[-1].parts[-1].content |
1311 | 1296 |
assert url3 == url4 |
1312 |
assert two_pubs.loggederror_class.count() == 1
|
|
1313 |
error = two_pubs.loggederror_class.select()[0]
|
|
1297 |
assert pub.loggederror_class.count() == 1
|
|
1298 |
error = pub.loggederror_class.select()[0]
|
|
1314 | 1299 |
assert error.kind == 'deprecated_usage' |
1315 | 1300 |
assert error.occurences_count == 2 |
1316 | 1301 | |
... | ... | |
1596 | 1581 |
assert 'to-role-or-submitter.txt' in display_parts()[6] |
1597 | 1582 | |
1598 | 1583 | |
1599 |
def test_webservice_call(http_requests, two_pubs): |
|
1600 |
pub = two_pubs |
|
1584 |
def test_webservice_call(http_requests, pub): |
|
1601 | 1585 |
pub.substitutions.feed(MockSubstitutionVariables()) |
1602 | 1586 | |
1603 | 1587 |
wf = Workflow(name='wf1') |
... | ... | |
2402 | 2386 |
formdata.evolution[-1].time = rewind_time(formdata.evolution[-1].time) |
2403 | 2387 | |
2404 | 2388 | |
2405 |
def test_timeout(two_pubs):
|
|
2389 |
def test_timeout(pub):
|
|
2406 | 2390 |
workflow = Workflow(name='timeout') |
2407 | 2391 |
st1 = workflow.add_status('Status1', 'st1') |
2408 | 2392 |
workflow.add_status('Status2', 'st2') |
... | ... | |
2427 | 2411 |
formdata.store() |
2428 | 2412 |
formdata_id = formdata.id |
2429 | 2413 | |
2430 |
_apply_timeouts(two_pubs)
|
|
2414 |
_apply_timeouts(pub)
|
|
2431 | 2415 | |
2432 | 2416 |
assert formdef.data_class().get(formdata_id).status == 'wf-st2' |
2433 | 2417 | |
... | ... | |
2437 | 2421 |
formdata_id = formdata.id |
2438 | 2422 |
with mock.patch('wcs.wf.jump.JumpWorkflowStatusItem.check_condition') as must_jump: |
2439 | 2423 |
must_jump.return_value = False |
2440 |
_apply_timeouts(two_pubs)
|
|
2424 |
_apply_timeouts(pub)
|
|
2441 | 2425 |
assert must_jump.call_count == 0 # not enough time has passed |
2442 | 2426 | |
2443 | 2427 |
# check a lower than minimal delay is not considered |
... | ... | |
2445 | 2429 |
workflow.store() |
2446 | 2430 |
rewind(formdata, seconds=10 * 60) |
2447 | 2431 |
formdata.store() |
2448 |
_apply_timeouts(two_pubs)
|
|
2432 |
_apply_timeouts(pub)
|
|
2449 | 2433 |
assert must_jump.call_count == 0 |
2450 | 2434 | |
2451 | 2435 |
# but is executed once delay is reached |
2452 | 2436 |
rewind(formdata, seconds=10 * 60) |
2453 | 2437 |
formdata.store() |
2454 |
_apply_timeouts(two_pubs)
|
|
2438 |
_apply_timeouts(pub)
|
|
2455 | 2439 |
assert must_jump.call_count == 1 |
2456 | 2440 | |
2457 | 2441 |
# check a templated timeout is considered as minimal delay for explicit evaluation |
2458 | 2442 |
jump.timeout = '{{ "0" }}' |
2459 | 2443 |
workflow.store() |
2460 |
_apply_timeouts(two_pubs)
|
|
2444 |
_apply_timeouts(pub)
|
|
2461 | 2445 |
assert must_jump.call_count == 2 |
2462 | 2446 | |
2463 | 2447 |
# check there's no crash on workflow without jumps |
2464 | 2448 |
formdef = FormDef() |
2465 | 2449 |
formdef.name = 'xxx' |
2466 | 2450 |
formdef.store() |
2467 |
_apply_timeouts(two_pubs)
|
|
2451 |
_apply_timeouts(pub)
|
|
2468 | 2452 | |
2469 | 2453 | |
2470 |
def test_timeout_with_humantime_template(two_pubs):
|
|
2454 |
def test_timeout_with_humantime_template(pub):
|
|
2471 | 2455 |
workflow = Workflow(name='timeout') |
2472 | 2456 |
st1 = workflow.add_status('Status1', 'st1') |
2473 | 2457 |
workflow.add_status('Status2', 'st2') |
... | ... | |
2491 | 2475 |
formdata.store() |
2492 | 2476 |
formdata_id = formdata.id |
2493 | 2477 | |
2494 |
_apply_timeouts(two_pubs)
|
|
2478 |
_apply_timeouts(pub)
|
|
2495 | 2479 |
assert formdef.data_class().get(formdata_id).status == 'wf-st1' # no change |
2496 | 2480 | |
2497 | 2481 |
rewind(formdata, seconds=40 * 60) |
2498 | 2482 |
formdata.store() |
2499 |
_apply_timeouts(two_pubs)
|
|
2483 |
_apply_timeouts(pub)
|
|
2500 | 2484 |
assert formdef.data_class().get(formdata_id).status == 'wf-st2' |
2501 | 2485 | |
2502 | 2486 |
# invalid timeout value |
... | ... | |
2509 | 2493 |
formdata.store() |
2510 | 2494 |
formdata_id = formdata.id |
2511 | 2495 | |
2512 |
two_pubs.loggederror_class.wipe()
|
|
2496 |
pub.loggederror_class.wipe()
|
|
2513 | 2497 | |
2514 | 2498 |
rewind(formdata, seconds=40 * 60) |
2515 | 2499 |
formdata.store() |
2516 |
_apply_timeouts(two_pubs)
|
|
2500 |
_apply_timeouts(pub)
|
|
2517 | 2501 |
assert formdef.data_class().get(formdata_id).status == 'wf-st1' # no change |
2518 | 2502 | |
2519 |
assert two_pubs.loggederror_class.count() == 1
|
|
2520 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
2503 |
assert pub.loggederror_class.count() == 1
|
|
2504 |
logged_error = pub.loggederror_class.select()[0]
|
|
2521 | 2505 |
assert logged_error.summary == "Error in timeout value '30 plop' (computed from '{{ 30 }} plop')" |
2522 | 2506 | |
2523 | 2507 |
# template timeout value returning nothing |
... | ... | |
2530 | 2514 |
formdata.store() |
2531 | 2515 |
formdata_id = formdata.id |
2532 | 2516 | |
2533 |
two_pubs.loggederror_class.wipe()
|
|
2517 |
pub.loggederror_class.wipe()
|
|
2534 | 2518 | |
2535 | 2519 |
rewind(formdata, seconds=40 * 60) |
2536 | 2520 |
formdata.store() |
2537 |
_apply_timeouts(two_pubs)
|
|
2521 |
_apply_timeouts(pub)
|
|
2538 | 2522 |
assert formdef.data_class().get(formdata_id).status == 'wf-st1' # no change |
2539 | 2523 | |
2540 |
assert two_pubs.loggederror_class.count() == 1
|
|
2541 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
2524 |
assert pub.loggederror_class.count() == 1
|
|
2525 |
logged_error = pub.loggederror_class.select()[0]
|
|
2542 | 2526 |
assert logged_error.summary == "Error in timeout value '' (computed from '{% if 1 %}{% endif %}')" |
2543 | 2527 | |
2544 | 2528 | |
... | ... | |
2571 | 2555 |
assert formdef.data_class().get(formdata_id).status == 'wf-st2' |
2572 | 2556 | |
2573 | 2557 | |
2574 |
def test_timeout_then_remove(two_pubs):
|
|
2558 |
def test_timeout_then_remove(pub):
|
|
2575 | 2559 |
workflow = Workflow(name='timeout-then-remove') |
2576 | 2560 |
st1 = workflow.add_status('Status1', 'st1') |
2577 | 2561 |
st2 = workflow.add_status('Status2', 'st2') |
... | ... | |
2586 | 2570 |
workflow.store() |
2587 | 2571 | |
2588 | 2572 |
formdef = FormDef() |
2589 |
formdef.name = 'baz%s' % id(two_pubs)
|
|
2573 |
formdef.name = 'baz%s' % id(pub)
|
|
2590 | 2574 |
formdef.fields = [] |
2591 | 2575 |
formdef.workflow_id = workflow.id |
2592 | 2576 |
assert formdef.get_workflow().id == workflow.id |
... | ... | |
2600 | 2584 | |
2601 | 2585 |
assert str(formdata_id) in [str(x) for x in formdef.data_class().keys()] |
2602 | 2586 | |
2603 |
_apply_timeouts(two_pubs)
|
|
2587 |
_apply_timeouts(pub)
|
|
2604 | 2588 | |
2605 | 2589 |
assert not str(formdata_id) in [str(x) for x in formdef.data_class().keys()] |
2606 | 2590 | |
2607 | 2591 | |
2608 |
def test_timeout_with_mark(two_pubs):
|
|
2592 |
def test_timeout_with_mark(pub):
|
|
2609 | 2593 |
workflow = Workflow(name='timeout') |
2610 | 2594 |
st1 = workflow.add_status('Status1', 'st1') |
2611 | 2595 |
workflow.add_status('Status2', 'st2') |
... | ... | |
2631 | 2615 |
formdata.store() |
2632 | 2616 |
formdata_id = formdata.id |
2633 | 2617 | |
2634 |
_apply_timeouts(two_pubs)
|
|
2618 |
_apply_timeouts(pub)
|
|
2635 | 2619 | |
2636 | 2620 |
formdata = formdef.data_class().get(formdata_id) |
2637 | 2621 |
assert formdata.workflow_data.get('_markers_stack') == [{'status_id': 'st1'}] |
2638 | 2622 | |
2639 | 2623 | |
2640 |
def test_jump_missing_previous_mark(two_pubs):
|
|
2624 |
def test_jump_missing_previous_mark(pub):
|
|
2641 | 2625 |
FormDef.wipe() |
2642 | 2626 |
Workflow.wipe() |
2643 | 2627 | |
... | ... | |
2662 | 2646 |
rewind(formdata, seconds=40 * 60) |
2663 | 2647 |
formdata.store() |
2664 | 2648 | |
2665 |
two_pubs.loggederror_class.wipe()
|
|
2666 |
_apply_timeouts(two_pubs)
|
|
2667 |
assert two_pubs.loggederror_class.count() == 1
|
|
2649 |
pub.loggederror_class.wipe()
|
|
2650 |
_apply_timeouts(pub)
|
|
2651 |
assert pub.loggederror_class.count() == 1
|
|
2668 | 2652 | |
2669 | 2653 | |
2670 | 2654 |
def test_sms(pub, sms_mocking): |
... | ... | |
2778 | 2762 |
assert sms_mocking.sms[0]['text'] == 'XXX' |
2779 | 2763 | |
2780 | 2764 | |
2781 |
def test_sms_with_passerelle(two_pubs): |
|
2782 |
pub = two_pubs |
|
2765 |
def test_sms_with_passerelle(pub): |
|
2783 | 2766 |
pub.cfg['sms'] = { |
2784 | 2767 |
'mode': 'passerelle', |
2785 | 2768 |
'passerelle_url': 'http://passerelle.example.com/send?nostop=1', |
... | ... | |
2828 | 2811 |
assert pub.loggederror_class.select()[0].summary == 'Could not send SMS' |
2829 | 2812 | |
2830 | 2813 | |
2831 |
def test_display_form(two_pubs):
|
|
2814 |
def test_display_form(pub):
|
|
2832 | 2815 |
formdef = FormDef() |
2833 | 2816 |
formdef.name = 'baz' |
2834 | 2817 |
formdef.fields = [] |
... | ... | |
2852 | 2835 |
assert form.widgets[0].title == 'Test' |
2853 | 2836 |
assert form.widgets[1].title == 'Date' |
2854 | 2837 | |
2855 |
two_pubs.get_request().environ['REQUEST_METHOD'] = 'POST'
|
|
2856 |
two_pubs.get_request().form = {'fxxx_1': 'Foobar', 'fxxx_2': '2015-05-12', 'submit': 'submit'}
|
|
2838 |
pub.get_request().environ['REQUEST_METHOD'] = 'POST'
|
|
2839 |
pub.get_request().form = {'fxxx_1': 'Foobar', 'fxxx_2': '2015-05-12', 'submit': 'submit'}
|
|
2857 | 2840 |
display_form.submit_form(form, formdata, None, None) |
2858 | 2841 | |
2859 | 2842 |
assert formdata.get_substitution_variables()['xxx_var_date'] == '2015-05-12' |
2860 | 2843 | |
2861 |
two_pubs.cfg['language'] = {'language': 'fr'}
|
|
2844 |
pub.cfg['language'] = {'language': 'fr'}
|
|
2862 | 2845 |
formdata = formdef.data_class()() |
2863 | 2846 |
formdata.just_created() |
2864 | 2847 |
formdata.store() |
2865 | 2848 | |
2866 | 2849 |
form = Form(action='#', use_tokens=False) |
2867 | 2850 |
display_form.fill_form(form, formdata, None) |
2868 |
two_pubs.get_request().environ['REQUEST_METHOD'] = 'POST'
|
|
2869 |
two_pubs.get_request().form = {'fxxx_1': 'Foobar', 'fxxx_2': '12/05/2015', 'submit': 'submit'}
|
|
2851 |
pub.get_request().environ['REQUEST_METHOD'] = 'POST'
|
|
2852 |
pub.get_request().form = {'fxxx_1': 'Foobar', 'fxxx_2': '12/05/2015', 'submit': 'submit'}
|
|
2870 | 2853 |
display_form.submit_form(form, formdata, None, None) |
2871 | 2854 |
assert formdata.get_substitution_variables()['xxx_var_date'] == '12/05/2015' |
2872 | 2855 | |
... | ... | |
2874 | 2857 |
'2015-05-12', '%Y-%m-%d' |
2875 | 2858 |
) |
2876 | 2859 | |
2877 |
two_pubs.cfg['language'] = {'language': 'en'}
|
|
2860 |
pub.cfg['language'] = {'language': 'en'}
|
|
2878 | 2861 | |
2879 | 2862 | |
2880 | 2863 |
def test_display_form_and_comment(pub): |
... | ... | |
3292 | 3275 |
assert formdata.get_criticality_level_object().name == 'green' |
3293 | 3276 | |
3294 | 3277 | |
3295 |
def test_geolocate_action_enable_geolocation(two_pubs):
|
|
3278 |
def test_geolocate_action_enable_geolocation(pub):
|
|
3296 | 3279 |
# switch to a workflow with geolocation |
3297 | 3280 |
formdef = FormDef() |
3298 | 3281 |
formdef.name = 'foo' |
... | ... | |
3342 | 3325 |
cur.close() |
3343 | 3326 | |
3344 | 3327 | |
3345 |
def test_geolocate_address(two_pubs):
|
|
3328 |
def test_geolocate_address(pub):
|
|
3346 | 3329 |
formdef = FormDef() |
3347 | 3330 |
formdef.geolocations = {'base': 'bla'} |
3348 | 3331 |
formdef.name = 'baz' |
... | ... | |
3355 | 3338 |
formdata.data = {'1': '169 rue du chateau'} |
3356 | 3339 |
formdata.just_created() |
3357 | 3340 |
formdata.store() |
3358 |
two_pubs.substitutions.feed(formdata)
|
|
3341 |
pub.substitutions.feed(formdata)
|
|
3359 | 3342 | |
3360 | 3343 |
item = GeolocateWorkflowStatusItem() |
3361 | 3344 |
item.method = 'address_string' |
... | ... | |
3374 | 3357 |
assert int(formdata.geolocations['base']['lat']) == 48 |
3375 | 3358 |
assert int(formdata.geolocations['base']['lon']) == 2 |
3376 | 3359 | |
3377 |
two_pubs.load_site_options()
|
|
3378 |
two_pubs.site_options.set('options', 'nominatim_key', 'KEY')
|
|
3360 |
pub.load_site_options()
|
|
3361 |
pub.site_options.set('options', 'nominatim_key', 'KEY')
|
|
3379 | 3362 |
with mock.patch('wcs.wf.geolocate.http_get_page') as http_get_page: |
3380 | 3363 |
http_get_page.return_value = ( |
3381 | 3364 |
None, |
... | ... | |
3390 | 3373 |
assert int(formdata.geolocations['base']['lat']) == 48 |
3391 | 3374 |
assert int(formdata.geolocations['base']['lon']) == 2 |
3392 | 3375 | |
3393 |
two_pubs.load_site_options()
|
|
3394 |
two_pubs.site_options.set('options', 'geocoding_service_url', 'http://example.net/')
|
|
3376 |
pub.load_site_options()
|
|
3377 |
pub.site_options.set('options', 'geocoding_service_url', 'http://example.net/')
|
|
3395 | 3378 |
with mock.patch('wcs.wf.geolocate.http_get_page') as http_get_page: |
3396 | 3379 |
http_get_page.return_value = ( |
3397 | 3380 |
None, |
... | ... | |
3402 | 3385 |
item.perform(formdata) |
3403 | 3386 |
assert 'http://example.net/?q=' in http_get_page.call_args[0][0] |
3404 | 3387 | |
3405 |
two_pubs.site_options.set('options', 'geocoding_service_url', 'http://example.net/?param=value')
|
|
3388 |
pub.site_options.set('options', 'geocoding_service_url', 'http://example.net/?param=value')
|
|
3406 | 3389 |
with mock.patch('wcs.wf.geolocate.http_get_page') as http_get_page: |
3407 | 3390 |
http_get_page.return_value = ( |
3408 | 3391 |
None, |
... | ... | |
3418 | 3401 |
formdata.geolocations = None |
3419 | 3402 |
item.perform(formdata) |
3420 | 3403 |
assert formdata.geolocations == {} |
3421 |
assert two_pubs.loggederror_class.count() == 1
|
|
3422 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
3404 |
assert pub.loggederror_class.count() == 1
|
|
3405 |
logged_error = pub.loggederror_class.select()[0]
|
|
3423 | 3406 |
assert ( |
3424 | 3407 |
logged_error.summary |
3425 | 3408 |
== 'error in template for address string [syntax error in ezt template: unclosed block at line 1 and column 24]' |
... | ... | |
3430 | 3413 |
logged_error.exception_message |
3431 | 3414 |
== 'syntax error in ezt template: unclosed block at line 1 and column 24' |
3432 | 3415 |
) |
3433 |
two_pubs.loggederror_class.wipe()
|
|
3416 |
pub.loggederror_class.wipe()
|
|
3434 | 3417 | |
3435 | 3418 |
# check for None |
3436 | 3419 |
item.address_string = '=None' |
... | ... | |
3459 | 3442 |
http_get_page.side_effect = ConnectionError('some error') |
3460 | 3443 |
item.perform(formdata) |
3461 | 3444 |
assert formdata.geolocations == {} |
3462 |
assert two_pubs.loggederror_class.count() == 1
|
|
3463 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
3445 |
assert pub.loggederror_class.count() == 1
|
|
3446 |
logged_error = pub.loggederror_class.select()[0]
|
|
3464 | 3447 |
assert logged_error.summary == 'error calling geocoding service [some error]' |
3465 | 3448 |
assert logged_error.formdata_id == str(formdata.id) |
3466 | 3449 |
assert logged_error.exception_class == 'ConnectionError' |
... | ... | |
3516 | 3499 |
assert formdata.geolocations == {} |
3517 | 3500 | |
3518 | 3501 | |
3519 |
def test_geolocate_map(two_pubs):
|
|
3502 |
def test_geolocate_map(pub):
|
|
3520 | 3503 |
formdef = FormDef() |
3521 | 3504 |
formdef.name = 'baz' |
3522 | 3505 |
formdef.geolocations = {'base': 'bla'} |
... | ... | |
3529 | 3512 |
formdata.data = {'2': '48.8337085;2.3233693'} |
3530 | 3513 |
formdata.just_created() |
3531 | 3514 |
formdata.store() |
3532 |
two_pubs.substitutions.feed(formdata)
|
|
3515 |
pub.substitutions.feed(formdata)
|
|
3533 | 3516 | |
3534 | 3517 |
item = GeolocateWorkflowStatusItem() |
3535 | 3518 |
item.method = 'map_variable' |
... | ... | |
3549 | 3532 |
formdata.geolocations = None |
3550 | 3533 |
formdata.data = {'2': '48.8337085'} |
3551 | 3534 |
item.map_variable = '=form_var_map' |
3552 |
assert two_pubs.loggederror_class.count() == 1
|
|
3553 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
3535 |
assert pub.loggederror_class.count() == 1
|
|
3536 |
logged_error = pub.loggederror_class.select()[0]
|
|
3554 | 3537 |
assert logged_error.summary == 'error geolocating from map variable' |
3555 | 3538 |
assert logged_error.formdata_id == str(formdata.id) |
3556 | 3539 |
assert logged_error.exception_class == 'ValueError' |
... | ... | |
3828 | 3811 |
assert b'>A <> name<' in new_content |
3829 | 3812 | |
3830 | 3813 | |
3831 |
def test_export_to_model_xml(two_pubs): |
|
3832 |
pub = two_pubs |
|
3814 |
def test_export_to_model_xml(pub): |
|
3833 | 3815 |
LoggedError = pub.loggederror_class |
3834 | 3816 |
if LoggedError: |
3835 | 3817 |
LoggedError.wipe() |
... | ... | |
3991 | 3973 | |
3992 | 3974 | |
3993 | 3975 |
@pytest.mark.parametrize('formdef_class', [FormDef, CardDef]) |
3994 |
def test_global_timeouts(two_pubs, formdef_class): |
|
3995 |
pub = two_pubs |
|
3976 |
def test_global_timeouts(pub, formdef_class): |
|
3996 | 3977 |
CardDef.wipe() |
3997 | 3978 |
FormDef.wipe() |
3998 | 3979 |
Workflow.wipe() |
... | ... | |
4263 | 4244 |
formdata1.store() |
4264 | 4245 | |
4265 | 4246 | |
4266 |
def test_global_timeouts_latest_arrival(two_pubs): |
|
4267 |
pub = two_pubs |
|
4247 |
def test_global_timeouts_latest_arrival(pub): |
|
4268 | 4248 |
FormDef.wipe() |
4269 | 4249 |
Workflow.wipe() |
4270 | 4250 | |
... | ... | |
4338 | 4318 |
assert formdef.data_class().get(formdata1.id).get_criticality_level_object().name == 'green' |
4339 | 4319 | |
4340 | 4320 | |
4341 |
def test_profile(two_pubs):
|
|
4342 |
User = two_pubs.user_class
|
|
4321 |
def test_profile(pub):
|
|
4322 |
User = pub.user_class
|
|
4343 | 4323 |
user = User() |
4344 | 4324 |
user.store() |
4345 | 4325 | |
... | ... | |
4373 | 4353 | |
4374 | 4354 |
from wcs.admin.settings import UserFieldsFormDef |
4375 | 4355 | |
4376 |
formdef = UserFieldsFormDef(two_pubs)
|
|
4356 |
formdef = UserFieldsFormDef(pub)
|
|
4377 | 4357 |
formdef.fields = [ |
4378 | 4358 |
StringField(id='3', label='test', type='string', varname='plop'), |
4379 | 4359 |
DateField(id='4', label='Date', type='date', varname='bar'), |
... | ... | |
4435 | 4415 |
assert http_patch_request.call_args[0][1] == '{"bar": null}' |
4436 | 4416 | |
4437 | 4417 |
# out of http request/response cycle (cron, after_job) |
4438 |
two_pubs._set_request(None)
|
|
4418 |
pub._set_request(None)
|
|
4439 | 4419 |
item.fields = [{'field_id': 'bar', 'value': '01/01/2020'}] |
4440 | 4420 |
with mock.patch('wcs.wf.profile.http_patch_request') as http_patch_request: |
4441 | 4421 |
http_patch_request.return_value = (None, 200, '', None) |
... | ... | |
4445 | 4425 |
assert http_patch_request.call_args[0][1] == '{"bar": "2020-01-01"}' |
4446 | 4426 | |
4447 | 4427 | |
4448 |
def test_set_backoffice_field(http_requests, two_pubs):
|
|
4428 |
def test_set_backoffice_field(http_requests, pub):
|
|
4449 | 4429 |
Workflow.wipe() |
4450 | 4430 |
FormDef.wipe() |
4451 | 4431 |
wf = Workflow(name='xxx') |
... | ... | |
4469 | 4449 |
formdata.data = {'00': 'HELLO'} |
4470 | 4450 |
formdata.just_created() |
4471 | 4451 |
formdata.store() |
4472 |
two_pubs.substitutions.feed(formdata)
|
|
4452 |
pub.substitutions.feed(formdata)
|
|
4473 | 4453 | |
4474 | 4454 |
item = SetBackofficeFieldsWorkflowStatusItem() |
4475 | 4455 |
item.parent = st1 |
... | ... | |
4546 | 4526 |
formdata = formdef.data_class().get(formdata.id) |
4547 | 4527 |
assert formdata.data['bo1'] == '' |
4548 | 4528 | |
4549 |
assert two_pubs.loggederror_class.count() == 0
|
|
4529 |
assert pub.loggederror_class.count() == 0
|
|
4550 | 4530 | |
4551 | 4531 |
item.fields = [{'field_id': 'bo1', 'value': '= ~ invalid python ~'}] |
4552 | 4532 |
item.perform(formdata) |
4553 | 4533 |
formdata = formdef.data_class().get(formdata.id) |
4554 |
assert two_pubs.loggederror_class.count() == 1
|
|
4555 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
4534 |
assert pub.loggederror_class.count() == 1
|
|
4535 |
logged_error = pub.loggederror_class.select()[0]
|
|
4556 | 4536 |
assert logged_error.summary == 'Failed to compute Python expression' |
4557 | 4537 |
assert logged_error.formdata_id == str(formdata.id) |
4558 | 4538 |
assert logged_error.expression == ' ~ invalid python ~' |
... | ... | |
4560 | 4540 |
assert logged_error.exception_class == 'SyntaxError' |
4561 | 4541 |
assert logged_error.exception_message == 'invalid syntax (<string>, line 1)' |
4562 | 4542 | |
4563 |
two_pubs.loggederror_class.wipe()
|
|
4543 |
pub.loggederror_class.wipe()
|
|
4564 | 4544 |
item.fields = [{'field_id': 'bo1', 'value': '{% if bad django %}'}] |
4565 | 4545 |
item.perform(formdata) |
4566 | 4546 |
formdata = formdef.data_class().get(formdata.id) |
4567 |
assert two_pubs.loggederror_class.count() == 1
|
|
4568 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
4547 |
assert pub.loggederror_class.count() == 1
|
|
4548 |
logged_error = pub.loggederror_class.select()[0]
|
|
4569 | 4549 |
assert logged_error.summary == 'Failed to compute template' |
4570 | 4550 |
assert logged_error.formdata_id == str(formdata.id) |
4571 | 4551 |
assert logged_error.expression == '{% if bad django %}' |
... | ... | |
4574 | 4554 |
assert logged_error.exception_message.startswith('syntax error in Django template') |
4575 | 4555 | |
4576 | 4556 | |
4577 |
def test_set_backoffice_field_map(http_requests, two_pubs):
|
|
4557 |
def test_set_backoffice_field_map(http_requests, pub):
|
|
4578 | 4558 |
Workflow.wipe() |
4579 | 4559 |
FormDef.wipe() |
4580 | 4560 |
wf = Workflow(name='xxx') |
... | ... | |
4598 | 4578 |
formdata.data = {'1': '42;10', '2': None} |
4599 | 4579 |
formdata.just_created() |
4600 | 4580 |
formdata.store() |
4601 |
two_pubs.substitutions.feed(formdata)
|
|
4581 |
pub.substitutions.feed(formdata)
|
|
4602 | 4582 | |
4603 | 4583 |
item = SetBackofficeFieldsWorkflowStatusItem() |
4604 | 4584 |
item.parent = st1 |
... | ... | |
4613 | 4593 |
formdata = formdef.data_class().get(formdata.id) |
4614 | 4594 |
assert formdata.data.get('bo1') is None |
4615 | 4595 | |
4616 |
assert two_pubs.loggederror_class.count() == 0
|
|
4596 |
assert pub.loggederror_class.count() == 0
|
|
4617 | 4597 | |
4618 | 4598 |
item.fields = [{'field_id': 'bo1', 'value': 'invalid value'}] |
4619 | 4599 |
item.perform(formdata) |
4620 | 4600 |
formdata = formdef.data_class().get(formdata.id) |
4621 |
assert two_pubs.loggederror_class.count() == 1
|
|
4622 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
4601 |
assert pub.loggederror_class.count() == 1
|
|
4602 |
logged_error = pub.loggederror_class.select()[0]
|
|
4623 | 4603 |
assert ( |
4624 | 4604 |
logged_error.summary |
4625 | 4605 |
== "Failed to set Map field (bo1), error: invalid coordinates 'invalid value' (missing ;)" |
... | ... | |
4627 | 4607 |
assert logged_error.formdata_id == str(formdata.id) |
4628 | 4608 |
assert logged_error.exception_class == 'SetValueError' |
4629 | 4609 |
assert logged_error.exception_message == "invalid coordinates 'invalid value' (missing ;)" |
4630 |
two_pubs.loggederror_class.wipe()
|
|
4610 |
pub.loggederror_class.wipe()
|
|
4631 | 4611 | |
4632 | 4612 |
item.fields = [{'field_id': 'bo1', 'value': 'XXX;YYY'}] |
4633 | 4613 |
item.perform(formdata) |
4634 | 4614 |
formdata = formdef.data_class().get(formdata.id) |
4635 |
assert two_pubs.loggederror_class.count() == 1
|
|
4636 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
4615 |
assert pub.loggederror_class.count() == 1
|
|
4616 |
logged_error = pub.loggederror_class.select()[0]
|
|
4637 | 4617 |
assert logged_error.summary == "Failed to set Map field (bo1), error: invalid coordinates 'XXX;YYY'" |
4638 | 4618 |
assert logged_error.formdata_id == str(formdata.id) |
4639 | 4619 |
assert logged_error.exception_class == 'SetValueError' |
4640 | 4620 |
assert logged_error.exception_message == "invalid coordinates 'XXX;YYY'" |
4641 |
two_pubs.loggederror_class.wipe()
|
|
4621 |
pub.loggederror_class.wipe()
|
|
4642 | 4622 | |
4643 | 4623 | |
4644 |
def test_set_backoffice_field_decimal(http_requests, two_pubs):
|
|
4624 |
def test_set_backoffice_field_decimal(http_requests, pub):
|
|
4645 | 4625 |
Workflow.wipe() |
4646 | 4626 |
FormDef.wipe() |
4647 | 4627 |
wf = Workflow(name='xxx') |
... | ... | |
4664 | 4644 |
formdata.data = {'1': '1000'} |
4665 | 4645 |
formdata.just_created() |
4666 | 4646 |
formdata.store() |
4667 |
two_pubs.substitutions.feed(formdata)
|
|
4647 |
pub.substitutions.feed(formdata)
|
|
4668 | 4648 | |
4669 | 4649 |
item = SetBackofficeFieldsWorkflowStatusItem() |
4670 | 4650 |
item.parent = st1 |
... | ... | |
4678 | 4658 |
assert formdef.data_class().get(formdata.id).data['bo1'] == '1000' |
4679 | 4659 | |
4680 | 4660 | |
4681 |
def test_set_backoffice_field_file(http_requests, two_pubs):
|
|
4661 |
def test_set_backoffice_field_file(http_requests, pub):
|
|
4682 | 4662 |
Workflow.wipe() |
4683 | 4663 |
FormDef.wipe() |
4684 | 4664 |
wf = Workflow(name='xxx') |
... | ... | |
4707 | 4687 |
formdata.data = {} |
4708 | 4688 |
formdata.just_created() |
4709 | 4689 |
formdata.store() |
4710 |
two_pubs.substitutions.feed(formdata)
|
|
4690 |
pub.substitutions.feed(formdata)
|
|
4711 | 4691 |
item.perform(formdata) |
4712 | 4692 |
formdata = formdef.data_class().get(formdata.id) |
4713 | 4693 |
assert formdata.data['bo1'] is None |
... | ... | |
4723 | 4703 |
formdata.just_created() |
4724 | 4704 |
formdata.store() |
4725 | 4705 | |
4726 |
two_pubs.substitutions.feed(formdata)
|
|
4706 |
pub.substitutions.feed(formdata)
|
|
4727 | 4707 |
item.perform(formdata) |
4728 | 4708 | |
4729 | 4709 |
formdata = formdef.data_class().get(formdata.id) |
... | ... | |
4738 | 4718 |
formdata.just_created() |
4739 | 4719 |
formdata.store() |
4740 | 4720 | |
4741 |
two_pubs.substitutions.feed(formdata)
|
|
4721 |
pub.substitutions.feed(formdata)
|
|
4742 | 4722 |
item.fields = [{'field_id': 'bo1', 'value': '{{form_var_file_raw}}'}] |
4743 | 4723 |
item.perform(formdata) |
4744 | 4724 | |
... | ... | |
4752 | 4732 |
formdata.just_created() |
4753 | 4733 |
formdata.store() |
4754 | 4734 | |
4755 |
two_pubs.substitutions.feed(formdata)
|
|
4735 |
pub.substitutions.feed(formdata)
|
|
4756 | 4736 |
item.fields = [{'field_id': 'bo1', 'value': '{{form_var_file}}'}] |
4757 | 4737 |
item.perform(formdata) |
4758 | 4738 | |
... | ... | |
4766 | 4746 |
formdata.just_created() |
4767 | 4747 |
formdata.store() |
4768 | 4748 | |
4769 |
two_pubs.substitutions.feed(formdata)
|
|
4749 |
pub.substitutions.feed(formdata)
|
|
4770 | 4750 |
item.fields = [{'field_id': 'bo1', 'value': '{{form_var_file|strip_metadata}}'}] |
4771 | 4751 |
item.perform(formdata) |
4772 | 4752 | |
... | ... | |
4781 | 4761 |
formdata.just_created() |
4782 | 4762 |
formdata.store() |
4783 | 4763 | |
4784 |
two_pubs.substitutions.feed(formdata)
|
|
4764 |
pub.substitutions.feed(formdata)
|
|
4785 | 4765 |
item.fields = [{'field_id': 'bo1', 'value': '{{form_var_file|rename_file:"foobar.jpeg"}}'}] |
4786 | 4766 |
item.perform(formdata) |
4787 | 4767 | |
... | ... | |
4794 | 4774 |
formdata.just_created() |
4795 | 4775 |
formdata.store() |
4796 | 4776 | |
4797 |
two_pubs.substitutions.feed(formdata)
|
|
4777 |
pub.substitutions.feed(formdata)
|
|
4798 | 4778 |
item.fields = [{'field_id': 'bo1', 'value': '{{form_var_file|rename_file:"foobar.$ext"}}'}] |
4799 | 4779 |
item.perform(formdata) |
4800 | 4780 | |
... | ... | |
4808 | 4788 |
formdata.just_created() |
4809 | 4789 |
formdata.store() |
4810 | 4790 | |
4811 |
two_pubs.substitutions.feed(formdata)
|
|
4791 |
pub.substitutions.feed(formdata)
|
|
4812 | 4792 | |
4813 | 4793 |
item.fields = [{'field_id': 'bo1', 'value': '{{"xxx"|rename_file:"foobar.jpeg"}}'}] |
4814 | 4794 |
item.perform(formdata) |
... | ... | |
4816 | 4796 |
assert 'bo1' not in formdata.data |
4817 | 4797 | |
4818 | 4798 |
# check with a template string, into a string field |
4819 |
two_pubs.substitutions.feed(formdata)
|
|
4799 |
pub.substitutions.feed(formdata)
|
|
4820 | 4800 |
item.fields = [{'field_id': 'bo2', 'value': '{{form_var_file}}'}] |
4821 | 4801 |
item.perform(formdata) |
4822 | 4802 | |
... | ... | |
4831 | 4811 |
assert formdata.data.get('bo1') is None |
4832 | 4812 | |
4833 | 4813 |
# check stripping metadata |
4834 |
two_pubs.substitutions.feed(formdata)
|
|
4814 |
pub.substitutions.feed(formdata)
|
|
4835 | 4815 |
item.fields = [ |
4836 | 4816 |
{ |
4837 | 4817 |
'field_id': 'bo1', |
... | ... | |
4845 | 4825 |
formdata.data = {'00': upload} |
4846 | 4826 |
formdata.just_created() |
4847 | 4827 |
formdata.store() |
4848 |
two_pubs.substitutions.feed(formdata)
|
|
4828 |
pub.substitutions.feed(formdata)
|
|
4849 | 4829 |
item.perform(formdata) |
4850 | 4830 |
formdata = formdef.data_class().get(formdata.id) |
4851 | 4831 |
assert formdata.data['bo1'].base_filename == 'new_test.jpeg' |
... | ... | |
4862 | 4842 |
formdata.data = {'00': upload2} |
4863 | 4843 |
formdata.just_created() |
4864 | 4844 |
formdata.store() |
4865 |
two_pubs.substitutions.feed(formdata)
|
|
4845 |
pub.substitutions.feed(formdata)
|
|
4866 | 4846 |
item.perform(formdata) |
4867 | 4847 |
formdata = formdef.data_class().get(formdata.id) |
4868 | 4848 |
assert formdata.data['bo1'].base_filename == 'new_test2.odt' |
... | ... | |
4871 | 4851 |
assert formdata.data['bo1'].qfilename == formdata.data['00'].qfilename |
4872 | 4852 | |
4873 | 4853 |
# check storing response as attachment |
4874 |
two_pubs.substitutions.feed(formdata)
|
|
4854 |
pub.substitutions.feed(formdata)
|
|
4875 | 4855 |
item = WebserviceCallStatusItem() |
4876 | 4856 |
item.url = 'http://remote.example.net/xml' |
4877 | 4857 |
item.varname = 'xxx' |
... | ... | |
4884 | 4864 |
assert attachment.content_type == 'text/xml' |
4885 | 4865 | |
4886 | 4866 |
formdata = formdef.data_class().get(formdata.id) |
4887 |
two_pubs.substitutions.feed(formdata)
|
|
4867 |
pub.substitutions.feed(formdata)
|
|
4888 | 4868 |
item = SetBackofficeFieldsWorkflowStatusItem() |
4889 | 4869 |
item.parent = st1 |
4890 | 4870 |
item.fields = [{'field_id': 'bo1', 'value': '=attachments.xxx'}] |
... | ... | |
4935 | 4915 |
item.parent = st1 |
4936 | 4916 |
item.fields = [{'field_id': 'bo1', 'value': value}] |
4937 | 4917 | |
4938 |
two_pubs.loggederror_class.wipe()
|
|
4918 |
pub.loggederror_class.wipe()
|
|
4939 | 4919 |
item.perform(formdata) |
4940 | 4920 | |
4941 | 4921 |
formdata = formdef.data_class().get(formdata.id) |
4942 | 4922 |
assert formdata.data['bo1'].base_filename == 'hello.txt' |
4943 | 4923 |
assert formdata.data['bo1'].get_content() == b'HELLO WORLD' |
4944 |
assert two_pubs.loggederror_class.count() == 1
|
|
4945 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
4924 |
assert pub.loggederror_class.count() == 1
|
|
4925 |
logged_error = pub.loggederror_class.select()[0]
|
|
4946 | 4926 |
assert logged_error.summary.startswith('Failed to convert') |
4947 | 4927 |
assert logged_error.formdata_id == str(formdata.id) |
4948 | 4928 |
assert logged_error.exception_class == 'ValueError' |
... | ... | |
4957 | 4937 |
assert formdata.data.get('bo3') is None |
4958 | 4938 | |
4959 | 4939 | |
4960 |
def test_set_backoffice_field_item(two_pubs):
|
|
4940 |
def test_set_backoffice_field_item(pub):
|
|
4961 | 4941 |
Workflow.wipe() |
4962 | 4942 |
FormDef.wipe() |
4963 | 4943 |
wf = Workflow(name='xxx') |
... | ... | |
5075 | 5055 |
assert formdata.data.get('bo1_structured') is None |
5076 | 5056 | |
5077 | 5057 | |
5078 |
def test_set_backoffice_field_card_item(two_pubs):
|
|
5058 |
def test_set_backoffice_field_card_item(pub):
|
|
5079 | 5059 |
CardDef.wipe() |
5080 | 5060 |
Workflow.wipe() |
5081 | 5061 |
FormDef.wipe() |
... | ... | |
5163 | 5143 |
assert formdata.data['bo1_structured']['attr'] == 'attr1' |
5164 | 5144 | |
5165 | 5145 |
# reset, with unknown value |
5166 |
two_pubs.loggederror_class.wipe()
|
|
5146 |
pub.loggederror_class.wipe()
|
|
5167 | 5147 |
formdata.data = {} |
5168 | 5148 |
formdata.store() |
5169 | 5149 |
item.fields = [{'field_id': 'bo1', 'value': 'xxx'}] |
... | ... | |
5172 | 5152 |
assert formdata.data.get('bo1') is None # invalid value is not stored |
5173 | 5153 |
assert formdata.data.get('bo1_display') is None |
5174 | 5154 |
assert formdata.data.get('bo1_structured') is None |
5175 |
assert two_pubs.loggederror_class.count() == 1
|
|
5176 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
5155 |
assert pub.loggederror_class.count() == 1
|
|
5156 |
logged_error = pub.loggederror_class.select()[0]
|
|
5177 | 5157 |
assert logged_error.summary.startswith('Failed to convert') |
5178 | 5158 | |
5179 | 5159 |
# reset, and get empty value |
... | ... | |
5187 | 5167 |
assert formdata.data.get('bo1_structured') is None |
5188 | 5168 | |
5189 | 5169 | |
5190 |
def test_set_backoffice_field_items(two_pubs):
|
|
5170 |
def test_set_backoffice_field_items(pub):
|
|
5191 | 5171 |
Workflow.wipe() |
5192 | 5172 |
FormDef.wipe() |
5193 | 5173 |
wf = Workflow(name='xxx') |
... | ... | |
5292 | 5272 |
formdata.data['1_structured'] = formdef.fields[0].store_structured_value(formdata.data, '1') |
5293 | 5273 |
formdata.just_created() |
5294 | 5274 |
formdata.store() |
5295 |
two_pubs.substitutions.feed(formdata)
|
|
5275 |
pub.substitutions.feed(formdata)
|
|
5296 | 5276 | |
5297 | 5277 |
item = SetBackofficeFieldsWorkflowStatusItem() |
5298 | 5278 |
item.parent = st1 |
... | ... | |
5312 | 5292 |
formdata.data['1_structured'] = formdef.fields[0].store_structured_value(formdata.data, '1') |
5313 | 5293 |
formdata.just_created() |
5314 | 5294 |
formdata.store() |
5315 |
two_pubs.substitutions.reset()
|
|
5316 |
two_pubs.substitutions.feed(formdata)
|
|
5295 |
pub.substitutions.reset()
|
|
5296 |
pub.substitutions.feed(formdata)
|
|
5317 | 5297 | |
5318 | 5298 |
item.fields = [{'field_id': 'bo1', 'value': "{{form_var_items_raw}}"}] |
5319 | 5299 |
item.perform(formdata) |
... | ... | |
5354 | 5334 |
# using an invalid value |
5355 | 5335 |
formdata.data = {} |
5356 | 5336 |
formdata.store() |
5357 |
two_pubs.loggederror_class.wipe()
|
|
5337 |
pub.loggederror_class.wipe()
|
|
5358 | 5338 |
item = SetBackofficeFieldsWorkflowStatusItem() |
5359 | 5339 |
item.parent = st1 |
5360 | 5340 |
item.fields = [{'field_id': 'bo1', 'value': "=Ellipsis"}] |
5361 | 5341 |
item.perform(formdata) |
5362 |
assert two_pubs.loggederror_class.count() == 1
|
|
5363 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
5342 |
assert pub.loggederror_class.count() == 1
|
|
5343 |
logged_error = pub.loggederror_class.select()[0]
|
|
5364 | 5344 |
assert 'Failed to convert' in logged_error.summary |
5365 | 5345 | |
5366 | 5346 |
# using a string with multiple values |
... | ... | |
5377 | 5357 |
assert {'id': 3, 'more': 'ccc', 'text': 'cc'} in formdata.data['bo1_structured'] |
5378 | 5358 | |
5379 | 5359 | |
5380 |
def test_set_backoffice_field_date(two_pubs):
|
|
5360 |
def test_set_backoffice_field_date(pub):
|
|
5381 | 5361 |
Workflow.wipe() |
5382 | 5362 |
FormDef.wipe() |
5383 | 5363 |
wf = Workflow(name='xxx') |
... | ... | |
5426 | 5406 |
assert datetime.date(*formdata.data['bo1'][:3]) == datetime.date(2017, 3, 23) |
5427 | 5407 | |
5428 | 5408 |
# invalid values => do nothing |
5429 |
assert two_pubs.loggederror_class.count() == 0
|
|
5409 |
assert pub.loggederror_class.count() == 0
|
|
5430 | 5410 |
for value in ('plop', '={}', '=[]'): |
5431 | 5411 |
item = SetBackofficeFieldsWorkflowStatusItem() |
5432 | 5412 |
item.parent = st1 |
5433 | 5413 |
item.fields = [{'field_id': 'bo1', 'value': value}] |
5434 | 5414 | |
5435 |
two_pubs.loggederror_class.wipe()
|
|
5415 |
pub.loggederror_class.wipe()
|
|
5436 | 5416 |
item.perform(formdata) |
5437 | 5417 |
formdata = formdef.data_class().get(formdata.id) |
5438 | 5418 |
assert datetime.date(*formdata.data['bo1'][:3]) == datetime.date(2017, 3, 23) |
5439 |
assert two_pubs.loggederror_class.count() == 1
|
|
5440 |
assert two_pubs.loggederror_class.select()[0].summary.startswith('Failed to convert')
|
|
5419 |
assert pub.loggederror_class.count() == 1
|
|
5420 |
assert pub.loggederror_class.select()[0].summary.startswith('Failed to convert')
|
|
5441 | 5421 | |
5442 | 5422 |
# None : empty date |
5443 | 5423 |
item = SetBackofficeFieldsWorkflowStatusItem() |
... | ... | |
5449 | 5429 |
assert formdata.data['bo1'] is None |
5450 | 5430 | |
5451 | 5431 | |
5452 |
def test_set_backoffice_field_boolean(two_pubs):
|
|
5432 |
def test_set_backoffice_field_boolean(pub):
|
|
5453 | 5433 |
Workflow.wipe() |
5454 | 5434 |
FormDef.wipe() |
5455 | 5435 |
wf = Workflow(name='xxx') |
... | ... | |
5493 | 5473 |
formdata.store() |
5494 | 5474 | |
5495 | 5475 | |
5496 |
def test_set_backoffice_field_str_time_filter(two_pubs):
|
|
5476 |
def test_set_backoffice_field_str_time_filter(pub):
|
|
5497 | 5477 |
Workflow.wipe() |
5498 | 5478 |
FormDef.wipe() |
5499 | 5479 |
wf = Workflow(name='xxx') |
... | ... | |
5536 | 5516 |
formdata.store() |
5537 | 5517 | |
5538 | 5518 | |
5539 |
def test_set_backoffice_field_block(two_pubs):
|
|
5519 |
def test_set_backoffice_field_block(pub):
|
|
5540 | 5520 |
BlockDef.wipe() |
5541 | 5521 |
Workflow.wipe() |
5542 | 5522 |
FormDef.wipe() |
... | ... | |
5616 | 5596 |
assert formdata.data['bo2'] == formdata.data['1_display'] |
5617 | 5597 | |
5618 | 5598 | |
5619 |
def test_set_backoffice_field_block_template_tag(two_pubs):
|
|
5599 |
def test_set_backoffice_field_block_template_tag(pub):
|
|
5620 | 5600 |
BlockDef.wipe() |
5621 | 5601 |
Workflow.wipe() |
5622 | 5602 |
FormDef.wipe() |
... | ... | |
5769 | 5749 |
assert formdata.data['bo1_display'] == 'XNoneY' |
5770 | 5750 | |
5771 | 5751 | |
5772 |
def test_set_backoffice_field_immediate_use(http_requests, two_pubs):
|
|
5752 |
def test_set_backoffice_field_immediate_use(http_requests, pub):
|
|
5773 | 5753 |
Workflow.wipe() |
5774 | 5754 |
FormDef.wipe() |
5775 | 5755 |
wf = Workflow(name='xxx') |
... | ... | |
5799 | 5779 |
item.fields = [ |
5800 | 5780 |
{'field_id': 'bo1', 'value': '{{form_var_string}}'}, |
5801 | 5781 |
] |
5802 |
two_pubs.substitutions.reset()
|
|
5803 |
two_pubs.substitutions.feed(formdata)
|
|
5782 |
pub.substitutions.reset()
|
|
5783 |
pub.substitutions.feed(formdata)
|
|
5804 | 5784 |
item.perform(formdata) |
5805 | 5785 |
formdata = formdef.data_class().get(formdata.id) |
5806 | 5786 |
assert formdata.data.get('bo1') == 'HELLO' |
... | ... | |
5808 | 5788 |
item.fields = [ |
5809 | 5789 |
{'field_id': 'bo1', 'value': 'WORLD'}, |
5810 | 5790 |
] |
5811 |
two_pubs.substitutions.reset()
|
|
5812 |
two_pubs.substitutions.feed(formdata)
|
|
5791 |
pub.substitutions.reset()
|
|
5792 |
pub.substitutions.feed(formdata)
|
|
5813 | 5793 |
item.perform(formdata) |
5814 | 5794 |
formdata = formdef.data_class().get(formdata.id) |
5815 | 5795 |
assert formdata.data.get('bo1') == 'WORLD' |
... | ... | |
5818 | 5798 |
{'field_id': 'bo1', 'value': 'X{{form_var_string}}X'}, |
5819 | 5799 |
{'field_id': 'bo2', 'value': "Y{{form_var_backoffice_blah}}Y"}, |
5820 | 5800 |
] |
5821 |
two_pubs.substitutions.reset()
|
|
5822 |
two_pubs.substitutions.feed(formdata)
|
|
5801 |
pub.substitutions.reset()
|
|
5802 |
pub.substitutions.feed(formdata)
|
|
5823 | 5803 |
item.perform(formdata) |
5824 | 5804 |
formdata = formdef.data_class().get(formdata.id) |
5825 | 5805 |
assert formdata.data.get('bo1') == 'XHELLOX' |
... | ... | |
5874 | 5854 |
assert reloaded_workflow.possible_status[0].items[0].condition == {'type': 'python', 'value': 'foobar'} |
5875 | 5855 | |
5876 | 5856 | |
5877 |
def test_workflow_action_condition(two_pubs):
|
|
5878 |
two_pubs._set_request(None) # to avoid after jobs
|
|
5857 |
def test_workflow_action_condition(pub):
|
|
5858 |
pub._set_request(None) # to avoid after jobs
|
|
5879 | 5859 |
workflow = Workflow(name='jump condition migration') |
5880 | 5860 |
st1 = workflow.add_status('Status1', 'st1') |
5881 | 5861 |
workflow.store() |
5882 | 5862 | |
5883 |
role = two_pubs.role_class(name='bar1')
|
|
5863 |
role = pub.role_class(name='bar1')
|
|
5884 | 5864 |
role.store() |
5885 | 5865 | |
5886 |
user = two_pubs.user_class()
|
|
5866 |
user = pub.user_class()
|
|
5887 | 5867 |
user.roles = [role.id] |
5888 | 5868 |
user.store() |
5889 | 5869 | |
... | ... | |
5919 | 5899 |
choice.condition = {'type': 'python', 'value': 'form_var_foo == "foo"'} |
5920 | 5900 |
workflow.store() |
5921 | 5901 | |
5922 |
with two_pubs.substitutions.temporary_feed(formdata1):
|
|
5902 |
with pub.substitutions.temporary_feed(formdata1):
|
|
5923 | 5903 |
assert FormDef.get(formdef.id).data_class().get(formdata1.id).get_actions_roles() == {role.id} |
5924 |
with two_pubs.substitutions.temporary_feed(formdata2):
|
|
5904 |
with pub.substitutions.temporary_feed(formdata2):
|
|
5925 | 5905 |
assert FormDef.get(formdef.id).data_class().get(formdata2.id).get_actions_roles() == set() |
5926 | 5906 | |
5927 | 5907 |
assert len(FormDef.get(formdef.id).data_class().get_actionable_ids([role.id])) == 1 |
... | ... | |
5936 | 5916 |
assert len(FormDef.get(formdef.id).data_class().get_actionable_ids([role.id])) == 2 |
5937 | 5917 | |
5938 | 5918 |
# bad condition |
5939 |
two_pubs.loggederror_class.wipe()
|
|
5919 |
pub.loggederror_class.wipe()
|
|
5940 | 5920 |
choice.condition = {'type': 'python', 'value': 'foobar == barfoo'} |
5941 | 5921 |
workflow.store() |
5942 | 5922 |
assert len(FormDef.get(formdef.id).data_class().get_actionable_ids([role.id])) == 0 |
5943 |
assert two_pubs.loggederror_class.count() == 1
|
|
5944 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
5923 |
assert pub.loggederror_class.count() == 1
|
|
5924 |
logged_error = pub.loggederror_class.select()[0]
|
|
5945 | 5925 |
assert logged_error.occurences_count > 1 # should be 2... == 12 with pickle, 4 with sql |
5946 | 5926 |
assert logged_error.summary == 'Failed to evaluate condition' |
5947 | 5927 |
assert logged_error.exception_class == 'NameError' |
... | ... | |
6030 | 6010 |
) |
6031 | 6011 | |
6032 | 6012 | |
6033 |
def test_call_external_workflow_with_evolution_linked_object(two_pubs):
|
|
6013 |
def test_call_external_workflow_with_evolution_linked_object(pub):
|
|
6034 | 6014 |
FormDef.wipe() |
6035 | 6015 |
CardDef.wipe() |
6036 | 6016 | |
... | ... | |
6126 | 6106 |
assert external_carddef.data_class().count() == 0 |
6127 | 6107 | |
6128 | 6108 | |
6129 |
def test_call_external_workflow_with_data_sourced_object(two_pubs, admin_user):
|
|
6109 |
def test_call_external_workflow_with_data_sourced_object(pub, admin_user):
|
|
6130 | 6110 |
FormDef.wipe() |
6131 | 6111 |
CardDef.wipe() |
6132 | 6112 | |
... | ... | |
6216 | 6196 |
perform_items([delete_action], formdata) |
6217 | 6197 | |
6218 | 6198 | |
6219 |
def test_call_external_workflow_with_items_data_sourced_object(two_pubs, admin_user):
|
|
6199 |
def test_call_external_workflow_with_items_data_sourced_object(pub, admin_user):
|
|
6220 | 6200 |
FormDef.wipe() |
6221 | 6201 |
CardDef.wipe() |
6222 | 6202 | |
... | ... | |
6464 | 6444 |
assert card.data['bo0'] == 'foo@example.com' # got called |
6465 | 6445 | |
6466 | 6446 | |
6467 |
def test_call_external_workflow_manual_targeting(two_pubs):
|
|
6447 |
def test_call_external_workflow_manual_targeting(pub):
|
|
6468 | 6448 |
FormDef.wipe() |
6469 | 6449 |
CardDef.wipe() |
6470 | 6450 | |
... | ... | |
6560 | 6540 |
assert carddef.data_class().get(2).data['bo0'] is None |
6561 | 6541 |
assert carddef.data_class().get(3).data['bo0'] is None |
6562 | 6542 |
assert carddef.data_class().get(4).data['bo0'] is None |
6563 |
assert two_pubs.loggederror_class.count() == 0
|
|
6543 |
assert pub.loggederror_class.count() == 0
|
|
6564 | 6544 | |
6565 | 6545 |
# configure target |
6566 | 6546 |
update_action.target_id = '{{ form_var_string }}' # == '1' |
... | ... | |
6579 | 6559 |
assert carddef.data_class().get(2).data['bo0'] is None |
6580 | 6560 |
assert carddef.data_class().get(3).data['bo0'] is None |
6581 | 6561 |
assert carddef.data_class().get(4).data['bo0'] is None |
6582 |
assert two_pubs.loggederror_class.count() == 1
|
|
6583 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
6562 |
assert pub.loggederror_class.count() == 1
|
|
6563 |
logged_error = pub.loggederror_class.select()[0]
|
|
6584 | 6564 |
assert logged_error.summary == 'Could not find targeted "Data" object by id 421' |
6585 | 6565 | |
6586 | 6566 |
# slug not or badly configured |
... | ... | |
6601 | 6581 |
assert carddef.data_class().get(4).data['bo0'] is None |
6602 | 6582 | |
6603 | 6583 | |
6604 |
def test_form_update_after_backoffice_fields(sql_pub):
|
|
6584 |
def test_form_update_after_backoffice_fields(pub): |
|
6605 | 6585 |
wf = Workflow(name='wf with backoffice field') |
6606 | 6586 |
wf.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(wf) |
6607 | 6587 |
wf.backoffice_fields_formdef.fields = [ |
... | ... | |
6644 | 6624 |
cur.close() |
6645 | 6625 | |
6646 | 6626 | |
6647 |
def test_call_external_workflow_manual_queryset_targeting(two_pubs):
|
|
6627 |
def test_call_external_workflow_manual_queryset_targeting(pub):
|
|
6648 | 6628 |
FormDef.wipe() |
6649 | 6629 |
CardDef.wipe() |
6650 | 6630 | |
... | ... | |
6763 | 6743 |
) |
6764 | 6744 |
wf.store() |
6765 | 6745 |
perform_items([update_action], formdata) |
6766 |
assert two_pubs.loggederror_class.count() == 1
|
|
6767 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
6746 |
assert pub.loggederror_class.count() == 1
|
|
6747 |
logged_error = pub.loggederror_class.select()[0]
|
|
6768 | 6748 |
assert logged_error.summary == 'Mismatch in target objects: expected "Other data", got "Data"' |
6769 | 6749 | |
6770 | 6750 |
# mismatch in target, with formdata |
6771 |
two_pubs.loggederror_class.wipe()
|
|
6751 |
pub.loggederror_class.wipe()
|
|
6772 | 6752 |
update_action.target_id = ( |
6773 | 6753 |
'{{cards|objects:"%s"|filter_by:"card_string"|filter_value:"Text 2"|first}}' % carddef.url_name |
6774 | 6754 |
) |
6775 | 6755 |
wf.store() |
6776 | 6756 |
perform_items([update_action], formdata) |
6777 |
assert two_pubs.loggederror_class.count() == 1
|
|
6778 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
6757 |
assert pub.loggederror_class.count() == 1
|
|
6758 |
logged_error = pub.loggederror_class.select()[0]
|
|
6779 | 6759 |
assert logged_error.summary == 'Mismatch in target object: expected "Other data", got "Data"' |
6780 | 6760 | |
6781 | 6761 | |
... | ... | |
6808 | 6788 |
assert formdata.evolution[0].parts[-1].actions[1][1:] == ('jump', str(jump2.id)) |
6809 | 6789 | |
6810 | 6790 | |
6811 |
def test_remove_tracking_code(two_pubs):
|
|
6791 |
def test_remove_tracking_code(pub):
|
|
6812 | 6792 |
formdef = FormDef() |
6813 | 6793 |
formdef.name = 'baz' |
6814 | 6794 |
formdef.enable_tracking_codes = True |
tests/workflow/test_carddata.py | ||
---|---|---|
38 | 38 |
return pub |
39 | 39 | |
40 | 40 | |
41 |
@pytest.fixture |
|
42 |
def two_pubs(request): |
|
43 |
pub = create_temporary_pub(sql_mode=True) |
|
44 |
pub.cfg['language'] = {'language': 'en'} |
|
45 |
pub.write_cfg() |
|
46 |
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''}) |
|
47 |
req.response.filter = {} |
|
48 |
req._user = None |
|
49 |
pub._set_request(req) |
|
50 |
req.session = sessions.BasicSession(id=1) |
|
51 |
pub.set_config(req) |
|
52 |
return pub |
|
53 | ||
54 | ||
55 |
def test_create_carddata(two_pubs): |
|
41 |
def test_create_carddata(pub): |
|
56 | 42 |
CardDef.wipe() |
57 | 43 |
FormDef.wipe() |
58 | 44 | |
... | ... | |
104 | 90 | |
105 | 91 |
assert carddef.data_class().count() == 1 |
106 | 92 | |
107 |
errors = two_pubs.loggederror_class.select()
|
|
93 |
errors = pub.loggederror_class.select()
|
|
108 | 94 |
assert len(errors) == 2 |
109 | 95 |
assert any('form_var_undefined' in (error.exception_message or '') for error in errors) |
110 | 96 |
assert any('invalid date value' in (error.exception_message or '') for error in errors) |
... | ... | |
316 | 302 |
assert carddata2.data['2'] == str(carddata1.id) |
317 | 303 | |
318 | 304 | |
319 |
def test_create_carddata_with_map_field(two_pubs):
|
|
305 |
def test_create_carddata_with_map_field(pub):
|
|
320 | 306 |
CardDef.wipe() |
321 | 307 |
FormDef.wipe() |
322 | 308 | |
... | ... | |
383 | 369 |
assert carddef.data_class().count() == 1 |
384 | 370 |
assert not carddef.data_class().select()[0].data.get('1') |
385 | 371 | |
386 |
errors = two_pubs.loggederror_class.select()
|
|
372 |
errors = pub.loggederror_class.select()
|
|
387 | 373 |
assert len(errors) == 1 |
388 | 374 |
assert any('invalid coordinates' in (error.exception_message or '') for error in errors) |
389 | 375 | |
... | ... | |
400 | 386 |
assert carddef.data_class().select()[0].data.get('1') == '2;3' |
401 | 387 | |
402 | 388 | |
403 |
def test_create_carddata_user_association(two_pubs):
|
|
389 |
def test_create_carddata_user_association(pub):
|
|
404 | 390 |
CardDef.wipe() |
405 | 391 |
FormDef.wipe() |
406 |
two_pubs.user_class.wipe()
|
|
392 |
pub.user_class.wipe()
|
|
407 | 393 | |
408 |
user = two_pubs.user_class()
|
|
394 |
user = pub.user_class()
|
|
409 | 395 |
user.email = 'test@example.net' |
410 | 396 |
user.name_identifiers = ['xyz'] |
411 | 397 |
user.store() |
412 |
user2 = two_pubs.user_class()
|
|
398 |
user2 = pub.user_class()
|
|
413 | 399 |
user2.store() |
414 | 400 | |
415 | 401 |
carddef = CardDef() |
... | ... | |
513 | 499 |
formdata.data = {} |
514 | 500 |
formdata.user_id = user.id |
515 | 501 |
formdata.just_created() |
516 |
if two_pubs.loggederror_class:
|
|
517 |
two_pubs.loggederror_class.wipe()
|
|
502 |
if pub.loggederror_class:
|
|
503 |
pub.loggederror_class.wipe()
|
|
518 | 504 |
formdata.perform_workflow() |
519 | 505 | |
520 | 506 |
assert carddef.data_class().count() == 1 |
521 | 507 |
assert carddef.data_class().select()[0].user is None |
522 |
if two_pubs.loggederror_class:
|
|
523 |
assert two_pubs.loggederror_class.count() == 1
|
|
524 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
508 |
if pub.loggederror_class:
|
|
509 |
assert pub.loggederror_class.count() == 1
|
|
510 |
logged_error = pub.loggederror_class.select()[0]
|
|
525 | 511 |
assert logged_error.summary == 'Failed to attach user (not found: "%s")' % invalid_user[1] |
526 | 512 |
assert logged_error.formdata_id == str(formdata.id) |
527 | 513 | |
... | ... | |
541 | 527 |
assert carddef.data_class().select()[0].user is None |
542 | 528 | |
543 | 529 | |
544 |
def test_create_carddata_map_fields_by_varname(two_pubs):
|
|
530 |
def test_create_carddata_map_fields_by_varname(pub):
|
|
545 | 531 |
CardDef.wipe() |
546 | 532 |
FormDef.wipe() |
547 |
two_pubs.user_class.wipe()
|
|
533 |
pub.user_class.wipe()
|
|
548 | 534 | |
549 | 535 |
carddef = CardDef() |
550 | 536 |
carddef.name = 'My card' |
... | ... | |
739 | 725 |
assert card_data.data['2'] == '3' |
740 | 726 | |
741 | 727 | |
742 |
def test_edit_carddata_manual_targeting(two_pubs):
|
|
728 |
def test_edit_carddata_manual_targeting(pub):
|
|
743 | 729 |
FormDef.wipe() |
744 | 730 |
CardDef.wipe() |
745 | 731 | |
... | ... | |
828 | 814 |
assert carddef.data_class().get(2).data['2'] == '0' |
829 | 815 |
assert carddef.data_class().get(3).data['2'] == '0' |
830 | 816 |
assert carddef.data_class().get(4).data['2'] == '2' |
831 |
assert two_pubs.loggederror_class.count() == 0
|
|
817 |
assert pub.loggederror_class.count() == 0
|
|
832 | 818 | |
833 | 819 |
# configure target |
834 | 820 |
edit.target_id = '{{ form_var_string }}' # == '1' |
... | ... | |
856 | 842 |
assert carddef.data_class().get(3).data['2'] == '0' |
857 | 843 |
assert carddef.data_class().get(4).data['2'] == '2' |
858 | 844 |
assert carddef.data_class().get(5).data['2'] == '2' |
859 |
assert two_pubs.loggederror_class.count() == 0
|
|
845 |
assert pub.loggederror_class.count() == 0
|
|
860 | 846 | |
861 | 847 |
# target not found |
862 | 848 |
edit.target_id = '42{{ form_var_string }}' # == '421' |
... | ... | |
885 | 871 |
assert carddef.data_class().get(4).data['2'] == '2' |
886 | 872 |
assert carddef.data_class().get(5).data['2'] == '2' |
887 | 873 |
assert carddef.data_class().get(6).data['2'] == '2' |
888 |
assert two_pubs.loggederror_class.count() == 1
|
|
889 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
874 |
assert pub.loggederror_class.count() == 1
|
|
875 |
logged_error = pub.loggederror_class.select()[0]
|
|
890 | 876 |
assert logged_error.summary == 'Could not find targeted "Parent" object by id 421' |
891 | 877 | |
892 | 878 |
# slug not or badly configured |
... | ... | |
1135 | 1121 |
assert str(card_data.user_id) == str(user.id) |
1136 | 1122 | |
1137 | 1123 | |
1138 |
def test_assign_carddata_manual_targeting(two_pubs):
|
|
1124 |
def test_assign_carddata_manual_targeting(pub):
|
|
1139 | 1125 |
FormDef.wipe() |
1140 | 1126 |
CardDef.wipe() |
1141 |
two_pubs.user_class.wipe()
|
|
1127 |
pub.user_class.wipe()
|
|
1142 | 1128 | |
1143 |
user = two_pubs.user_class()
|
|
1129 |
user = pub.user_class()
|
|
1144 | 1130 |
user.email = 'test@example.net' |
1145 | 1131 |
user.name_identifiers = ['xyz'] |
1146 | 1132 |
user.store() |
... | ... | |
1225 | 1211 |
assert carddef.data_class().get(2).user_id is None |
1226 | 1212 |
assert carddef.data_class().get(3).user_id is None |
1227 | 1213 |
assert carddef.data_class().get(4).user_id is None |
1228 |
assert two_pubs.loggederror_class.count() == 0
|
|
1214 |
assert pub.loggederror_class.count() == 0
|
|
1229 | 1215 | |
1230 | 1216 |
# configure target |
1231 | 1217 |
assign.target_id = '{{ form_var_string }}' # == '1' |
... | ... | |
1253 | 1239 |
assert carddef.data_class().get(3).user_id is None |
1254 | 1240 |
assert carddef.data_class().get(4).user_id is None |
1255 | 1241 |
assert carddef.data_class().get(5).user_id is None |
1256 |
assert two_pubs.loggederror_class.count() == 0
|
|
1242 |
assert pub.loggederror_class.count() == 0
|
|
1257 | 1243 | |
1258 | 1244 |
# target not found |
1259 | 1245 |
assign.target_id = '42{{ form_var_string }}' # == '424' |
... | ... | |
1282 | 1268 |
assert carddef.data_class().get(4).user_id is None # not changed |
1283 | 1269 |
assert carddef.data_class().get(5).user_id is None |
1284 | 1270 |
assert carddef.data_class().get(6).user_id is None |
1285 |
assert two_pubs.loggederror_class.count() == 1
|
|
1286 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
1271 |
assert pub.loggederror_class.count() == 1
|
|
1272 |
logged_error = pub.loggederror_class.select()[0]
|
|
1287 | 1273 |
assert logged_error.summary == 'Could not find targeted "Parent" object by id 424' |
1288 | 1274 | |
1289 | 1275 |
# slug not or badly configured |
... | ... | |
1435 | 1421 |
assert str(carddata_reloaded.user_id) == str(user.id) |
1436 | 1422 | |
1437 | 1423 | |
1438 |
def test_assign_carddata_user_association(two_pubs):
|
|
1424 |
def test_assign_carddata_user_association(pub):
|
|
1439 | 1425 |
CardDef.wipe() |
1440 | 1426 |
FormDef.wipe() |
1441 |
two_pubs.user_class.wipe()
|
|
1427 |
pub.user_class.wipe()
|
|
1442 | 1428 | |
1443 |
user = two_pubs.user_class()
|
|
1429 |
user = pub.user_class()
|
|
1444 | 1430 |
user.email = 'test@example.net' |
1445 | 1431 |
user.name_identifiers = ['xyz'] |
1446 | 1432 |
user.store() |
1447 |
user2 = two_pubs.user_class()
|
|
1433 |
user2 = pub.user_class()
|
|
1448 | 1434 |
user2.store() |
1449 | 1435 | |
1450 | 1436 |
carddef = CardDef() |
... | ... | |
1555 | 1541 |
formdata = FormDef.get(formdef.id).data_class()() |
1556 | 1542 |
formdata.data = {'0': '1'} |
1557 | 1543 |
formdata.just_created() |
1558 |
if two_pubs.loggederror_class:
|
|
1559 |
two_pubs.loggederror_class.wipe()
|
|
1544 |
if pub.loggederror_class:
|
|
1545 |
pub.loggederror_class.wipe()
|
|
1560 | 1546 |
formdata.perform_workflow() |
1561 | 1547 | |
1562 | 1548 |
assert carddef.data_class().select()[0].user is None |
1563 |
if two_pubs.loggederror_class:
|
|
1564 |
assert two_pubs.loggederror_class.count() == 1
|
|
1565 |
logged_error = two_pubs.loggederror_class.select()[0]
|
|
1549 |
if pub.loggederror_class:
|
|
1550 |
assert pub.loggederror_class.count() == 1
|
|
1551 |
logged_error = pub.loggederror_class.select()[0]
|
|
1566 | 1552 |
assert logged_error.summary == 'Failed to attach user (not found: "zzz")' |
1567 | 1553 |
assert logged_error.formdata_id == str(formdata.id) |
1568 | 1554 |
tests/workflow/test_formdata.py | ||
---|---|---|
34 | 34 |
return pub |
35 | 35 | |
36 | 36 | |
37 |
@pytest.fixture |
|
38 |
def two_pubs(request): |
|
39 |
pub = create_temporary_pub(sql_mode=True) |
|
40 |
pub.cfg['language'] = {'language': 'en'} |
|
41 |
pub.write_cfg() |
|
42 |
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''}) |
|
43 |
req.response.filter = {} |
|
44 |
req._user = None |
|
45 |
pub._set_request(req) |
|
46 |
req.session = sessions.BasicSession(id=1) |
|
47 |
pub.set_config(req) |
|
48 |
return pub |
|
49 | ||
50 | ||
51 |
def test_create_formdata(two_pubs): |
|
37 |
def test_create_formdata(pub): |
|
52 | 38 |
FormDef.wipe() |
53 |
two_pubs.tracking_code_class.wipe()
|
|
39 |
pub.tracking_code_class.wipe()
|
|
54 | 40 | |
55 | 41 |
target_formdef = FormDef() |
56 | 42 |
target_formdef.name = 'target form' |
... | ... | |
82 | 68 |
formdata.just_created() |
83 | 69 | |
84 | 70 |
assert target_formdef.data_class().count() == 0 |
85 |
assert two_pubs.loggederror_class.count() == 0
|
|
71 |
assert pub.loggederror_class.count() == 0
|
|
86 | 72 |
# check unconfigure action do nothing |
87 | 73 |
formdata.perform_workflow() |
88 | 74 |
assert target_formdef.data_class().count() == 0 |
... | ... | |
93 | 79 |
formdata.perform_workflow() |
94 | 80 |
assert target_formdef.data_class().count() == 1 |
95 | 81 | |
96 |
errors = two_pubs.loggederror_class.select()
|
|
82 |
errors = pub.loggederror_class.select()
|
|
97 | 83 |
assert len(errors) == 2 |
98 | 84 |
assert 'form_var_toto_string' in errors[0].exception_message |
99 | 85 |
assert errors[1].summary == 'Missing field: unknown (1), unknown (2)' |
... | ... | |
101 | 87 |
assert errors[1].formdata_id == str(target_formdef.data_class().select()[0].id) |
102 | 88 | |
103 | 89 |
# add field labels cache |
104 |
two_pubs.loggederror_class.wipe()
|
|
90 |
pub.loggederror_class.wipe()
|
|
105 | 91 |
target_formdef.data_class().wipe() |
106 | 92 |
create.formdef_slug = target_formdef.url_name |
107 | 93 |
create.cached_field_labels = {'0': 'field0', '1': 'field1', '2': 'field2'} |
... | ... | |
110 | 96 |
formdata.perform_workflow() |
111 | 97 |
assert target_formdef.data_class().count() == 1 |
112 | 98 | |
113 |
errors = two_pubs.loggederror_class.select()
|
|
99 |
errors = pub.loggederror_class.select()
|
|
114 | 100 |
assert len(errors) == 2 |
115 | 101 |
assert errors[1].summary == 'Missing field: field1, field2' |
116 | 102 | |
117 | 103 |
# no tracking code has been created |
118 | 104 |
created_formdata = target_formdef.data_class().select()[0] |
119 | 105 |
assert created_formdata.tracking_code is None |
120 |
assert two_pubs.tracking_code_class.count() == 0
|
|
106 |
assert pub.tracking_code_class.count() == 0
|
|
121 | 107 |
# now we want one |
122 | 108 |
target_formdef.enable_tracking_codes = True |
123 | 109 |
target_formdef.store() |
... | ... | |
127 | 113 |
assert target_formdef.data_class().count() == 1 |
128 | 114 |
created_formdata = target_formdef.data_class().select()[0] |
129 | 115 |
assert created_formdata.tracking_code is not None |
130 |
assert two_pubs.tracking_code_class.count() == 1
|
|
131 |
assert two_pubs.tracking_code_class.select()[0].formdef_id == target_formdef.id
|
|
132 |
assert two_pubs.tracking_code_class.select()[0].formdata_id == str(created_formdata.id)
|
|
116 |
assert pub.tracking_code_class.count() == 1
|
|
117 |
assert pub.tracking_code_class.select()[0].formdef_id == target_formdef.id
|
|
118 |
assert pub.tracking_code_class.select()[0].formdata_id == str(created_formdata.id)
|
|
133 | 119 | |
134 | 120 |
create.condition = {'type': 'python', 'value': '1 == 2'} |
135 | 121 |
wf.store() |
... | ... | |
160 | 146 |
assert not hasattr(wf.possible_status[0].items[0], 'keep_user') |
161 | 147 | |
162 | 148 | |
163 |
def test_create_formdata_tracking_code(two_pubs, emails):
|
|
149 |
def test_create_formdata_tracking_code(pub, emails):
|
|
164 | 150 |
FormDef.wipe() |
165 |
two_pubs.tracking_code_class.wipe()
|
|
151 |
pub.tracking_code_class.wipe()
|
|
166 | 152 | |
167 | 153 |
target_wf = Workflow(name='send-mail') |
168 | 154 |
st1 = target_wf.add_status('Status1', 'st1') |
... | ... | |
213 | 199 |
assert tracking_code in emails.get('Foobar')['payload'] |
214 | 200 | |
215 | 201 | |
216 |
def test_create_formdata_attach_to_history(two_pubs):
|
|
202 |
def test_create_formdata_attach_to_history(pub):
|
|
217 | 203 |
FormDef.wipe() |
218 |
two_pubs.tracking_code_class.wipe()
|
|
204 |
pub.tracking_code_class.wipe()
|
|
219 | 205 | |
220 | 206 |
target_formdef = FormDef() |
221 | 207 |
target_formdef.name = 'target form' |
... | ... | |
270 | 256 |
assert 'New form created (deleted, 1-1)' in str(formdata.evolution[-1].parts[0].view()) |
271 | 257 | |
272 | 258 | |
273 |
def test_create_formdata_card_item_mapping(two_pubs):
|
|
274 |
two_pubs.loggederror_class.wipe()
|
|
259 |
def test_create_formdata_card_item_mapping(pub):
|
|
260 |
pub.loggederror_class.wipe()
|
|
275 | 261 |
FormDef.wipe() |
276 | 262 |
CardDef.wipe() |
277 | 263 | |
... | ... | |
363 | 349 |
target_formdata = target_formdef.data_class().select()[0] |
364 | 350 |
assert target_formdata.data.get('0') is None |
365 | 351 |
assert target_formdata.data.get('0_display') is None |
366 |
assert two_pubs.loggederror_class.count() == 1
|
|
367 |
assert two_pubs.loggederror_class.count() == 1
|
|
368 |
error = two_pubs.loggederror_class.select()[0]
|
|
352 |
assert pub.loggederror_class.count() == 1
|
|
353 |
assert pub.loggederror_class.count() == 1
|
|
354 |
error = pub.loggederror_class.select()[0]
|
|
369 | 355 |
assert error.exception_message == "unknown card value ('XXX')" |
tests/workflow/test_notification.py | ||
---|---|---|
20 | 20 |
clean_temporary_pub() |
21 | 21 | |
22 | 22 | |
23 |
def pub_fixture(**kwargs): |
|
24 |
pub = create_temporary_pub(**kwargs) |
|
23 |
@pytest.fixture |
|
24 |
def pub(): |
|
25 |
pub = create_temporary_pub() |
|
25 | 26 |
pub.cfg['language'] = {'language': 'en'} |
26 | 27 |
pub.write_cfg() |
27 | 28 |
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''}) |
... | ... | |
33 | 34 |
return pub |
34 | 35 | |
35 | 36 | |
36 |
@pytest.fixture |
|
37 |
def pub(request): |
|
38 |
return pub_fixture() |
|
39 | ||
40 | ||
41 |
@pytest.fixture |
|
42 |
def sql_pub(request): |
|
43 |
return pub_fixture(sql_mode=True) |
|
44 | ||
45 | ||
46 | 37 |
def test_notifications(pub, http_requests): |
47 | 38 |
pub.user_class.wipe() |
48 | 39 |
FormDef.wipe() |
... | ... | |
152 | 143 |
assert set(json.loads(http_requests.get_last('body'))['name_ids']) == {'xxy1'} |
153 | 144 | |
154 | 145 | |
155 |
def test_notifications_to_users_template(sql_pub, http_requests):
|
|
156 |
sql_pub.user_class.wipe()
|
|
146 |
def test_notifications_to_users_template(pub, http_requests): |
|
147 |
pub.user_class.wipe() |
|
157 | 148 |
FormDef.wipe() |
158 | 149 | |
159 |
user1 = sql_pub.user_class(name='userA')
|
|
150 |
user1 = pub.user_class(name='userA') |
|
160 | 151 |
user1.name_identifiers = ['xxy1'] |
161 | 152 |
user1.email = 'user1@example.com' |
162 | 153 |
user1.store() |
163 |
user2 = sql_pub.user_class(name='userB')
|
|
154 |
user2 = pub.user_class(name='userB') |
|
164 | 155 |
user2.name_identifiers = ['xxy2'] |
165 | 156 |
user2.email = 'user2@example.com' |
166 | 157 |
user2.store() |
... | ... | |
193 | 184 |
formdata.store() |
194 | 185 | |
195 | 186 |
assert not SendNotificationWorkflowStatusItem.is_available() |
196 |
if not sql_pub.site_options.has_section('variables'):
|
|
197 |
sql_pub.site_options.add_section('variables')
|
|
198 |
sql_pub.site_options.set('variables', 'portal_url', 'https://portal/')
|
|
187 |
if not pub.site_options.has_section('variables'): |
|
188 |
pub.site_options.add_section('variables') |
|
189 |
pub.site_options.set('variables', 'portal_url', 'https://portal/') |
|
199 | 190 |
assert SendNotificationWorkflowStatusItem.is_available() |
200 | 191 | |
201 | 192 |
item = SendNotificationWorkflowStatusItem() |
... | ... | |
254 | 245 |
item.perform(formdata) |
255 | 246 |
assert http_requests.count() == 1 |
256 | 247 |
assert set(json.loads(http_requests.get_last('body'))['name_ids']) == {'xxy1'} |
257 |
assert sql_pub.loggederror_class.count() == 1
|
|
258 |
logged_error = sql_pub.loggederror_class.select()[0]
|
|
248 |
assert pub.loggederror_class.count() == 1 |
|
249 |
logged_error = pub.loggederror_class.select()[0] |
|
259 | 250 |
assert logged_error.summary == 'Failed to notify user (not found: "foobar")' |
260 | 251 |
assert logged_error.formdata_id == str(formdata.id) |
261 | 252 | |
... | ... | |
264 | 255 |
http_requests.empty() |
265 | 256 |
item.perform(formdata) |
266 | 257 |
assert http_requests.count() == 0 |
267 |
assert sql_pub.loggederror_class.count() == 2
|
|
268 |
logged_error = sql_pub.loggederror_class.select()[1]
|
|
258 |
assert pub.loggederror_class.count() == 2 |
|
259 |
logged_error = pub.loggederror_class.select()[1] |
|
269 | 260 |
assert logged_error.summary == 'Failed to notify users, bad template result (None)' |
270 | 261 |
assert logged_error.formdata_id == str(formdata.id) |
271 | 262 | |
... | ... | |
274 | 265 |
http_requests.empty() |
275 | 266 |
item.perform(formdata) |
276 | 267 |
assert http_requests.count() == 0 |
277 |
assert sql_pub.loggederror_class.count() == 3
|
|
278 |
logged_error = sql_pub.loggederror_class.select()[2]
|
|
268 |
assert pub.loggederror_class.count() == 3 |
|
269 |
logged_error = pub.loggederror_class.select()[2] |
|
279 | 270 |
assert logged_error.summary == 'Failed to compute template' |
280 | 271 |
assert logged_error.formdata_id == str(formdata.id) |
281 | 272 | |
282 | 273 | |
283 |
def test_notifications_target_url(sql_pub, http_requests): |
|
284 |
pub = sql_pub |
|
274 |
def test_notifications_target_url(pub, http_requests): |
|
285 | 275 |
pub.substitutions.feed(pub) |
286 | 276 |
pub.user_class.wipe() |
287 | 277 |
user = pub.user_class() |
288 |
- |