]> littlesong.place Git - littlesongplace.git/commitdiff
Add remaining playlist tests, update news
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 16 Feb 2025 20:06:10 +0000 (15:06 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 16 Feb 2025 20:06:10 +0000 (15:06 -0500)
main.py
templates/news.html
test/test_offline.py
todo.txt

diff --git a/main.py b/main.py
index ed075b6c3f943b5e973c34ff13647af91d2ebfb6..ada6574e4462f1b5604817650b10d5c832a67f96 100644 (file)
--- 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"]
index 74eb46421896d32c84dc6b64aeba66eecb881d12..27da4fee4b1078ac8e3d79fdf31e5f97c85708c5 100644 (file)
@@ -6,6 +6,19 @@
 
 <h1>Site News</h1>
 
+<h2>2025-02-16 - Playlists</h2>
+<p>
+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.
+</p>
+<ul>
+    <li>Playlists!</li>
+    <li>Profile colors now also apply to individual songs and playlists</li>
+    <li>On PC, you can use the left and right arrow keys to jump forward/back 10 seconds while a song is playing</li>
+    <li>The upload date is now displayed in song details</li>
+</ul>
+
 <h2>2025-02-08 - Profile Update & YouTube Importer</h2>
 <p>
 Make your profile your own by uploading a slick PFP and selecting custom
index 29755a2d8f303cd6d801eb04d47304b545169841..26b39dc97bc7965c6dac224362c8a3d2e6c1149d 100644 (file)
@@ -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
+
index 2dcc9df64cc353c072d6ed71bf924cd1165c42b1..646d236f7436f9ca73de12b616bb2750da60854f 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,5 +1,4 @@
 NOW
-- Test playlist API
 
 SOON
 - Break up main.py, test_offline.py