aboutsummaryrefslogtreecommitdiff
path: root/tests/playwright/test_basic.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/playwright/test_basic.py')
-rw-r--r--tests/playwright/test_basic.py98
1 files changed, 18 insertions, 80 deletions
diff --git a/tests/playwright/test_basic.py b/tests/playwright/test_basic.py
index cde682e..a2e6030 100644
--- a/tests/playwright/test_basic.py
+++ b/tests/playwright/test_basic.py
@@ -1,45 +1,12 @@
import datetime
import pytest
-from pyramid.authentication import AuthTktCookieHelper
-from pyramid.testing import DummyRequest
from playwright.sync_api import Page, expect
from sqlalchemy import select
from testutils import load_gpx_asset
from fietsboek import models
-from fietsboek.models.track import Visibility, TrackType
-from fietsboek.config import Config
-
-
-@pytest.fixture
-def john_doe(dbaccess):
- """Provides a test user (John Doe).
-
- This fixture either returns the existing John or creates a new one.
- """
- with dbaccess:
- user = models.User(name="John Doe", email="john@doe.com", is_verified=True)
- user.set_password("password")
- dbaccess.add(user)
- dbaccess.commit()
- dbaccess.refresh(user, ["id"])
- dbaccess.expunge(user)
- return user
-
-
-def do_login(settings: dict, page: Page, user: models.User):
- """Logs the given user in by setting the auth cookie."""
- config = Config.construct(session_key=settings["session_key"])
- secret = config.derive_secret("auth-cookie")
- helper = AuthTktCookieHelper(secret)
- headers = helper.remember(DummyRequest(), str(user.id))
- for _, header_val in headers:
- cookie = header_val.split(";")[0]
- name, value = cookie.split("=", 1)
- page.context.add_cookies([
- {"name": name, "value": value, "domain": "localhost", "path": "/"},
- ])
+from fietsboek.models.track import Visibility
def test_homepage(page: Page):
@@ -60,7 +27,8 @@ def test_login_failed(page: Page):
expect(page.locator(".alert")).to_have_text("Invalid login credentials")
-def test_login_success(page: Page, john_doe):
+def test_login_success(page: Page, playwright_helper):
+ playwright_helper.john_doe()
page.goto("/")
page.get_by_role("button", name="User").click()
@@ -73,8 +41,9 @@ def test_login_success(page: Page, john_doe):
expect(page.locator(".alert")).to_have_text("You are now logged in")
-def test_upload(page: Page, john_doe, app_settings, tmp_path, dbaccess):
- do_login(app_settings, page, john_doe)
+def test_upload(page: Page, playwright_helper, tmp_path, dbaccess):
+ playwright_helper.login()
+
page.goto("/")
page.get_by_text("Upload").click()
@@ -111,21 +80,9 @@ def test_upload(page: Page, john_doe, app_settings, tmp_path, dbaccess):
assert track.description == "Beschreibung der tollen Tour"
-def test_edit(page: Page, john_doe, app_settings, dbaccess, data_manager):
- do_login(app_settings, page, john_doe)
- with dbaccess:
- john_doe = dbaccess.merge(john_doe)
- track = models.Track(
- title="Another awesome track",
- visibility=Visibility.PRIVATE,
- description="Another description",
- )
- track.date = datetime.datetime.now(datetime.timezone.utc)
- john_doe.tracks.append(track)
- dbaccess.flush()
- track_id = track.id
- data_manager.initialize(track_id).compress_gpx(load_gpx_asset("Teasi_1.gpx.gz"))
- dbaccess.commit()
+def test_edit(page: Page, playwright_helper, dbaccess):
+ playwright_helper.login()
+ track_id = playwright_helper.add_track().id
page.goto(f"/track/{track_id}")
page.locator(".btn", has_text="Edit").click()
@@ -151,20 +108,13 @@ def test_edit(page: Page, john_doe, app_settings, dbaccess, data_manager):
assert track.description == "Not so descriptive anymore"
-def test_browse(page: Page, john_doe, app_settings, dbaccess, data_manager):
- do_login(app_settings, page, john_doe)
+def test_browse(page: Page, playwright_helper, dbaccess):
+ playwright_helper.login()
+ track = playwright_helper.add_track()
+
with dbaccess:
- john_doe = dbaccess.merge(john_doe)
- track = models.Track(
- title="We're looking for this track",
- visibility=Visibility.PRIVATE,
- description="Another description",
- type=TrackType.ORGANIC,
- )
- track.date = datetime.datetime.now(datetime.timezone.utc)
- john_doe.tracks.append(track)
- dbaccess.flush()
- data_manager.initialize(track.id).compress_gpx(load_gpx_asset("Teasi_1.gpx.gz"))
+ track = dbaccess.merge(track)
+ track.title = "We're looking for this track"
dbaccess.commit()
page.goto("/")
@@ -185,21 +135,9 @@ def test_browse(page: Page, john_doe, app_settings, dbaccess, data_manager):
expect(page.locator(".card-header", has_text="We're looking for this track")).to_be_visible()
-def test_delete(page: Page, john_doe, app_settings, dbaccess, data_manager):
- do_login(app_settings, page, john_doe)
- with dbaccess:
- john_doe = dbaccess.merge(john_doe)
- track = models.Track(
- title="Another awesome track",
- visibility=Visibility.PRIVATE,
- description="Another description",
- )
- track.date = datetime.datetime.now(datetime.timezone.utc)
- john_doe.tracks.append(track)
- dbaccess.flush()
- track_id = track.id
- data_manager.initialize(track_id).compress_gpx(load_gpx_asset("Teasi_1.gpx.gz"))
- dbaccess.commit()
+def test_delete(page: Page, playwright_helper, dbaccess, data_manager):
+ playwright_helper.login()
+ track_id = playwright_helper.add_track().id
page.goto(f"/track/{track_id}")
page.locator("#deleteLink", has_text="Delete").click()