aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/assets/Synthetic_Steep_Slope.gpx.gzbin0 -> 883 bytes
-rw-r--r--tests/assets/Synthetic_Zero_Elevation.gpx.gzbin0 -> 791 bytes
-rw-r--r--tests/playwright/conftest.py1
-rw-r--r--tests/playwright/test_basic.py4
-rw-r--r--tests/playwright/test_transformers.py130
-rw-r--r--tests/testutils.py24
6 files changed, 154 insertions, 5 deletions
diff --git a/tests/assets/Synthetic_Steep_Slope.gpx.gz b/tests/assets/Synthetic_Steep_Slope.gpx.gz
new file mode 100644
index 0000000..244f78a
--- /dev/null
+++ b/tests/assets/Synthetic_Steep_Slope.gpx.gz
Binary files differ
diff --git a/tests/assets/Synthetic_Zero_Elevation.gpx.gz b/tests/assets/Synthetic_Zero_Elevation.gpx.gz
new file mode 100644
index 0000000..94abb0a
--- /dev/null
+++ b/tests/assets/Synthetic_Zero_Elevation.gpx.gz
Binary files differ
diff --git a/tests/playwright/conftest.py b/tests/playwright/conftest.py
index 18b7ad0..f57aca7 100644
--- a/tests/playwright/conftest.py
+++ b/tests/playwright/conftest.py
@@ -126,6 +126,7 @@ class Helper:
tags=[],
badges=[],
tagged_people=[],
+ transformers=[],
gpx_data=load_gpx_asset(track_name),
)
self.dbaccess.commit()
diff --git a/tests/playwright/test_basic.py b/tests/playwright/test_basic.py
index 3b3329a..a98e52d 100644
--- a/tests/playwright/test_basic.py
+++ b/tests/playwright/test_basic.py
@@ -51,7 +51,7 @@ def test_upload(page: Page, playwright_helper, tmp_path, dbaccess):
page.locator(".bi-upload").click()
# We now fill in most of the data
- page.get_by_label("Title").fill("An awesome track!")
+ page.get_by_label("Title", exact=True).fill("An awesome track!")
page.get_by_label("Date").type("07302022")
page.get_by_label("Date").press("Tab")
page.get_by_label("Date").type("12:41")
@@ -82,7 +82,7 @@ def test_edit(page: Page, playwright_helper, dbaccess):
page.locator(".btn", has_text="Edit").click()
# We now fill in most of the data
- page.get_by_label("Title").fill("Not so awesome anymore!")
+ page.get_by_label("Title", exact=True).fill("Not so awesome anymore!")
page.get_by_label("Date").type("09232019")
page.get_by_label("Date").press("Tab")
page.get_by_label("Date").type("15:28")
diff --git a/tests/playwright/test_transformers.py b/tests/playwright/test_transformers.py
new file mode 100644
index 0000000..0b2e4de
--- /dev/null
+++ b/tests/playwright/test_transformers.py
@@ -0,0 +1,130 @@
+from playwright.sync_api import Page, expect
+from sqlalchemy import select
+
+from testutils import extract_and_upload
+from fietsboek import models
+
+
+def test_transformer_zero_elevation_disabled(page: Page, playwright_helper, tmp_path, dbaccess):
+ playwright_helper.login()
+
+ page.goto("/")
+ page.get_by_text("Upload").click()
+
+ extract_and_upload(page, "Synthetic_Zero_Elevation.gpx.gz", tmp_path)
+
+ page.locator(".btn", has_text="Upload").click()
+
+ # Expect early (here and in the other tests) to ensure that the backend has
+ # caught up with executing the transformer. Otherwise it might happen that
+ # we read the database while the request is not finished yet.
+ expect(page.locator("#detailsUphill")).to_contain_text("167.7 m")
+ new_track_id = int(page.url.rsplit("/", 1)[1])
+ track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one()
+
+ assert track.cache.uphill > 160
+
+
+def test_transformer_zero_elevation_enabled(page: Page, playwright_helper, tmp_path, dbaccess):
+ playwright_helper.login()
+
+ page.goto("/")
+ page.get_by_text("Upload").click()
+
+ extract_and_upload(page, "Synthetic_Zero_Elevation.gpx.gz", tmp_path)
+
+ page.locator("#transformer-heading-1 .accordion-button").click()
+ page.locator("#transformer-enabled-1").click()
+
+ page.locator(".btn", has_text="Upload").click()
+
+ expect(page.locator("#detailsUphill")).to_contain_text("0 m")
+ new_track_id = int(page.url.rsplit("/", 1)[1])
+ track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one()
+
+ assert track.cache.uphill < 0.1
+
+
+def test_transformer_zero_elevation_edited(page: Page, playwright_helper, tmp_path, dbaccess):
+ playwright_helper.login()
+
+ page.goto("/")
+ page.get_by_text("Upload").click()
+
+ extract_and_upload(page, "Synthetic_Zero_Elevation.gpx.gz", tmp_path)
+
+ page.locator(".btn", has_text="Upload").click()
+
+ page.locator(".btn", has_text="Edit").click()
+
+ page.locator("#transformer-heading-1 .accordion-button").click()
+ page.locator("#transformer-enabled-1").click()
+
+ page.locator(".btn", has_text="Save").click()
+
+ expect(page.locator("#detailsUphill")).to_contain_text("0 m")
+ track_id = int(page.url.rsplit("/", 1)[1])
+ track = dbaccess.execute(select(models.Track).filter_by(id=track_id)).scalar_one()
+
+ assert track.cache.uphill < 0.1
+
+
+def test_transformer_steep_slope_disabled(page: Page, playwright_helper, tmp_path, dbaccess):
+ playwright_helper.login()
+
+ page.goto("/")
+ page.get_by_text("Upload").click()
+
+ extract_and_upload(page, "Synthetic_Steep_Slope.gpx.gz", tmp_path)
+
+ page.locator(".btn", has_text="Upload").click()
+
+ expect(page.locator("#detailsUphill")).to_contain_text("61.54 m")
+ new_track_id = int(page.url.rsplit("/", 1)[1])
+ track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one()
+
+ assert track.cache.uphill > 60
+
+
+def test_transformer_steep_slope_enabled(page: Page, playwright_helper, tmp_path, dbaccess):
+ playwright_helper.login()
+
+ page.goto("/")
+ page.get_by_text("Upload").click()
+
+ extract_and_upload(page, "Synthetic_Steep_Slope.gpx.gz", tmp_path)
+
+ page.locator("#transformer-heading-1 .accordion-button").click()
+ page.locator("#transformer-enabled-1").click()
+
+ page.locator(".btn", has_text="Upload").click()
+
+ expect(page.locator("#detailsUphill")).to_contain_text("1.2 m")
+ new_track_id = int(page.url.rsplit("/", 1)[1])
+ track = dbaccess.execute(select(models.Track).filter_by(id=new_track_id)).scalar_one()
+
+ assert track.cache.uphill < 2
+
+
+def test_transformer_steep_slope_edited(page: Page, playwright_helper, tmp_path, dbaccess):
+ playwright_helper.login()
+
+ page.goto("/")
+ page.get_by_text("Upload").click()
+
+ extract_and_upload(page, "Synthetic_Steep_Slope.gpx.gz", tmp_path)
+
+ page.locator(".btn", has_text="Upload").click()
+
+ page.locator(".btn", has_text="Edit").click()
+
+ page.locator("#transformer-heading-1 .accordion-button").click()
+ page.locator("#transformer-enabled-1").click()
+
+ page.locator(".btn", has_text="Save").click()
+
+ expect(page.locator("#detailsUphill")).to_contain_text("1.2 m")
+ track_id = int(page.url.rsplit("/", 1)[1])
+ track = dbaccess.execute(select(models.Track).filter_by(id=track_id)).scalar_one()
+
+ assert track.cache.uphill < 2
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()