diff options
| -rw-r--r-- | tests/integration/test_browse.py | 74 | 
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/integration/test_browse.py b/tests/integration/test_browse.py index 46ec329..83218cc 100644 --- a/tests/integration/test_browse.py +++ b/tests/integration/test_browse.py @@ -70,6 +70,55 @@ def added_tracks(tm, dbsession, owner, data_manager):          tm.doom() +@contextmanager +def a_lot_of_tracks(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() + +    gpx_data = load_gpx_asset("MyTourbook_1.gpx.gz") + +    tracks = [] +    track_ids = [] +    with tm: +        for index in range(50): +            track = models.Track( +                owner=owner, +                title=f"Traxi {index}", +                visibility=Visibility.PUBLIC, +                description="One of many", +                badges=[], +                link_secret="foobar", +                tagged_people=[], +            ) +            track.date = datetime(2022 - index, 3, 14, 9, 26, 59) +            dbsession.add(track) +            dbsession.flush() +            data_manager.initialize(track.id).compress_gpx(gpx_data) +            tracks.append(track) +            track_ids.append(track.id) + +    tm.begin() +    tm.doom() + +    try: +        yield track_ids +    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, data_manager):      # pylint: disable=too-many-positional-arguments      # Ensure there are some tracks in the database @@ -81,6 +130,31 @@ def test_browse(testapp, dbsession, route_path, logged_in, tm, data_manager):          assert "Barfoo" in browse.text +def test_browse_paged(testapp, dbsession, route_path, logged_in, tm, data_manager): +    # pylint: disable=too-many-positional-arguments +    with a_lot_of_tracks(tm, dbsession, logged_in, data_manager): +        page_1 = testapp.get(route_path("browse", _query=[("page", 1)])) +        assert "Traxi 0" in page_1.text +        assert "Traxi 10" in page_1.text +        assert "Traxi 20" not in page_1.text +        assert "Traxi 30" not in page_1.text +        assert "Traxi 40" not in page_1.text + +        page_2 = testapp.get(route_path("browse", _query=[("page", 2)])) +        assert "Traxi 0" not in page_2.text +        assert "Traxi 10" not in page_2.text +        assert "Traxi 20" in page_2.text +        assert "Traxi 30" in page_2.text +        assert "Traxi 40" not in page_2.text + +        page_3 = testapp.get(route_path("browse", _query=[("page", 3)])) +        assert "Traxi 0" not in page_3.text +        assert "Traxi 10" not in page_3.text +        assert "Traxi 20" not in page_3.text +        assert "Traxi 30" not in page_3.text +        assert "Traxi 40" in page_3.text + +  def test_archive(testapp, dbsession, route_path, logged_in, tm, data_manager):      # pylint: disable=too-many-positional-arguments      with added_tracks(tm, dbsession, logged_in, data_manager) as tracks:  | 
