diff options
author | Daniel Schadt <kingdread@gmx.de> | 2023-03-07 20:17:35 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2023-03-07 20:17:35 +0100 |
commit | 40a0f2dbed1034ca02fcb83c820f22976601c777 (patch) | |
tree | 6eb1889dbace979442e0058136e49208f8e89903 /tests/testutils.py | |
parent | bb4b8eed4cd0ede4198f5dcf4269f2efed25541a (diff) | |
parent | e8678a7155ff64d797693f7a8ec84c196d1d4748 (diff) | |
download | fietsboek-40a0f2dbed1034ca02fcb83c820f22976601c777.tar.gz fietsboek-40a0f2dbed1034ca02fcb83c820f22976601c777.tar.bz2 fietsboek-40a0f2dbed1034ca02fcb83c820f22976601c777.zip |
Merge branch 'transformers'
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() |