aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-12-29 13:56:38 +0100
committerDaniel Schadt <kingdread@gmx.de>2022-12-29 13:56:38 +0100
commit2aee4fe00400ae34350ed50a05fa5c3ac30b1eac (patch)
tree66a8af9cce696a29a97adf7ce3d7861c0d61d849
parente7495338906e4f17c6394f59028226444347dfb3 (diff)
downloadfietsboek-2aee4fe00400ae34350ed50a05fa5c3ac30b1eac.tar.gz
fietsboek-2aee4fe00400ae34350ed50a05fa5c3ac30b1eac.tar.bz2
fietsboek-2aee4fe00400ae34350ed50a05fa5c3ac30b1eac.zip
add playwright tests for the sharing functionality
-rw-r--r--tests/playwright/conftest.py3
-rw-r--r--tests/playwright/test_share.py49
2 files changed, 51 insertions, 1 deletions
diff --git a/tests/playwright/conftest.py b/tests/playwright/conftest.py
index efa82c6..21edca8 100644
--- a/tests/playwright/conftest.py
+++ b/tests/playwright/conftest.py
@@ -8,7 +8,7 @@ from pyramid.authentication import AuthTktCookieHelper
from pyramid.testing import DummyRequest
from testutils import load_gpx_asset
-from fietsboek import models
+from fietsboek import models, util
from fietsboek.models.track import Visibility, TrackType
from fietsboek.config import Config
@@ -119,6 +119,7 @@ class Helper:
visibility=Visibility.PRIVATE,
description="Another description",
type=TrackType.ORGANIC,
+ link_secret=util.random_link_secret(),
)
track.date = datetime.datetime(2022, 12, 21, 17, 5, tzinfo=datetime.timezone.utc)
user.tracks.append(track)
diff --git a/tests/playwright/test_share.py b/tests/playwright/test_share.py
new file mode 100644
index 0000000..de288a0
--- /dev/null
+++ b/tests/playwright/test_share.py
@@ -0,0 +1,49 @@
+from playwright.sync_api import Page, expect
+from sqlalchemy import select
+
+from fietsboek import models
+
+
+def test_view_link(page: Page, playwright_helper, dbaccess):
+ playwright_helper.login()
+ track = playwright_helper.add_track()
+
+ page.goto(f"/track/{track.id}")
+
+ page.locator(".btn", has_text="Share").click()
+
+ expect(page.locator("a", has_text=track.link_secret)).to_be_visible()
+
+
+def test_view_with_link(page: Page, playwright_helper, dbaccess):
+ track = playwright_helper.add_track()
+
+ page.goto(f"/track/{track.id}?secret={track.link_secret}")
+
+ expect(page.locator("h1")).to_have_text("Another awesome track")
+
+
+def test_view_wrong_link(page: Page, playwright_helper, dbaccess):
+ track = playwright_helper.add_track()
+
+ with page.expect_response(lambda resp: resp.status == 403):
+ page.goto(f"/track/{track.id}?secret=foobar")
+
+ assert "Forbidden" in page.content()
+
+
+def test_change_link(page: Page, playwright_helper, dbaccess):
+ playwright_helper.login()
+ track = playwright_helper.add_track()
+ old_secret = track.link_secret
+
+ page.goto(f"/track/{track.id}")
+
+ page.locator(".btn", has_text="Share").click()
+ page.get_by_role("button", name="Invalidate link").click()
+ page.wait_for_load_state()
+
+ query = select(models.Track).filter_by(id=track.id)
+ new_track = dbaccess.execute(query).scalar_one()
+
+ assert old_secret != new_track.link_secret