aboutsummaryrefslogtreecommitdiff
path: root/tests/integration/test_browse.py
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-07-17 20:56:38 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-07-17 20:56:38 +0200
commit69c9167911a8449fef20951abe924a1c4528545c (patch)
tree95b840058d8abf78e7b0fdd0331a0b86fef7b6d3 /tests/integration/test_browse.py
parentd8ba9371656f9bd1492b9fbe13234f216ebbd240 (diff)
downloadfietsboek-69c9167911a8449fef20951abe924a1c4528545c.tar.gz
fietsboek-69c9167911a8449fef20951abe924a1c4528545c.tar.bz2
fietsboek-69c9167911a8449fef20951abe924a1c4528545c.zip
add tests for archive download
Diffstat (limited to 'tests/integration/test_browse.py')
-rw-r--r--tests/integration/test_browse.py91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/integration/test_browse.py b/tests/integration/test_browse.py
new file mode 100644
index 0000000..cfd1d71
--- /dev/null
+++ b/tests/integration/test_browse.py
@@ -0,0 +1,91 @@
+import io
+import zipfile
+from contextlib import contextmanager
+from datetime import datetime
+
+from sqlalchemy import select, func
+from webtest import Upload
+
+from testutils import load_gpx_asset
+from fietsboek import models
+from fietsboek.models.track import Visibility
+
+
+@contextmanager
+def added_tracks(tm, dbsession, owner):
+ """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()
+
+ tracks = []
+ with tm:
+ track = models.Track(
+ owner=owner,
+ title="Foobar",
+ visibility=Visibility.PUBLIC,
+ description="A foo'd track",
+ badges=[],
+ link_secret="foobar",
+ tagged_people=[],
+ )
+ track.date = datetime(2022, 3, 14, 9, 26, 54)
+ track.gpx_data = load_gpx_asset("MyTourbook_1.gpx.gz")
+ dbsession.add(track)
+ tracks.append(track)
+
+ track = models.Track(
+ owner=owner,
+ title="Barfoo",
+ visibility=Visibility.PUBLIC,
+ description="A bar'd track",
+ badges=[],
+ link_secret="barfoo",
+ tagged_people=[],
+ )
+ track.date = datetime(2022, 10, 29, 13, 37, 11)
+ track.gpx_data = load_gpx_asset("Teasi_1.gpx.gz")
+ dbsession.add(track)
+ tracks.append(track)
+
+ tm.begin()
+ tm.doom()
+
+ try:
+ yield tracks
+ finally:
+ tm.abort()
+ with tm:
+ for track in tracks:
+ dbsession.delete(track)
+ tm.begin()
+ tm.doom()
+
+
+def test_browse(testapp, dbsession, route_path, logged_in, tm):
+ # Ensure there are some tracks in the database
+ with added_tracks(tm, dbsession, logged_in):
+ # Now go to the browse page
+ browse = testapp.get(route_path('browse'))
+
+ assert "Foobar" in browse.text
+ assert "Barfoo" in browse.text
+
+
+def test_archive(testapp, dbsession, route_path, logged_in, tm):
+ with added_tracks(tm, dbsession, logged_in):
+ archive = testapp.get(
+ route_path('track-archive', _query=[("track_id[]", "1"), ("track_id[]", "2")])
+ )
+ result = io.BytesIO(archive.body)
+
+ with zipfile.ZipFile(result, 'r') as zipped:
+ assert len(zipped.namelist()) == 2
+ assert "track_1.gpx" in zipped.namelist()
+ assert "track_2.gpx" in zipped.namelist()