diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 16 | ||||
-rw-r--r-- | tests/playwright/test_profiles.py | 25 | ||||
-rw-r--r-- | tests/unit/test_util.py | 14 |
3 files changed, 50 insertions, 5 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index a499bec..d4394cd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,7 +12,7 @@ import pytest import transaction import webtest -from sqlalchemy import delete, select +from sqlalchemy import delete, inspect, select from fietsboek import main, models from fietsboek.data import DataManager @@ -59,12 +59,18 @@ def data_manager(app_settings): def _cleanup_data(app_settings): yield engine = models.get_engine(app_settings) + db_meta = inspect(engine) with engine.begin() as connection: for table in reversed(Base.metadata.sorted_tables): - connection.execute(table.delete()) - data_dir = Path(app_settings["fietsboek.data_dir"]) - if (data_dir / "tracks").is_dir(): - shutil.rmtree(data_dir / "tracks") + # The unit tests don't always set up the tables, so be gentle when + # tearing them down + if db_meta.has_table(table.name): + connection.execute(table.delete()) + # The unit tests also often don't have a data directory, so be gentle here as well + if "fietsboek.data_dir" in app_settings: + data_dir = Path(app_settings["fietsboek.data_dir"]) + if (data_dir / "tracks").is_dir(): + shutil.rmtree(data_dir / "tracks") @pytest.fixture(scope='session') def app(app_settings, dbengine, tmp_path_factory): diff --git a/tests/playwright/test_profiles.py b/tests/playwright/test_profiles.py new file mode 100644 index 0000000..7e5fb3c --- /dev/null +++ b/tests/playwright/test_profiles.py @@ -0,0 +1,25 @@ +from playwright.sync_api import Page, expect + + +def test_forbidden(page: Page, playwright_helper): + john = playwright_helper.john_doe() + + with page.expect_response(lambda resp: resp.status == 403): + page.goto(f"/user/{john.id}") + + +def test_profile(page: Page, playwright_helper): + playwright_helper.login() + + page.goto("/") + page.get_by_role("button", name="User").click() + page.get_by_role("link", name="Profile").click() + + expect(page.locator("#profileLength")).to_have_text("0 km") + expect(page.locator("#profileUphill")).to_have_text("0 m") + expect(page.locator("#profileDownhill")).to_have_text("0 m") + expect(page.locator("#profileMovingTime")).to_have_text("0:00:00") + expect(page.locator("#profileStoppedTime")).to_have_text("0:00:00") + expect(page.locator("#profileMaxSpeed")).to_have_text("0 km/h") + expect(page.locator("#profileAvgSpeed")).to_have_text("0 km/h") + expect(page.locator("#profileNumberOfTracks")).to_have_text("0") diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index b35f218..0ac5c33 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -30,6 +30,11 @@ def test_fix_iso_timestamp(timestamp, fixed): @pytest.mark.parametrize('delta, multiple, expected', [ ( + timedelta(seconds=0), + timedelta(seconds=1), + timedelta(seconds=0), + ), + ( timedelta(minutes=42), timedelta(minutes=15), timedelta(minutes=45), @@ -82,3 +87,12 @@ def test_tour_metadata(gpx_file): @pytest.mark.parametrize('mps, kph', [(1, 3.6), (10, 36)]) def test_mps_to_kph(mps, kph): assert util.mps_to_kph(mps) == pytest.approx(kph, 0.1) + + +def test_tile_url(app_request): + route_url = util.tile_url(app_request, "tile-proxy", provider="bobby") + + assert "{x}" in route_url + assert "{y}" in route_url + assert "{z}" in route_url + assert "bobby" in route_url |