diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-03-04 18:24:11 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-03-04 18:24:11 +0100 |
commit | e9025533b86228f7073a672269c939c5ae5db8e2 (patch) | |
tree | 8a98178672ac4fa5e42e136098c0406cd6c838d0 /tests/testutils.py | |
parent | 63779a61151babf9dc60d55acc81e3a97811a60e (diff) | |
download | fietsboek-e9025533b86228f7073a672269c939c5ae5db8e2.tar.gz fietsboek-e9025533b86228f7073a672269c939c5ae5db8e2.tar.bz2 fietsboek-e9025533b86228f7073a672269c939c5ae5db8e2.zip |
add tests for the new transformer
Diffstat (limited to 'tests/testutils.py')
-rw-r--r-- | tests/testutils.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tests/testutils.py b/tests/testutils.py index 3ddbdbe..810bdf7 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -2,19 +2,37 @@ import gzip from pathlib import Path +from playwright.sync_api import Page -def load_gpx_asset(filename): + +def load_gpx_asset(filename: str) -> bytes: """Load a GPX test asset. This looks in the tests/assets/ folder, reads and unzips the file and returns its contents. :param filename: Name of the asset to load. - :type filename: str :return: The content of the asset as bytes. - :rtype: bytes """ asset_dir = Path(__file__).parent / 'assets' test_file = asset_dir / filename with gzip.open(test_file, 'rb') as fobj: return fobj.read() + + +def extract_and_upload(page: Page, filename: str, tmp_path: Path): + """Extracts the given test asset, fills in the upload form and presses + upload. + + :param page: The playwright page on which to execute the actions. + :param filename: The filename. + :param tmp_path: The temporary path (as given by pytest). + """ + gpx_data = load_gpx_asset(filename) + gpx_path = tmp_path / "Upload.gpx" + with open(gpx_path, "wb") as gpx_fobj: + gpx_fobj.write(gpx_data) + + page.get_by_label("GPX file").set_input_files(gpx_path) + + page.locator(".bi-upload").click() |