diff options
| -rw-r--r-- | tests/playwright/test_basic.py | 7 | ||||
| -rw-r--r-- | tests/testutils.py | 16 |
2 files changed, 18 insertions, 5 deletions
diff --git a/tests/playwright/test_basic.py b/tests/playwright/test_basic.py index 3ae0f58..19ef8ff 100644 --- a/tests/playwright/test_basic.py +++ b/tests/playwright/test_basic.py @@ -4,7 +4,7 @@ import pytest from playwright.sync_api import Page, expect from sqlalchemy import select -from testutils import load_gpx_asset +from testutils import asset_path, load_gpx_asset from fietsboek import models from fietsboek.models.track import Visibility @@ -60,6 +60,10 @@ def test_upload(page: Page, playwright_helper, tmp_path, dbaccess): page.get_by_role("button", name="Add Tag").click() page.get_by_label("Description").fill("Beschreibung der tollen Tour") + page.locator("#imageSelector").set_input_files( + [asset_path("picture01.jpg"), asset_path("picture02.jpg")], + ) + page.locator(".btn", has_text="Upload").click() # Once we have finished the upload, extract the ID of the track and check @@ -72,6 +76,7 @@ def test_upload(page: Page, playwright_helper, tmp_path, dbaccess): assert track.visibility == Visibility.PUBLIC assert track.text_tags() == {"Tolle Tour"} assert track.description == "Beschreibung der tollen Tour" + assert len(track.images) == 2 def test_edit(page: Page, playwright_helper, dbaccess): diff --git a/tests/testutils.py b/tests/testutils.py index 9a62062..e49a0b5 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -21,6 +21,16 @@ class PopulationIds(NamedTuple): riverrun: int +def asset_path(filename: str) -> Path: + """Returns the path to the test asset given by the filename. + + :param filename: The filename of the asset. + :return: The complete path. + """ + asset_dir = Path(__file__).parent / "assets" + return asset_dir / filename + + def load_test_asset(filename: str) -> bytes: """Load a test asset. @@ -29,8 +39,7 @@ def load_test_asset(filename: str) -> bytes: :param filkename: Name of the asset to load. :return: The content of the file as bytes. """ - asset_dir = Path(__file__).parent / "assets" - return (asset_dir / filename).read_bytes() + return asset_path(filename).read_bytes() def load_gpx_asset(filename: str) -> bytes: @@ -42,8 +51,7 @@ def load_gpx_asset(filename: str) -> bytes: :param filename: Name of the asset to load. :return: The content of the asset as bytes. """ - asset_dir = Path(__file__).parent / 'assets' - test_file = asset_dir / filename + test_file = asset_path(filename) with gzip.open(test_file, 'rb') as fobj: return fobj.read() |
