From fd1e828490be93b6fd40abe080e60dc691d80902 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Tue, 1 Mar 2022 16:11:17 +0100
Subject: [PATCH 3/4] misc: split some tests (#58796)

---
 tests/admin_pages/test_all.py    | 36 ------------------
 tests/admin_pages/test_studio.py | 64 ++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 36 deletions(-)
 create mode 100644 tests/admin_pages/test_studio.py

diff --git a/tests/admin_pages/test_all.py b/tests/admin_pages/test_all.py
index f962bc77d..eb75107b8 100644
--- a/tests/admin_pages/test_all.py
+++ b/tests/admin_pages/test_all.py
@@ -162,39 +162,3 @@ def test_users_roles_menu_entries(pub):
     resp = app.get('/backoffice/menu.json')
     assert 'Users' not in [x['label'] for x in resp.json]
     assert 'Roles' not in [x['label'] for x in resp.json]
-
-
-def test_studio_home(pub):
-    create_superuser(pub)
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/')
-    assert 'studio' in resp.text
-    resp = app.get('/backoffice/studio/')
-    assert '../forms/' in resp.text
-    assert '../cards/' in resp.text
-    assert '../workflows/' in resp.text
-    assert 'Logged Errors' in resp.text
-
-    pub.cfg['admin-permissions'] = {}
-    for part in ('forms', 'cards', 'workflows'):
-        # check section link are not displayed if user has no access right
-        pub.cfg['admin-permissions'].update({part: ['x']})  # block access
-        pub.write_cfg()
-        if part != 'workflows':
-            resp = app.get('/backoffice/studio/')
-            assert '../%s/' % part not in resp.text
-        else:
-            resp = app.get('/backoffice/studio/', status=403)  # totally closed
-
-    resp = app.get('/backoffice/')
-    assert 'studio' not in resp.text
-
-
-def test_studio_workflows(pub):
-    create_superuser(pub)
-    app = login(get_app(pub))
-    resp = app.get('/backoffice/workflows/')
-    resp = resp.click(r'Default \(cards\)')
-    assert 'status/recorded/' in resp.text
-    assert 'status/deleted/' in resp.text
-    assert 'This is the default workflow,' in resp.text
diff --git a/tests/admin_pages/test_studio.py b/tests/admin_pages/test_studio.py
new file mode 100644
index 000000000..ce74b58bf
--- /dev/null
+++ b/tests/admin_pages/test_studio.py
@@ -0,0 +1,64 @@
+import pytest
+
+from wcs.qommon.http_request import HTTPRequest
+
+from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, login
+from .test_all import create_superuser
+
+
+def pytest_generate_tests(metafunc):
+    if 'pub' in metafunc.fixturenames:
+        metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
+
+
+@pytest.fixture
+def pub(request):
+    pub = create_temporary_pub(sql_mode=bool('sql' in request.param))
+
+    req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
+    pub.set_app_dir(req)
+    pub.cfg['identification'] = {'methods': ['password']}
+    pub.cfg['language'] = {'language': 'en'}
+    pub.write_cfg()
+
+    return pub
+
+
+def teardown_module(module):
+    clean_temporary_pub()
+
+
+def test_studio_home(pub):
+    create_superuser(pub)
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/')
+    assert 'studio' in resp.text
+    resp = app.get('/backoffice/studio/')
+    assert '../forms/' in resp.text
+    assert '../cards/' in resp.text
+    assert '../workflows/' in resp.text
+    assert 'Logged Errors' in resp.text
+
+    pub.cfg['admin-permissions'] = {}
+    for part in ('forms', 'cards', 'workflows'):
+        # check section link are not displayed if user has no access right
+        pub.cfg['admin-permissions'].update({part: ['x']})  # block access
+        pub.write_cfg()
+        if part != 'workflows':
+            resp = app.get('/backoffice/studio/')
+            assert '../%s/' % part not in resp.text
+        else:
+            resp = app.get('/backoffice/studio/', status=403)  # totally closed
+
+    resp = app.get('/backoffice/')
+    assert 'studio' not in resp.text
+
+
+def test_studio_workflows(pub):
+    create_superuser(pub)
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/workflows/')
+    resp = resp.click(r'Default \(cards\)')
+    assert 'status/recorded/' in resp.text
+    assert 'status/deleted/' in resp.text
+    assert 'This is the default workflow,' in resp.text
-- 
2.34.1

