From eac4f7a7f7fec9585a7c080400c4ae8fa9b67578 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 13 Nov 2023 18:35:03 +0100 Subject: make test app fixture module-scoped Previously, we had it session-scoped, which meant that the app was created once for all tests. This doesn't allow us to play with different settings however, such as disabling account registration or image uploads and testing that. Now, the fixtures are module scoped, which means that we still save on prepare/teardown time a bit, but we're also a bit more flexible. By making new test modules, we can test different settings there. --- tests/conftest.py | 9 ++++++--- tests/playwright/conftest.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/conftest.py b/tests/conftest.py index a4366ab..94f795a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,11 +28,14 @@ def ini_file(request): # potentially grab this path from a pytest option return os.path.abspath(request.config.option.ini or 'testing.ini') -@pytest.fixture(scope='session') +# Even though the ini file is scoped to session, we scope the actual settings +# to module only. This way, we can test different configurations in different +# modules. +@pytest.fixture(scope='module') def app_settings(ini_file): return get_appsettings(ini_file) -@pytest.fixture(scope='session') +@pytest.fixture(scope='module') def dbengine(app_settings, ini_file): engine = models.get_engine(app_settings) @@ -73,7 +76,7 @@ def _cleanup_data(app_settings): if (data_dir / "tracks").is_dir(): shutil.rmtree(data_dir / "tracks") -@pytest.fixture(scope='session') +@pytest.fixture(scope='module') def app(app_settings, dbengine, tmp_path_factory): app_settings["fietsboek.data_dir"] = str(tmp_path_factory.mktemp("data")) logging.getLogger().setLevel(logging.DEBUG) diff --git a/tests/playwright/conftest.py b/tests/playwright/conftest.py index 12a0047..4e7f5a4 100644 --- a/tests/playwright/conftest.py +++ b/tests/playwright/conftest.py @@ -15,7 +15,7 @@ from fietsboek.config import Config import pytest -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def server_port(): """Return a (likely) free port. @@ -29,7 +29,7 @@ def server_port(): return port -@pytest.fixture(scope="session", autouse=True) +@pytest.fixture(scope="module", autouse=True) def running_server(server_port, app): """Have the app running as an actual server.""" server = simple_server.make_server("127.0.0.1", server_port, app) -- cgit v1.2.3 From 9aac19a422addda40e802c0b94d7a237b742d8e1 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 13 Nov 2023 18:51:52 +0100 Subject: add tests for disabled image uploads --- tests/playwright/test_no_image_uploads.py | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/playwright/test_no_image_uploads.py (limited to 'tests') diff --git a/tests/playwright/test_no_image_uploads.py b/tests/playwright/test_no_image_uploads.py new file mode 100644 index 0000000..ce45ebb --- /dev/null +++ b/tests/playwright/test_no_image_uploads.py @@ -0,0 +1,33 @@ +import pytest +from playwright.sync_api import Page, expect + +from testutils import extract_and_upload + + +@pytest.fixture(scope="module") +def app_settings(app_settings): + app_settings["fietsboek.enable_image_uploads"] = "false" + return app_settings + + +def test_image_button_disabled_during_upload(page: Page, playwright_helper, tmp_path, dbaccess): + playwright_helper.login() + + page.goto("/") + page.get_by_text("Upload").click() + + # We unpack one of the test GPX files + extract_and_upload(page, "Teasi_1.gpx.gz", tmp_path) + + # We now fill in most of the data + expect(page.locator("#selectImagesButton")).to_be_disabled() + + +def test_image_button_disabled_during_edit(page: Page, playwright_helper, dbaccess): + playwright_helper.login() + track_id = playwright_helper.add_track().id + + page.goto(f"/track/{track_id}") + page.locator(".btn", has_text="Edit").click() + + expect(page.locator("#selectImagesButton")).to_be_disabled() -- cgit v1.2.3 From ac2eea33e8e2b03a0c4c1c170e6141355bef01a5 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Mon, 13 Nov 2023 18:58:01 +0100 Subject: add docstring --- tests/playwright/test_no_image_uploads.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/playwright/test_no_image_uploads.py b/tests/playwright/test_no_image_uploads.py index ce45ebb..b133697 100644 --- a/tests/playwright/test_no_image_uploads.py +++ b/tests/playwright/test_no_image_uploads.py @@ -6,6 +6,7 @@ from testutils import extract_and_upload @pytest.fixture(scope="module") def app_settings(app_settings): + """Override the standard app settings to disable image uploads.""" app_settings["fietsboek.enable_image_uploads"] = "false" return app_settings -- cgit v1.2.3