From: Chris Fulljames Date: Sun, 16 Feb 2025 20:06:10 +0000 (-0500) Subject: Add remaining playlist tests, update news X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=7ca06040f8305034f45112be4e0c8396f42d51b5;p=littlesongplace.git Add remaining playlist tests, update news --- diff --git a/main.py b/main.py index ed075b6..ada6574 100644 --- a/main.py +++ b/main.py @@ -513,7 +513,7 @@ def song(userid, songid): song = Song.by_id(songid) if song.userid != userid: abort(404) - + user_data = query_db("select * from users where userid = ?", [userid], one=True) return render_template( "song.html", @@ -807,7 +807,7 @@ def edit_playlist_post(playlistid): # Cannot edit other user's playlist if session["userid"] != plist_data["userid"]: - abort(401) + abort(403) # Make sure name is valid name = request.form["name"] diff --git a/templates/news.html b/templates/news.html index 74eb464..27da4fe 100644 --- a/templates/news.html +++ b/templates/news.html @@ -6,6 +6,19 @@

Site News

+

2025-02-16 - Playlists

+

+Do you need specific songs in a specific order? Have I got the feature for +you! Create the perfect road trip playlist, DJ your nephew's birthday party, or +organize your songs into albums. +

+ +

2025-02-08 - Profile Update & YouTube Importer

Make your profile your own by uploading a slick PFP and selecting custom diff --git a/test/test_offline.py b/test/test_offline.py index 29755a2..26b39dc 100644 --- a/test/test_offline.py +++ b/test/test_offline.py @@ -987,7 +987,7 @@ def test_create_playlist_invalid_name(client): assert response.status_code == 302 response = client.get("/users/user") assert b"must have a name" in response.data - + response = client.post("/create-playlist", data={"name": "", "type": "private"}) assert response.status_code == 302 response = client.get("/users/user") @@ -1147,8 +1147,54 @@ def test_edit_playlist_change_name_invalid(client): assert b"my playlist" in response.data assert b"must have a name" in response.data -# Edit playlist - change song order -# Edit playlist - remove song(s) -# Edit playlist - not logged in -# Edit playlist - other user's playlist -# Edit playlist - invalid songid +def test_edit_playlist_change_song_order(client): + _create_user_song_and_playlist(client) + _test_upload_song(client, b"Successfully uploaded") + client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"}) + client.post("/append-to-playlist", data={"playlistid": "1", "songid": "2"}) + songs = _get_song_list_from_page(client, "/playlists/1") + assert songs[0]["songid"] == 1 + assert songs[1]["songid"] == 2 + + client.post("/edit-playlist/1", data={"name": "my playlist", "type": "private", "songids": "2,1"}) + songs = _get_song_list_from_page(client, "/playlists/1") + assert songs[0]["songid"] == 2 + assert songs[1]["songid"] == 1 + +def test_edit_playlist_remove_song(client): + _create_user_song_and_playlist(client) + _test_upload_song(client, b"Successfully uploaded") + client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"}) + client.post("/append-to-playlist", data={"playlistid": "1", "songid": "2"}) + songs = _get_song_list_from_page(client, "/playlists/1") + assert len(songs) == 2 + + client.post("/edit-playlist/1", data={"name": "my playlist", "type": "private", "songids": "2"}) + songs = _get_song_list_from_page(client, "/playlists/1") + assert len(songs) == 1 + assert songs[0]["songid"] == 2 + +def test_edit_playlist_not_logged_in(client): + _create_user_song_and_playlist(client) + client.get("/logout") + + response = client.post("/edit-playlist/1", data={"name": "my playlist", "type": "private", "songids": ""}) + assert response.status_code == 401 + +def test_edit_other_users_playlist(client): + _create_user_song_and_playlist(client) + _create_user(client, "user2", login=True) + + response = client.post("/edit-playlist/1", data={"name": "my playlist", "type": "private", "songids": ""}) + assert response.status_code == 403 + +def test_edit_playlist_invalid_songid(client): + _create_user_and_playlist(client) + response = client.post("/edit-playlist/1", data={"name": "my playlist", "type": "private", "songids": "1"}) + assert response.status_code == 400 + +def test_edit_playlist_invalid_playlistid(client): + _create_user_and_playlist(client) + response = client.post("/edit-playlist/2", data={"name": "my playlist", "type": "private", "songids": ""}) + assert response.status_code == 404 + diff --git a/todo.txt b/todo.txt index 2dcc9df..646d236 100644 --- a/todo.txt +++ b/todo.txt @@ -1,5 +1,4 @@ NOW -- Test playlist API SOON - Break up main.py, test_offline.py