From db470d5f6f9c543a105ef34553beaa74870c3fa8 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 8 Feb 2023 23:51:46 +0100 Subject: fix transformer handling when uploading a file --- tests/playwright/conftest.py | 1 + tests/playwright/test_basic.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'tests/playwright') 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") -- cgit v1.2.3 From e9025533b86228f7073a672269c939c5ae5db8e2 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 4 Mar 2023 18:24:11 +0100 Subject: add tests for the new transformer --- tests/playwright/test_transformers.py | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tests/playwright/test_transformers.py (limited to 'tests/playwright') diff --git a/tests/playwright/test_transformers.py b/tests/playwright/test_transformers.py new file mode 100644 index 0000000..0fc4ffc --- /dev/null +++ b/tests/playwright/test_transformers.py @@ -0,0 +1,87 @@ +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() + + # Once we have finished the upload, extract the ID of the track and check + # the properties + 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 + expect(page.locator("#detailsUphill")).to_contain_text("167.7 m") + + +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() + + # Once we have finished the upload, extract the ID of the track and check + # the properties + 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 + expect(page.locator("#detailsUphill")).to_contain_text("0 m") + + +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() + + # Once we have finished the upload, extract the ID of the track and check + # the properties + 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 + expect(page.locator("#detailsUphill")).to_contain_text("61.54 m") + + +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() + + # Once we have finished the upload, extract the ID of the track and check + # the properties + 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 + expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") -- cgit v1.2.3 From 5a7c780b4f171de2476a4ff060cc450b4e3a3749 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 7 Mar 2023 19:03:02 +0100 Subject: also test transformers when editing a track --- tests/playwright/test_transformers.py | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests/playwright') diff --git a/tests/playwright/test_transformers.py b/tests/playwright/test_transformers.py index 0fc4ffc..d12be5e 100644 --- a/tests/playwright/test_transformers.py +++ b/tests/playwright/test_transformers.py @@ -46,6 +46,30 @@ def test_transformer_zero_elevation_enabled(page: Page, playwright_helper, tmp_p expect(page.locator("#detailsUphill")).to_contain_text("0 m") +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() + + 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 + expect(page.locator("#detailsUphill")).to_contain_text("0 m") + + def test_transformer_steep_slope_disabled(page: Page, playwright_helper, tmp_path, dbaccess): playwright_helper.login() @@ -85,3 +109,27 @@ def test_transformer_steep_slope_enabled(page: Page, playwright_helper, tmp_path assert track.cache.uphill < 2 expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") + + +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() + + 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 + expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") -- cgit v1.2.3 From e8678a7155ff64d797693f7a8ec84c196d1d4748 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 7 Mar 2023 19:54:07 +0100 Subject: switch order of expect & assert While it shouldn't change the outcome of the test, it might make the test less flaky, as the expect call will wait until the page is loaded - which also indicates that the data is updated. Without this, the test depends on the backend being "fast enough" with applying the transformation. --- tests/playwright/test_transformers.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'tests/playwright') diff --git a/tests/playwright/test_transformers.py b/tests/playwright/test_transformers.py index d12be5e..0b2e4de 100644 --- a/tests/playwright/test_transformers.py +++ b/tests/playwright/test_transformers.py @@ -15,13 +15,14 @@ def test_transformer_zero_elevation_disabled(page: Page, playwright_helper, tmp_ page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + # 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 - expect(page.locator("#detailsUphill")).to_contain_text("167.7 m") def test_transformer_zero_elevation_enabled(page: Page, playwright_helper, tmp_path, dbaccess): @@ -37,13 +38,11 @@ def test_transformer_zero_elevation_enabled(page: Page, playwright_helper, tmp_p page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + 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 - expect(page.locator("#detailsUphill")).to_contain_text("0 m") def test_transformer_zero_elevation_edited(page: Page, playwright_helper, tmp_path, dbaccess): @@ -63,11 +62,11 @@ def test_transformer_zero_elevation_edited(page: Page, playwright_helper, tmp_pa 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 - expect(page.locator("#detailsUphill")).to_contain_text("0 m") def test_transformer_steep_slope_disabled(page: Page, playwright_helper, tmp_path, dbaccess): @@ -80,13 +79,11 @@ def test_transformer_steep_slope_disabled(page: Page, playwright_helper, tmp_pat page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + 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 - expect(page.locator("#detailsUphill")).to_contain_text("61.54 m") def test_transformer_steep_slope_enabled(page: Page, playwright_helper, tmp_path, dbaccess): @@ -102,13 +99,11 @@ def test_transformer_steep_slope_enabled(page: Page, playwright_helper, tmp_path page.locator(".btn", has_text="Upload").click() - # Once we have finished the upload, extract the ID of the track and check - # the properties + 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 - expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") def test_transformer_steep_slope_edited(page: Page, playwright_helper, tmp_path, dbaccess): @@ -128,8 +123,8 @@ def test_transformer_steep_slope_edited(page: Page, playwright_helper, tmp_path, 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 - expect(page.locator("#detailsUphill")).to_contain_text("1.2 m") -- cgit v1.2.3