From 6a303013c9bb99cf9e576a151852ff9ef8c47cf9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 8 Apr 2022 17:43:54 +0200
Subject: [PATCH] misc: remove pickle auto tests from admin_pages (#65241)

---
 tests/admin_pages/test_all.py             |  7 +--
 tests/admin_pages/test_api_access.py      |  7 +--
 tests/admin_pages/test_block.py           |  7 +--
 tests/admin_pages/test_card.py            | 51 +++++++++++----
 tests/admin_pages/test_carddefcategory.py |  7 +--
 tests/admin_pages/test_category.py        |  7 +--
 tests/admin_pages/test_datasource.py      | 34 +++++-----
 tests/admin_pages/test_form.py            | 75 +++++++++++++++--------
 tests/admin_pages/test_role.py            |  7 +--
 tests/admin_pages/test_settings.py        | 11 +---
 tests/admin_pages/test_studio.py          |  7 +--
 tests/admin_pages/test_user.py            |  7 +--
 tests/admin_pages/test_workflow.py        | 18 ++----
 tests/admin_pages/test_wscall.py          |  7 +--
 14 files changed, 120 insertions(+), 132 deletions(-)

diff --git a/tests/admin_pages/test_all.py b/tests/admin_pages/test_all.py
index eb75107b8..03744e7a2 100644
--- a/tests/admin_pages/test_all.py
+++ b/tests/admin_pages/test_all.py
@@ -8,14 +8,9 @@ from wcs.qommon.ident.password_accounts import PasswordAccount
 from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, login
 
 
-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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
diff --git a/tests/admin_pages/test_api_access.py b/tests/admin_pages/test_api_access.py
index 2013dd7af..3c48acb7a 100644
--- a/tests/admin_pages/test_api_access.py
+++ b/tests/admin_pages/test_api_access.py
@@ -23,14 +23,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
diff --git a/tests/admin_pages/test_block.py b/tests/admin_pages/test_block.py
index e7f349d20..4e9a269bf 100644
--- a/tests/admin_pages/test_block.py
+++ b/tests/admin_pages/test_block.py
@@ -15,14 +15,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 from .test_all import create_role, 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
diff --git a/tests/admin_pages/test_card.py b/tests/admin_pages/test_card.py
index cb3840a58..9dbd3949f 100644
--- a/tests/admin_pages/test_card.py
+++ b/tests/admin_pages/test_card.py
@@ -19,14 +19,8 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+def pub_fixture(**kwargs):
+    pub = create_temporary_pub(**kwargs)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
@@ -37,6 +31,16 @@ def pub(request):
     return pub
 
 
+@pytest.fixture
+def pub(request, emails):
+    return pub_fixture(sql_mode=True)
+
+
+@pytest.fixture
+def nosql_pub(request, emails):
+    return pub_fixture()
+
+
 def teardown_module(module):
     clean_temporary_pub()
 
@@ -141,11 +145,10 @@ def test_cards_delete(pub):
     app = login(get_app(pub))
     resp = app.get('http://example.net/backoffice/cards/1/')
     resp = resp.click('Delete')
-    if pub.is_using_postgresql():
-        assert 'Deletion is not possible as there are cards.' in resp
-        carddef.data_class().wipe()
-        resp = app.get('http://example.net/backoffice/cards/1/')
-        resp = resp.click('Delete')
+    assert 'Deletion is not possible as there are cards.' in resp
+    carddef.data_class().wipe()
+    resp = app.get('http://example.net/backoffice/cards/1/')
+    resp = resp.click('Delete')
 
     resp = resp.form.submit('submit')
     assert CardDef.count() == 1
@@ -157,6 +160,28 @@ def test_cards_delete(pub):
     carddata.remove_self()  # don't keep leftovers
 
 
+def test_cards_delete_nosql(nosql_pub):
+    pub = nosql_pub
+    create_superuser(pub)
+
+    CardDef.wipe()
+    carddef = CardDef()
+    carddef.name = 'card title'
+    carddef.fields = []
+    carddef.store()
+
+    carddata = carddef.data_class()()
+    carddata.just_created()
+    carddata.data = {}
+    carddata.store()
+
+    app = login(get_app(pub))
+    resp = app.get('http://example.net/backoffice/cards/1/')
+    resp = resp.click('Delete')
+    assert 'Deletion is not possible as there are cards.' not in resp
+    assert 'delete-button' in resp.text
+
+
 def test_cards_in_use_delete(pub):
     CardDef.wipe()
     carddef = CardDef()
diff --git a/tests/admin_pages/test_carddefcategory.py b/tests/admin_pages/test_carddefcategory.py
index 8079882b3..f71cce17e 100644
--- a/tests/admin_pages/test_carddefcategory.py
+++ b/tests/admin_pages/test_carddefcategory.py
@@ -9,14 +9,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
diff --git a/tests/admin_pages/test_category.py b/tests/admin_pages/test_category.py
index bbcd96cf8..ca481289c 100644
--- a/tests/admin_pages/test_category.py
+++ b/tests/admin_pages/test_category.py
@@ -8,14 +8,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
diff --git a/tests/admin_pages/test_datasource.py b/tests/admin_pages/test_datasource.py
index 17d4e1b31..76b4de775 100644
--- a/tests/admin_pages/test_datasource.py
+++ b/tests/admin_pages/test_datasource.py
@@ -21,11 +21,6 @@ from ..utilities import HttpRequestsMocking, clean_temporary_pub, create_tempora
 from .test_all import create_superuser
 
 
-def pytest_generate_tests(metafunc):
-    if 'pub' in metafunc.fixturenames:
-        metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
-
-
 def pub_fixture(**kwargs):
     pub = create_temporary_pub(**kwargs)
 
@@ -40,12 +35,12 @@ def pub_fixture(**kwargs):
 
 @pytest.fixture
 def pub(request, emails):
-    return pub_fixture(sql_mode=bool('sql' in request.param))
+    return pub_fixture(sql_mode=True)
 
 
 @pytest.fixture
-def sql_pub(request, emails):
-    return pub_fixture(sql_mode=True)
+def nosql_pub(request, emails):
+    return pub_fixture()
 
 
 def teardown_module(module):
@@ -150,17 +145,24 @@ def test_data_sources_agenda(pub, chrono_url):
     )
 
 
-def test_data_sources_users(pub):
+def test_data_sources_users_no_sql(nosql_pub):
+    pub = nosql_pub
     create_superuser(pub)
     NamedDataSource.wipe()
 
     app = login(get_app(pub))
     resp = app.get('/backoffice/settings/data-sources/')
 
-    if not pub.is_using_postgresql():
-        assert 'Users Data Sources' not in resp
-        assert 'new-users' not in resp
-        return
+    assert 'Users Data Sources' not in resp
+    assert 'new-users' not in resp
+
+
+def test_data_sources_users(pub):
+    create_superuser(pub)
+    NamedDataSource.wipe()
+
+    app = login(get_app(pub))
+    resp = app.get('/backoffice/settings/data-sources/')
 
     assert 'Users Data Sources' in resp
     assert 'There are no users data sources defined.' in resp
@@ -218,8 +220,7 @@ def test_data_sources_new(pub):
     assert NamedDataSource.count() == 2
 
 
-def test_data_sources_users_new(sql_pub):
-    pub = sql_pub
+def test_data_sources_users_new(pub):
     create_superuser(pub)
     NamedDataSource.wipe()
     DataSourceCategory.wipe()
@@ -418,8 +419,7 @@ def test_data_sources_view(pub):
     data_source.store()
     resp = app.get('/backoffice/settings/data-sources/%s/' % data_source.id)
     assert 'Preview' not in resp.text
-    if pub.is_using_postgresql():
-        assert pub.loggederror_class.count() == 0  # error not recorded
+    assert pub.loggederror_class.count() == 0  # error not recorded
 
     # check geojson
     geojson_file_path = os.path.join(pub.app_dir, 'test.geojson')
diff --git a/tests/admin_pages/test_form.py b/tests/admin_pages/test_form.py
index 942ba55ef..93dcc0ea1 100644
--- a/tests/admin_pages/test_form.py
+++ b/tests/admin_pages/test_form.py
@@ -23,14 +23,8 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 from .test_all import create_role, 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))
+def pub_fixture(**kwargs):
+    pub = create_temporary_pub(**kwargs)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
@@ -41,6 +35,16 @@ def pub(request):
     return pub
 
 
+@pytest.fixture
+def pub(request, emails):
+    return pub_fixture(sql_mode=True)
+
+
+@pytest.fixture
+def nosql_pub(request, emails):
+    return pub_fixture()
+
+
 def teardown_module(module):
     clean_temporary_pub()
 
@@ -693,7 +697,7 @@ def test_form_workflow_link(pub):
     assert '/backoffice/workflows/%s/' % workflow.id not in resp.text
 
 
-def test_form_workflow_remapping(pub):
+def _test_form_workflow_remapping(pub):
     create_superuser(pub)
     create_role(pub)
 
@@ -781,6 +785,14 @@ def test_form_workflow_remapping(pub):
     FormDef.get(formdef.id).data_class().select()
 
 
+def test_form_workflow_remapping(pub):
+    _test_form_workflow_remapping(pub)
+
+
+def test_form_workflow_remapping_nosql(nosql_pub):
+    _test_form_workflow_remapping(nosql_pub)
+
+
 def test_form_submitter_roles(pub):
     create_superuser(pub)
     create_role(pub)
@@ -1184,8 +1196,7 @@ def test_form_delete_with_data(pub):
 
     resp = app.get('/backoffice/forms/%s/' % formdef.id)
     resp = resp.click(href='delete')
-    if pub.is_using_postgresql():
-        assert 'Deletion is not possible' in resp
+    assert 'Deletion is not possible' in resp
 
     formdata.status = 'draft'
     formdata.store()
@@ -1200,6 +1211,28 @@ def test_form_delete_with_data(pub):
     assert 'Deletion is not possible' not in resp
 
 
+def test_form_delete_with_data_nosql(nosql_pub):
+    pub = nosql_pub
+    create_superuser(pub)
+    create_role(pub)
+
+    FormDef.wipe()
+    formdef = FormDef()
+    formdef.name = 'form title'
+    formdef.fields = []
+    formdef.store()
+
+    formdata = formdef.data_class()()
+    formdata.just_created()
+    formdata.store()
+
+    app = login(get_app(pub))
+
+    resp = app.get('/backoffice/forms/%s/' % formdef.id)
+    resp = resp.click(href='delete')
+    assert 'Deletion is not possible' not in resp
+
+
 def test_form_duplicate(pub):
     create_superuser(pub)
     create_role(pub)
@@ -2094,8 +2127,7 @@ def test_form_edit_item_field_data_source(pub):
     resp.form.submit('submit').follow()
     resp = app.get('/backoffice/forms/1/')
     assert FormDef.get(formdef.id).fields[0].data_source == {'type': 'foobar'}
-    if pub.is_using_postgresql():
-        assert pub.loggederror_class.count() == 0  # error not recorded
+    assert pub.loggederror_class.count() == 0  # error not recorded
 
     carddef = CardDef()
     carddef.name = 'Baz'
@@ -2920,15 +2952,12 @@ def test_form_management_view(pub):
     assert 'backoffice/management/form-title/' in resp
 
 
-def test_form_archive(pub):
+def test_form_archive(nosql_pub):
+    # this doesn't exist in SQL
+    pub = nosql_pub
     create_superuser(pub)
     create_role(pub)
 
-    if pub.is_using_postgresql():
-        # this doesn't exist in SQL
-        pytest.skip('no archive in SQL mode')
-        return
-
     FormDef.wipe()
     formdef = FormDef()
     formdef.name = 'form title'
@@ -3081,9 +3110,8 @@ def test_form_overwrite(pub):
     # check existing data
     data = FormDef.get(formdef_id).data_class().get(formdata.id).data
     assert data.get('2') == 'bar'
-    if pub.is_using_postgresql():
-        # in SQL, check data with different type has been removed
-        assert data.get('3') is None
+    # in SQL, check data with different type has been removed
+    assert data.get('3') is None
 
 
 def test_form_export_import_export_overwrite(pub):
@@ -3230,8 +3258,7 @@ def test_form_comment_with_error_in_wscall(http_requests, pub):
     app = login(get_app(pub))
     resp = app.get('/backoffice/forms/%s/' % formdef.id)
     assert 'x [webservice.xxx.foobar] x' in resp.text
-    if pub.is_using_postgresql():
-        assert pub.loggederror_class.count() == 0  # error not recorded
+    assert pub.loggederror_class.count() == 0  # error not recorded
 
 
 def test_form_new_computed_field(pub):
diff --git a/tests/admin_pages/test_role.py b/tests/admin_pages/test_role.py
index f3978cf71..e63ff227b 100644
--- a/tests/admin_pages/test_role.py
+++ b/tests/admin_pages/test_role.py
@@ -7,14 +7,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
diff --git a/tests/admin_pages/test_settings.py b/tests/admin_pages/test_settings.py
index abdc1358f..2ba732815 100644
--- a/tests/admin_pages/test_settings.py
+++ b/tests/admin_pages/test_settings.py
@@ -31,14 +31,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
@@ -869,10 +864,6 @@ def test_settings_theme_download_upload(pub):
 
 
 def test_postgresql_settings(pub):
-    if not pub.is_using_postgresql():
-        pytest.skip('this requires SQL')
-        return
-
     create_superuser(pub)
 
     database = pub.cfg['postgresql']['database']
diff --git a/tests/admin_pages/test_studio.py b/tests/admin_pages/test_studio.py
index 30c959ade..14c2e8b74 100644
--- a/tests/admin_pages/test_studio.py
+++ b/tests/admin_pages/test_studio.py
@@ -17,11 +17,6 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 from .test_all import create_superuser
 
 
-def pytest_generate_tests(metafunc):
-    if 'pub' in metafunc.fixturenames:
-        metafunc.parametrize('pub', ['pickle', 'sql'], indirect=True)
-
-
 def pub_fixture(**kwargs):
     pub = create_temporary_pub(**kwargs)
 
@@ -36,7 +31,7 @@ def pub_fixture(**kwargs):
 
 @pytest.fixture
 def pub(request):
-    return pub_fixture(sql_mode=(request.param == 'sql'))
+    return pub_fixture(sql_mode=True)
 
 
 @pytest.fixture
diff --git a/tests/admin_pages/test_user.py b/tests/admin_pages/test_user.py
index 47799768e..a19822d9a 100644
--- a/tests/admin_pages/test_user.py
+++ b/tests/admin_pages/test_user.py
@@ -9,14 +9,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 from .test_all import create_role, 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
diff --git a/tests/admin_pages/test_workflow.py b/tests/admin_pages/test_workflow.py
index 8e8cc5c49..9434cfda1 100644
--- a/tests/admin_pages/test_workflow.py
+++ b/tests/admin_pages/test_workflow.py
@@ -30,14 +30,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
@@ -1951,10 +1946,9 @@ def test_workflows_backoffice_fields(pub):
     assert Workflow.get(1).backoffice_fields_formdef.fields[0].key == 'string'
     assert Workflow.get(1).backoffice_fields_formdef.fields[0].label == 'foobar'
 
-    if pub.is_using_postgresql():
-        assert 'New backoffice field "foobar"' in [
-            x.comment for x in pub.snapshot_class.select_object_history(workflow)
-        ]
+    assert 'New backoffice field "foobar"' in [
+        x.comment for x in pub.snapshot_class.select_object_history(workflow)
+    ]
 
     backoffice_field_id = Workflow.get(1).backoffice_fields_formdef.fields[0].id
     formdef = FormDef.get(formdef.id)
@@ -3135,10 +3129,6 @@ def test_workflows_wscall_options(pub, value):
 
 
 def test_workflows_wscall_status_error(pub):
-    if not pub.is_using_postgresql():
-        pytest.skip('this requires SQL')
-        return
-
     create_superuser(pub)
 
     Workflow.wipe()
diff --git a/tests/admin_pages/test_wscall.py b/tests/admin_pages/test_wscall.py
index d8afe2073..efe067a35 100644
--- a/tests/admin_pages/test_wscall.py
+++ b/tests/admin_pages/test_wscall.py
@@ -11,14 +11,9 @@ from ..utilities import clean_temporary_pub, create_temporary_pub, get_app, logi
 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))
+    pub = create_temporary_pub(sql_mode=True)
 
     req = HTTPRequest(None, {'SCRIPT_NAME': '/', 'SERVER_NAME': 'example.net'})
     pub.set_app_dir(req)
-- 
2.35.1

