aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/integration/test_pdf.py59
2 files changed, 60 insertions, 1 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index d10a318..b49dad2 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -191,7 +191,7 @@ def logged_in(testapp, route_path, dbsession, tm):
tm.abort()
with tm:
- user = models.User(email='foo@barre.com', is_verified=True)
+ user = models.User(name="Feu Barre", email='foo@barre.com', is_verified=True)
user.set_password("foobar")
dbsession.add(user)
dbsession.flush()
diff --git a/tests/integration/test_pdf.py b/tests/integration/test_pdf.py
new file mode 100644
index 0000000..29cda02
--- /dev/null
+++ b/tests/integration/test_pdf.py
@@ -0,0 +1,59 @@
+from contextlib import contextmanager
+from datetime import datetime
+
+from testutils import load_gpx_asset
+from fietsboek import convert, models
+from fietsboek.models.track import Visibility
+
+
+@contextmanager
+def a_track(tm, dbsession, owner, data_manager):
+ """Adds some tracks to the database session.
+
+ This function should be used as a context manager and it ensures that the
+ added tracks are deleted again after the test, to make a clean slate for
+ the next test.
+ """
+ # The normal transaction is "doomed", so we need to abort it, start a fresh
+ # one, and then explicitely commit it, otherwise we will not persist the
+ # objects to the database.
+ tm.abort()
+
+ with tm:
+ track = models.Track(
+ owner=owner,
+ title="Goober",
+ visibility=Visibility.PUBLIC,
+ description="A bar'd track",
+ badges=[],
+ link_secret="raboof",
+ tagged_people=[],
+ )
+ track.date = datetime(2027, 3, 14, 9, 26, 54)
+ track.set_path(convert.smart_convert(load_gpx_asset("MyTourbook_1.gpx.gz")).path())
+ dbsession.add(track)
+ dbsession.flush()
+ data_manager.initialize(track.id)
+ track_id = track.id
+
+ tm.begin()
+ tm.doom()
+
+ try:
+ yield track_id
+ finally:
+ tm.abort()
+ with tm:
+ dbsession.delete(track)
+ data_manager.purge(track_id)
+ tm.begin()
+ tm.doom()
+
+
+def test_pdf(testapp, dbsession, route_path, logged_in, tm, data_manager):
+ # pylint: disable=too-many-positional-arguments
+ # Ensure there are some tracks in the database
+ with a_track(tm, dbsession, logged_in, data_manager) as track_id:
+ pdf = testapp.get(route_path("track-pdf", track_id=track_id))
+
+ assert pdf