]> littlesong.place Git - littlesongplace.git/commitdiff
More test refactoring
authorChris Fulljames <christianfulljames@gmail.com>
Fri, 4 Apr 2025 23:31:24 +0000 (19:31 -0400)
committerChris Fulljames <christianfulljames@gmail.com>
Fri, 4 Apr 2025 23:31:24 +0000 (19:31 -0400)
test/test_activity.py [new file with mode: 0644]
test/test_auth.py
test/test_comments.py [new file with mode: 0644]
test/test_news.py [new file with mode: 0644]
test/test_offline.py [deleted file]
test/test_playlists.py [new file with mode: 0644]
test/test_profile.py
test/test_songlists.py
test/test_songs.py
test/utils.py

diff --git a/test/test_activity.py b/test/test_activity.py
new file mode 100644 (file)
index 0000000..f66edd5
--- /dev/null
@@ -0,0 +1,125 @@
+from .utils import create_user, create_user_and_song
+
+def test_activity_redirects_when_not_logged_in(client):
+    response = client.get("/activity")
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/login"
+
+def test_activity_empty_when_user_has_no_notifications(client):
+    create_user_and_song(client)
+    response = client.get("/activity")
+    assert b"Nothing to show" in response.data
+
+def test_activity_for_comment_on_song(client):
+    create_user_and_song(client)
+    create_user(client, "user2", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool song"})
+    response = client.get("/activity")
+    assert b"Nothing to show" in response.data
+
+    client.post("/login", data={"username": "user", "password": "password"})
+    response = client.get("/activity")
+    assert b"hey cool song" in response.data
+
+def test_activity_for_reply_to_comment(client):
+    create_user_and_song(client)
+    create_user(client, "user2", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool song"})
+
+    client.post("/login", data={"username": "user", "password": "password"})
+    client.post("/comment?threadid=2&replytoid=1", data={"content": "thank you"})
+
+    client.post("/login", data={"username": "user2", "password": "password"})
+    response = client.get("/activity")
+    assert b"thank you" in response.data
+
+def test_activity_for_reply_to_reply(client):
+    create_user_and_song(client)
+    create_user(client, "user2")
+    create_user(client, "user3", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool song"})
+
+    client.post("/login", data={"username": "user2", "password": "password"})
+    client.post("/comment?threadid=2&replytoid=1", data={"content": "it really is cool"})
+
+    client.post("/login", data={"username": "user3", "password": "password"})
+    client.post("/comment?threadid=2&replytoid=1", data={"content": "thanks for agreeing"})
+
+    # Song owner gets all three notifications
+    client.post("/login", data={"username": "user", "password": "password"})
+    response = client.get("/activity")
+    assert b"hey cool song" in response.data
+    assert b"it really is cool" in response.data
+    assert b"thanks for agreeing" in response.data
+
+    # user2 gets reply notification
+    client.post("/login", data={"username": "user2", "password": "password"})
+    response = client.get("/activity")
+    assert b"thanks for agreeing" in response.data
+
+    # user3 gets reply notification
+    client.post("/login", data={"username": "user3", "password": "password"})
+    response = client.get("/activity")
+    assert b"it really is cool" in response.data
+
+def test_activity_deleted_when_song_deleted(client):
+    create_user_and_song(client)
+    create_user(client, "user2", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool song"})
+
+    client.post("/login", data={"username": "user", "password": "password"})
+    response = client.get("/activity")
+    assert b"hey cool song" in response.data
+
+    client.get("/delete-song/1")
+    response = client.get("/activity")
+    assert b"hey cool song" not in response.data
+
+def test_activity_deleted_when_comment_deleted(client):
+    create_user_and_song(client)
+    create_user(client, "user2", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool song"})
+
+    client.post("/login", data={"username": "user", "password": "password"})
+    response = client.get("/activity")
+    assert b"hey cool song" in response.data
+
+    client.get("/delete-comment/1")
+    response = client.get("/activity")
+    assert b"hey cool song" not in response.data
+
+# New Activity Status ##########################################################
+
+def test_no_new_activity_when_not_logged_in(client):
+    response = client.get("/new-activity")
+    assert response.status_code == 200
+    assert not response.json["new_activity"]
+
+def test_no_new_activity_when_no_activity(client):
+    create_user_and_song(client)
+    response = client.get("/new-activity")
+    assert response.status_code == 200
+    assert not response.json["new_activity"]
+
+def test_new_activity_after_comment(client):
+    create_user_and_song(client)
+    create_user(client, "user2", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool song"})
+
+    client.post("/login", data={"username": "user", "password": "password"})
+    response = client.get("/new-activity")
+    assert response.status_code == 200
+    assert response.json["new_activity"]
+
+def test_no_new_activity_after_checking(client):
+    create_user_and_song(client)
+    create_user(client, "user2", login=True)
+    client.post("/comment?threadid=2", data={"content": "hey cool song"})
+
+    client.post("/login", data={"username": "user", "password": "password"})
+    client.get("/activity")  # Check activity page
+
+    response = client.get("/new-activity")
+    assert response.status_code == 200
+    assert not response.json["new_activity"]
+
index 1d66b33baf6ce0699c920d7e984d4d90d959f014..9a78051c9a396457d01f62382b45d6a818cda5c1 100644 (file)
@@ -1,9 +1,7 @@
 from flask import session
 from .utils import create_user, post_signup_form
 
-################################################################################
-# Signup
-################################################################################
+# Signup #######################################################################
 
 def test_signup_get(client):
     response = client.get("/signup")
@@ -52,9 +50,7 @@ def test_signup_user_exists(client):
     # Error the second time
     _test_signup_error(client, "user", "password", "password", b"already taken")
 
-################################################################################
-# Login/Logout
-################################################################################
+# Login/Logout #################################################################
 
 def test_login_get(client):
     response = client.get("/login")
diff --git a/test/test_comments.py b/test/test_comments.py
new file mode 100644 (file)
index 0000000..fb8fd7d
--- /dev/null
@@ -0,0 +1,201 @@
+from .utils import create_user, create_user_and_song, create_user_song_and_comment, create_user_song_and_playlist
+
+# Comments - Normal Flow #######################################################
+
+def test_comment_page_no_reply_or_edit(client):
+    create_user_and_song(client)
+    response = client.get("/comment?threadid=2")
+    assert response.status_code == 200
+    assert not b"reply" in response.data
+
+def test_post_comment(client):
+    create_user_and_song(client)
+    response = client.post("/comment?threadid=2", data={"content": "comment text here"})
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/" # No previous page, use homepage
+
+    response = client.get("/song/1/1?action=view")
+    assert b"comment text here" in response.data
+
+def test_edit_comment(client):
+    create_user_song_and_comment(client, "comment text here")
+
+    response = client.post("/comment?threadid=2&commentid=1", data={"content": "new comment content"})
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/" # No previous page, use homepage
+
+    response = client.get("/song/1/1?action=view")
+    assert b"new comment content" in response.data
+
+def test_delete_comment(client):
+    create_user_song_and_comment(client, "comment text here")
+
+    response = client.get("/delete-comment/1")
+    assert response.status_code == 302
+    assert response.headers["Location"] == "None"
+
+    response = client.get("/song/1/1?action=view")
+    assert b"comment text here" not in response.data
+
+def test_delete_song_with_comments(client):
+    create_user_song_and_comment(client, "comment text here")
+    response = client.get("/delete-song/1")
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/users/user"
+
+    response = client.get("/song/1/1?action=view")
+    assert response.status_code == 404  # Song deleted
+
+def test_reply_to_comment(client):
+    create_user_song_and_comment(client, "parent comment")
+
+    response = client.post("/comment?threadid=2&replytoid=1", data={"content": "child comment"})
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/" # No previous page, use homepage
+
+    response = client.get("/song/1/1?action=view")
+    assert b"parent comment" in response.data
+    assert b"child comment" in response.data
+
+def test_comment_on_profile(client):
+    create_user(client, "user1", login=True)
+    response = client.get("/comment?threadid=1", headers={"Referer": "/users/user1"})
+    response = client.post("/comment?threadid=1", data={"content": "comment on profile"}, follow_redirects=True)
+    assert response.request.path == "/users/user1"
+    assert b"comment on profile" in response.data
+
+def test_comment_on_playlist(client):
+    create_user_song_and_playlist(client)
+    response = client.get("/comment?threadid=3", headers={"Referer": "/playlists/1"})
+    response = client.post("/comment?threadid=3", data={"content": "comment on playlist"}, follow_redirects=True)
+    assert response.request.path == "/playlists/1"
+    assert b"comment on playlist" in response.data
+
+# Comments - Auth Status and Errors ############################################
+
+def test_comment_page_redirects_when_not_logged_in(client):
+    create_user_and_song(client)
+    client.get("/logout")
+
+    response = client.get("/comment?threadid=2")
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/login"
+
+def test_post_comment_redirects_when_not_logged_in(client):
+    create_user_and_song(client)
+    client.get("/logout")
+
+    response = client.post("/comment?threadid=2", data={"content": "should fail"})
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/login"
+
+def test_add_comment_link_not_shown_when_not_logged_in(client):
+    create_user_and_song(client)
+    response = client.get("/song/1/1?action=view")
+    assert b"Add a Comment" in response.data
+
+    client.get("/logout")
+    response = client.get("/song/1/1?action=view")
+    assert b"Add a Comment" not in response.data
+
+def test_delete_comment_not_logged_in(client):
+    create_user_song_and_comment(client, "comment text here")
+    client.get("/logout")
+
+    response = client.get("/delete-comment/1")
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/login"
+
+    # Comment not deleted
+    response = client.get("/song/1/1?action=view")
+    assert b"comment text here" in response.data
+
+def test_song_owner_can_delete_other_users_comment(client):
+    create_user(client, "user1")
+    create_user_and_song(client, "user2")
+
+    # user1 comments on user2's song
+    client.post("/login", data={"username": "user1", "password": "password"})
+    client.post("/comment?threadid=3", data={"content": "mean comment"})
+    response = client.get("/song/2/1?action=view")
+    assert b"mean comment" in response.data
+
+    # user2 deletes user1's rude comment
+    client.post("/login", data={"username": "user2", "password": "password"})
+    response = client.get("/delete-comment/1")
+    assert response.status_code == 302
+    response = client.get("/song/2/1?action=view")
+    assert b"mean comment" not in response.data
+
+def test_rando_cannot_delete_other_users_comment(client):
+    create_user(client, "user1")
+    create_user(client, "user2")
+    create_user_and_song(client, "user3")
+
+    # user1 comments on user3's song
+    client.post("/login", data={"username": "user1", "password": "password"})
+    client.post("/comment?threadid=4", data={"content": "nice comment"})
+    response = client.get("/song/3/1?action=view")
+    assert b"nice comment" in response.data
+
+    # user2 cannot delete user1's comment
+    client.post("/login", data={"username": "user2", "password": "password"})
+    response = client.get("/delete-comment/1")
+    assert response.status_code == 403
+    response = client.get("/song/3/1?action=view")
+    assert b"nice comment" in response.data
+
+def test_cannot_edit_other_users_comment(client):
+    create_user(client, "user1")
+    create_user_and_song(client, "user2")
+
+    # user1 comments on user2's song
+    client.post("/login", data={"username": "user1", "password": "password"})
+    client.post("/comment?threadid=3", data={"content": "mean comment"})
+    response = client.get("/song/2/1?action=view")
+    assert b"mean comment" in response.data
+
+    # user2 cannot edit user1's rude comment
+    client.post("/login", data={"username": "user2", "password": "password"})
+    response = client.post("/comment?threadid=2&commentid=1", data={"content": "im a meanie"})
+    assert response.status_code == 403
+    response = client.get("/song/2/1?action=view")
+    assert b"mean comment" in response.data
+
+def test_comment_invalid_threadid(client):
+    create_user_and_song(client)
+    response = client.post("/comment?threadid=3", data={"content": "broken comment"})
+    assert response.status_code == 404
+
+    response = client.get("/comment?threadid=3")
+    assert response.status_code == 404
+
+def test_comment_invalid_replytoid(client):
+    create_user_and_song(client)
+    response = client.post("/comment?threadid=2&replytoid=1", data={"content": "broken comment"})
+    assert response.status_code == 404
+
+    response = client.get("/comment?threadid=2&replytoid=1")
+    assert response.status_code == 404
+
+def test_comment_invalid_commentid(client):
+    create_user_and_song(client)
+    response = client.post("/comment?threadid=2&commentid=1", data={"content": "broken comment"})
+    assert response.status_code == 404
+
+    response = client.get("/comment?threadid=2&commentid=1")
+    assert response.status_code == 404
+
+def test_comment_no_songid(client):
+    create_user_and_song(client)
+    response = client.post("/comment", data={"content": "broken comment"})
+    assert response.status_code == 400
+
+    response = client.get("/comment")
+    assert response.status_code == 400
+
+def test_delete_invalid_comment_id(client):
+    create_user_and_song(client)
+    response = client.get("/delete-comment/1")
+    assert response.status_code == 404
+
diff --git a/test/test_news.py b/test/test_news.py
new file mode 100644 (file)
index 0000000..116f86d
--- /dev/null
@@ -0,0 +1,5 @@
+
+def test_site_news(client):
+    response = client.get("/site-news")
+    assert response.status_code == 200
+    assert b"Site News" in response.data
diff --git a/test/test_offline.py b/test/test_offline.py
deleted file mode 100644 (file)
index b4b7419..0000000
+++ /dev/null
@@ -1,588 +0,0 @@
-from pathlib import Path
-
-import pytest
-
-from .utils import create_user, create_user_and_song, upload_song, get_song_list_from_page
-
-TEST_DATA = Path(__file__).parent / "data"
-
-################################################################################
-# Site News
-################################################################################
-
-def test_site_news(client):
-    response = client.get("/site-news")
-    assert response.status_code == 200
-    assert b"Site News" in response.data
-
-################################################################################
-# Comments - Normal Flow
-################################################################################
-
-def create_user_song_and_comment(client, content):
-    create_user_and_song(client)
-    response = client.post("/comment?threadid=2", data={"content": content})
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/" # No previous page, use homepage
-
-def test_comment_page_no_reply_or_edit(client):
-    create_user_and_song(client)
-    response = client.get("/comment?threadid=2")
-    assert response.status_code == 200
-    assert not b"reply" in response.data
-
-def test_post_comment(client):
-    create_user_and_song(client)
-    response = client.post("/comment?threadid=2", data={"content": "comment text here"})
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/" # No previous page, use homepage
-
-    response = client.get("/song/1/1?action=view")
-    assert b"comment text here" in response.data
-
-def test_edit_comment(client):
-    create_user_song_and_comment(client, "comment text here")
-
-    response = client.post("/comment?threadid=2&commentid=1", data={"content": "new comment content"})
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/" # No previous page, use homepage
-
-    response = client.get("/song/1/1?action=view")
-    assert b"new comment content" in response.data
-
-def test_delete_comment(client):
-    create_user_song_and_comment(client, "comment text here")
-
-    response = client.get("/delete-comment/1")
-    assert response.status_code == 302
-    assert response.headers["Location"] == "None"
-
-    response = client.get("/song/1/1?action=view")
-    assert b"comment text here" not in response.data
-
-def test_delete_song_with_comments(client):
-    create_user_song_and_comment(client, "comment text here")
-    response = client.get("/delete-song/1")
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/users/user"
-
-    response = client.get("/song/1/1?action=view")
-    assert response.status_code == 404  # Song deleted
-
-def test_reply_to_comment(client):
-    create_user_song_and_comment(client, "parent comment")
-
-    response = client.post("/comment?threadid=2&replytoid=1", data={"content": "child comment"})
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/" # No previous page, use homepage
-
-    response = client.get("/song/1/1?action=view")
-    assert b"parent comment" in response.data
-    assert b"child comment" in response.data
-
-def test_comment_on_profile(client):
-    create_user(client, "user1", login=True)
-    response = client.get("/comment?threadid=1", headers={"Referer": "/users/user1"})
-    response = client.post("/comment?threadid=1", data={"content": "comment on profile"}, follow_redirects=True)
-    assert response.request.path == "/users/user1"
-    assert b"comment on profile" in response.data
-
-def test_comment_on_playlist(client):
-    create_user_song_and_playlist(client)
-    response = client.get("/comment?threadid=3", headers={"Referer": "/playlists/1"})
-    response = client.post("/comment?threadid=3", data={"content": "comment on playlist"}, follow_redirects=True)
-    assert response.request.path == "/playlists/1"
-    assert b"comment on playlist" in response.data
-
-################################################################################
-# Comments - Auth Status and Errors
-################################################################################
-
-def test_comment_page_redirects_when_not_logged_in(client):
-    create_user_and_song(client)
-    client.get("/logout")
-
-    response = client.get("/comment?threadid=2")
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/login"
-
-def test_post_comment_redirects_when_not_logged_in(client):
-    create_user_and_song(client)
-    client.get("/logout")
-
-    response = client.post("/comment?threadid=2", data={"content": "should fail"})
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/login"
-
-def test_add_comment_link_not_shown_when_not_logged_in(client):
-    create_user_and_song(client)
-    response = client.get("/song/1/1?action=view")
-    assert b"Add a Comment" in response.data
-
-    client.get("/logout")
-    response = client.get("/song/1/1?action=view")
-    assert b"Add a Comment" not in response.data
-
-def test_delete_comment_not_logged_in(client):
-    create_user_song_and_comment(client, "comment text here")
-    client.get("/logout")
-
-    response = client.get("/delete-comment/1")
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/login"
-
-    # Comment not deleted
-    response = client.get("/song/1/1?action=view")
-    assert b"comment text here" in response.data
-
-def test_song_owner_can_delete_other_users_comment(client):
-    create_user(client, "user1")
-    create_user_and_song(client, "user2")
-
-    # user1 comments on user2's song
-    client.post("/login", data={"username": "user1", "password": "password"})
-    client.post("/comment?threadid=3", data={"content": "mean comment"})
-    response = client.get("/song/2/1?action=view")
-    assert b"mean comment" in response.data
-
-    # user2 deletes user1's rude comment
-    client.post("/login", data={"username": "user2", "password": "password"})
-    response = client.get("/delete-comment/1")
-    assert response.status_code == 302
-    response = client.get("/song/2/1?action=view")
-    assert b"mean comment" not in response.data
-
-def test_rando_cannot_delete_other_users_comment(client):
-    create_user(client, "user1")
-    create_user(client, "user2")
-    create_user_and_song(client, "user3")
-
-    # user1 comments on user3's song
-    client.post("/login", data={"username": "user1", "password": "password"})
-    client.post("/comment?threadid=4", data={"content": "nice comment"})
-    response = client.get("/song/3/1?action=view")
-    assert b"nice comment" in response.data
-
-    # user2 cannot delete user1's comment
-    client.post("/login", data={"username": "user2", "password": "password"})
-    response = client.get("/delete-comment/1")
-    assert response.status_code == 403
-    response = client.get("/song/3/1?action=view")
-    assert b"nice comment" in response.data
-
-def test_cannot_edit_other_users_comment(client):
-    create_user(client, "user1")
-    create_user_and_song(client, "user2")
-
-    # user1 comments on user2's song
-    client.post("/login", data={"username": "user1", "password": "password"})
-    client.post("/comment?threadid=3", data={"content": "mean comment"})
-    response = client.get("/song/2/1?action=view")
-    assert b"mean comment" in response.data
-
-    # user2 cannot edit user1's rude comment
-    client.post("/login", data={"username": "user2", "password": "password"})
-    response = client.post("/comment?threadid=2&commentid=1", data={"content": "im a meanie"})
-    assert response.status_code == 403
-    response = client.get("/song/2/1?action=view")
-    assert b"mean comment" in response.data
-
-def test_comment_invalid_threadid(client):
-    create_user_and_song(client)
-    response = client.post("/comment?threadid=3", data={"content": "broken comment"})
-    assert response.status_code == 404
-
-    response = client.get("/comment?threadid=3")
-    assert response.status_code == 404
-
-def test_comment_invalid_replytoid(client):
-    create_user_and_song(client)
-    response = client.post("/comment?threadid=2&replytoid=1", data={"content": "broken comment"})
-    assert response.status_code == 404
-
-    response = client.get("/comment?threadid=2&replytoid=1")
-    assert response.status_code == 404
-
-def test_comment_invalid_commentid(client):
-    create_user_and_song(client)
-    response = client.post("/comment?threadid=2&commentid=1", data={"content": "broken comment"})
-    assert response.status_code == 404
-
-    response = client.get("/comment?threadid=2&commentid=1")
-    assert response.status_code == 404
-
-def test_comment_no_songid(client):
-    create_user_and_song(client)
-    response = client.post("/comment", data={"content": "broken comment"})
-    assert response.status_code == 400
-
-    response = client.get("/comment")
-    assert response.status_code == 400
-
-def test_delete_invalid_comment_id(client):
-    create_user_and_song(client)
-    response = client.get("/delete-comment/1")
-    assert response.status_code == 404
-
-################################################################################
-# Activity
-################################################################################
-
-def test_activity_redirects_when_not_logged_in(client):
-    response = client.get("/activity")
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/login"
-
-def test_activity_empty_when_user_has_no_notifications(client):
-    create_user_and_song(client)
-    response = client.get("/activity")
-    assert b"Nothing to show" in response.data
-
-def test_activity_for_comment_on_song(client):
-    create_user_and_song(client)
-    create_user(client, "user2", login=True)
-    client.post("/comment?threadid=2", data={"content": "hey cool song"})
-    response = client.get("/activity")
-    assert b"Nothing to show" in response.data
-
-    client.post("/login", data={"username": "user", "password": "password"})
-    response = client.get("/activity")
-    assert b"hey cool song" in response.data
-
-def test_activity_for_reply_to_comment(client):
-    create_user_and_song(client)
-    create_user(client, "user2", login=True)
-    client.post("/comment?threadid=2", data={"content": "hey cool song"})
-
-    client.post("/login", data={"username": "user", "password": "password"})
-    client.post("/comment?threadid=2&replytoid=1", data={"content": "thank you"})
-
-    client.post("/login", data={"username": "user2", "password": "password"})
-    response = client.get("/activity")
-    assert b"thank you" in response.data
-
-def test_activity_for_reply_to_reply(client):
-    create_user_and_song(client)
-    create_user(client, "user2")
-    create_user(client, "user3", login=True)
-    client.post("/comment?threadid=2", data={"content": "hey cool song"})
-
-    client.post("/login", data={"username": "user2", "password": "password"})
-    client.post("/comment?threadid=2&replytoid=1", data={"content": "it really is cool"})
-
-    client.post("/login", data={"username": "user3", "password": "password"})
-    client.post("/comment?threadid=2&replytoid=1", data={"content": "thanks for agreeing"})
-
-    # Song owner gets all three notifications
-    client.post("/login", data={"username": "user", "password": "password"})
-    response = client.get("/activity")
-    assert b"hey cool song" in response.data
-    assert b"it really is cool" in response.data
-    assert b"thanks for agreeing" in response.data
-
-    # user2 gets reply notification
-    client.post("/login", data={"username": "user2", "password": "password"})
-    response = client.get("/activity")
-    assert b"thanks for agreeing" in response.data
-
-    # user3 gets reply notification
-    client.post("/login", data={"username": "user3", "password": "password"})
-    response = client.get("/activity")
-    assert b"it really is cool" in response.data
-
-def test_activity_deleted_when_song_deleted(client):
-    create_user_and_song(client)
-    create_user(client, "user2", login=True)
-    client.post("/comment?threadid=2", data={"content": "hey cool song"})
-
-    client.post("/login", data={"username": "user", "password": "password"})
-    response = client.get("/activity")
-    assert b"hey cool song" in response.data
-
-    client.get("/delete-song/1")
-    response = client.get("/activity")
-    assert b"hey cool song" not in response.data
-
-def test_activity_deleted_when_comment_deleted(client):
-    create_user_and_song(client)
-    create_user(client, "user2", login=True)
-    client.post("/comment?threadid=2", data={"content": "hey cool song"})
-
-    client.post("/login", data={"username": "user", "password": "password"})
-    response = client.get("/activity")
-    assert b"hey cool song" in response.data
-
-    client.get("/delete-comment/1")
-    response = client.get("/activity")
-    assert b"hey cool song" not in response.data
-
-################################################################################
-# New Activity Status
-################################################################################
-
-def test_no_new_activity_when_not_logged_in(client):
-    response = client.get("/new-activity")
-    assert response.status_code == 200
-    assert not response.json["new_activity"]
-
-def test_no_new_activity_when_no_activity(client):
-    create_user_and_song(client)
-    response = client.get("/new-activity")
-    assert response.status_code == 200
-    assert not response.json["new_activity"]
-
-def test_new_activity_after_comment(client):
-    create_user_and_song(client)
-    create_user(client, "user2", login=True)
-    client.post("/comment?threadid=2", data={"content": "hey cool song"})
-
-    client.post("/login", data={"username": "user", "password": "password"})
-    response = client.get("/new-activity")
-    assert response.status_code == 200
-    assert response.json["new_activity"]
-
-def test_no_new_activity_after_checking(client):
-    create_user_and_song(client)
-    create_user(client, "user2", login=True)
-    client.post("/comment?threadid=2", data={"content": "hey cool song"})
-
-    client.post("/login", data={"username": "user", "password": "password"})
-    client.get("/activity")  # Check activity page
-
-    response = client.get("/new-activity")
-    assert response.status_code == 200
-    assert not response.json["new_activity"]
-
-################################################################################
-# Playlists
-################################################################################
-
-# Create Playlist ##############################################################
-
-def test_create_playlist(client):
-    create_user(client, "user", login=True)
-    response = client.post("/create-playlist", data={"name": "my playlist", "type": "private"})
-    assert response.status_code == 302
-
-    response = client.get("/users/user")
-    assert b"my playlist" in response.data
-    assert b"[Private]" in response.data
-
-def test_create_playlist_invalid_name(client):
-    create_user(client, "user", login=True)
-    response = client.post("/create-playlist", data={"name": "a"*201, "type": "private"})
-    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")
-    assert b"must have a name" in response.data
-
-def test_create_playlist_not_logged_in(client):
-    response = client.post("/create-playlist", data={"name": "my playlist", "type": "private"})
-    assert response.status_code == 302
-    assert response.headers["Location"] == "/login"
-
-# Delete Playlist ##############################################################
-
-def create_user_and_playlist(client):
-    create_user(client, "user", login=True)
-    client.post("/create-playlist", data={"name": "my playlist", "type": "private"})
-
-def test_delete_playlist(client):
-    create_user_and_playlist(client)
-    response = client.get("/delete-playlist/1", follow_redirects=True)
-    assert b"Deleted playlist my playlist" in response.data
-
-    response = client.get("/users/user")
-    assert not b"my playlist" in response.data
-
-def test_delete_playlist_invalid_playlistid(client):
-    create_user_and_playlist(client)
-    response = client.get("/delete-playlist/2")
-    assert response.status_code == 404
-
-def test_delete_playlist_not_logged_in(client):
-    create_user_and_playlist(client)
-    client.get("/logout")
-
-    response = client.get("/delete-playlist/2")
-    assert response.status_code == 401
-
-def test_delete_playlist_other_users_playlist(client):
-    create_user_and_playlist(client)
-    create_user(client, "user2", login=True)
-
-    response = client.get("/delete-playlist/1")
-    assert response.status_code == 403
-
-# Append to Playlist ###########################################################
-
-def create_user_song_and_playlist(client, playlist_type="private"):
-    create_user_and_song(client)
-    client.post("/create-playlist", data={"name": "my playlist", "type": playlist_type})
-
-def test_append_to_playlist(client):
-    create_user_song_and_playlist(client)
-    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"})
-    data = response.json
-    assert data["status"] == "success"
-    assert "Added 'song title' to my playlist" in data["messages"]
-
-def test_append_to_playlist_not_logged_in(client):
-    create_user_song_and_playlist(client)
-    client.get("/logout")
-    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"})
-    assert response.status_code == 401
-
-def test_append_to_other_users_playlist(client):
-    create_user_song_and_playlist(client)
-    create_user(client, "user2", login=True)
-    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"})
-    assert response.status_code == 403
-
-def test_append_playlist_invalid_songid(client):
-    create_user_song_and_playlist(client)
-    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "2"})
-    assert response.status_code == 404
-
-def test_append_playlist_invalid_playlistid(client):
-    create_user_song_and_playlist(client)
-    response = client.post("/append-to-playlist", data={"playlistid": "2", "songid": "1"})
-    assert response.status_code == 404
-
-# Playlist on Profile ##########################################################
-
-def test_playlists_on_own_profile(client):
-    create_user_song_and_playlist(client)  # Private playlist
-    client.post("/create-playlist", data={"name": "my public playlist", "type": "public"}, follow_redirects=True)
-    client.get("/users/user") # Clear flashes
-
-    # Shows public and private playlists
-    response = client.get("/users/user")
-    assert b"my playlist" in response.data
-    assert b"my public playlist" in response.data
-
-def test_playlists_on_other_users_profile(client):
-    create_user_song_and_playlist(client)  # Private playlist
-    client.post("/create-playlist", data={"name": "my public playlist", "type": "public"})
-    client.get("/users/user") # Clear flashes
-
-    # Shows only public playlists
-    create_user(client, "user2", login=True)
-    response = client.get("/users/user")
-    assert b"my playlist" not in response.data
-    assert b"my public playlist" in response.data
-
-# View Playlist ################################################################
-
-def test_view_own_public_playlist(client):
-    create_user_song_and_playlist(client, playlist_type="public")
-    response = client.get("/playlists/1")
-    assert response.status_code == 200
-    assert b"[Public]" in response.data
-
-def test_view_own_private_playlist(client):
-    create_user_song_and_playlist(client, playlist_type="private")
-    response = client.get("/playlists/1")
-    assert response.status_code == 200
-    assert b"[Private]" in response.data
-
-def test_view_other_users_public_playlist(client):
-    create_user_song_and_playlist(client, playlist_type="public")
-    create_user(client, "user2", login=True)
-    response = client.get("/playlists/1")
-    assert response.status_code == 200
-    assert b"[Public]" not in response.data  # Type not shown
-
-def test_view_other_users_private_playlist(client):
-    create_user_song_and_playlist(client, playlist_type="private")
-    create_user(client, "user2", login=True)
-    response = client.get("/playlists/1")
-    assert response.status_code == 404
-
-def test_view_invalid_playlist(client):
-    response = client.get("/playlists/0")
-    assert response.status_code == 404
-
-# Edit Playlist ################################################################
-
-def test_edit_playlist_change_type(client):
-    create_user_song_and_playlist(client, playlist_type="private")
-    response = client.post("/edit-playlist/1", data={"name": "my playlist", "type": "public", "songids": ""})
-    assert response.status_code == 302
-
-    response = client.get("/playlists/1")
-    assert b"[Public]" in response.data
-
-def test_edit_playlist_change_name(client):
-    create_user_song_and_playlist(client, playlist_type="private")
-    response = client.post("/edit-playlist/1", data={"name": "cool new playlist name", "type": "private", "songids": ""})
-    assert response.status_code == 302
-
-    response = client.get("/playlists/1")
-    assert b"cool new playlist name" in response.data
-
-def test_edit_playlist_change_name_invalid(client):
-    create_user_song_and_playlist(client, playlist_type="private")
-    client.get("/playlists/1")  # Clear flashes
-    response = client.post("/edit-playlist/1", data={"name": "", "type": "private", "songids": ""})
-    assert response.status_code == 302
-
-    response = client.get("/playlists/1")
-    assert b"my playlist" in response.data
-    assert b"must have a name" in response.data
-
-def test_edit_playlist_change_song_order(client):
-    create_user_song_and_playlist(client)
-    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)
-    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/test/test_playlists.py b/test/test_playlists.py
new file mode 100644 (file)
index 0000000..540a94d
--- /dev/null
@@ -0,0 +1,227 @@
+from .utils import create_user, upload_song, get_song_list_from_page, create_user_song_and_playlist
+
+# Create Playlist ##############################################################
+
+def test_create_playlist(client):
+    create_user(client, "user", login=True)
+    response = client.post("/create-playlist", data={"name": "my playlist", "type": "private"})
+    assert response.status_code == 302
+
+    response = client.get("/users/user")
+    assert b"my playlist" in response.data
+    assert b"[Private]" in response.data
+
+def test_create_playlist_invalid_name(client):
+    create_user(client, "user", login=True)
+    response = client.post("/create-playlist", data={"name": "a"*201, "type": "private"})
+    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")
+    assert b"must have a name" in response.data
+
+def test_create_playlist_not_logged_in(client):
+    response = client.post("/create-playlist", data={"name": "my playlist", "type": "private"})
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/login"
+
+# Delete Playlist ##############################################################
+
+def create_user_and_playlist(client):
+    create_user(client, "user", login=True)
+    client.post("/create-playlist", data={"name": "my playlist", "type": "private"})
+
+def test_delete_playlist(client):
+    create_user_and_playlist(client)
+    response = client.get("/delete-playlist/1", follow_redirects=True)
+    assert b"Deleted playlist my playlist" in response.data
+
+    response = client.get("/users/user")
+    assert not b"my playlist" in response.data
+
+def test_delete_playlist_invalid_playlistid(client):
+    create_user_and_playlist(client)
+    response = client.get("/delete-playlist/2")
+    assert response.status_code == 404
+
+def test_delete_playlist_not_logged_in(client):
+    create_user_and_playlist(client)
+    client.get("/logout")
+
+    response = client.get("/delete-playlist/2")
+    assert response.status_code == 401
+
+def test_delete_playlist_other_users_playlist(client):
+    create_user_and_playlist(client)
+    create_user(client, "user2", login=True)
+
+    response = client.get("/delete-playlist/1")
+    assert response.status_code == 403
+
+# Append to Playlist ###########################################################
+
+def test_append_to_playlist(client):
+    create_user_song_and_playlist(client)
+    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"})
+    data = response.json
+    assert data["status"] == "success"
+    assert "Added 'song title' to my playlist" in data["messages"]
+
+def test_append_to_playlist_not_logged_in(client):
+    create_user_song_and_playlist(client)
+    client.get("/logout")
+    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"})
+    assert response.status_code == 401
+
+def test_append_to_other_users_playlist(client):
+    create_user_song_and_playlist(client)
+    create_user(client, "user2", login=True)
+    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "1"})
+    assert response.status_code == 403
+
+def test_append_playlist_invalid_songid(client):
+    create_user_song_and_playlist(client)
+    response = client.post("/append-to-playlist", data={"playlistid": "1", "songid": "2"})
+    assert response.status_code == 404
+
+def test_append_playlist_invalid_playlistid(client):
+    create_user_song_and_playlist(client)
+    response = client.post("/append-to-playlist", data={"playlistid": "2", "songid": "1"})
+    assert response.status_code == 404
+
+# Playlist on Profile ##########################################################
+
+def test_playlists_on_own_profile(client):
+    create_user_song_and_playlist(client)  # Private playlist
+    client.post("/create-playlist", data={"name": "my public playlist", "type": "public"}, follow_redirects=True)
+    client.get("/users/user") # Clear flashes
+
+    # Shows public and private playlists
+    response = client.get("/users/user")
+    assert b"my playlist" in response.data
+    assert b"my public playlist" in response.data
+
+def test_playlists_on_other_users_profile(client):
+    create_user_song_and_playlist(client)  # Private playlist
+    client.post("/create-playlist", data={"name": "my public playlist", "type": "public"})
+    client.get("/users/user") # Clear flashes
+
+    # Shows only public playlists
+    create_user(client, "user2", login=True)
+    response = client.get("/users/user")
+    assert b"my playlist" not in response.data
+    assert b"my public playlist" in response.data
+
+# View Playlist ################################################################
+
+def test_view_own_public_playlist(client):
+    create_user_song_and_playlist(client, playlist_type="public")
+    response = client.get("/playlists/1")
+    assert response.status_code == 200
+    assert b"[Public]" in response.data
+
+def test_view_own_private_playlist(client):
+    create_user_song_and_playlist(client, playlist_type="private")
+    response = client.get("/playlists/1")
+    assert response.status_code == 200
+    assert b"[Private]" in response.data
+
+def test_view_other_users_public_playlist(client):
+    create_user_song_and_playlist(client, playlist_type="public")
+    create_user(client, "user2", login=True)
+    response = client.get("/playlists/1")
+    assert response.status_code == 200
+    assert b"[Public]" not in response.data  # Type not shown
+
+def test_view_other_users_private_playlist(client):
+    create_user_song_and_playlist(client, playlist_type="private")
+    create_user(client, "user2", login=True)
+    response = client.get("/playlists/1")
+    assert response.status_code == 404
+
+def test_view_invalid_playlist(client):
+    response = client.get("/playlists/0")
+    assert response.status_code == 404
+
+# Edit Playlist ################################################################
+
+def test_edit_playlist_change_type(client):
+    create_user_song_and_playlist(client, playlist_type="private")
+    response = client.post("/edit-playlist/1", data={"name": "my playlist", "type": "public", "songids": ""})
+    assert response.status_code == 302
+
+    response = client.get("/playlists/1")
+    assert b"[Public]" in response.data
+
+def test_edit_playlist_change_name(client):
+    create_user_song_and_playlist(client, playlist_type="private")
+    response = client.post("/edit-playlist/1", data={"name": "cool new playlist name", "type": "private", "songids": ""})
+    assert response.status_code == 302
+
+    response = client.get("/playlists/1")
+    assert b"cool new playlist name" in response.data
+
+def test_edit_playlist_change_name_invalid(client):
+    create_user_song_and_playlist(client, playlist_type="private")
+    client.get("/playlists/1")  # Clear flashes
+    response = client.post("/edit-playlist/1", data={"name": "", "type": "private", "songids": ""})
+    assert response.status_code == 302
+
+    response = client.get("/playlists/1")
+    assert b"my playlist" in response.data
+    assert b"must have a name" in response.data
+
+def test_edit_playlist_change_song_order(client):
+    create_user_song_and_playlist(client)
+    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)
+    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 4cc8f49806c733cf5c7654103851ea0b5c898fb0..f83d5b6d8bfdb4ee650b556c72eba39c38643894 100644 (file)
@@ -3,10 +3,6 @@ from .utils import create_user
 
 TEST_DATA = Path(__file__).parent / "data"
 
-################################################################################
-# Profile/Bio
-################################################################################
-
 def test_default_bio_empty(client):
     create_user(client, "user", "password")
 
index d86f3ab1efc2c2fb0d6439aa00477e97fa2962c4..8c864b02e4590fe210a4db057006b10497f496ba 100644 (file)
@@ -1,10 +1,6 @@
 from .utils import create_user_and_song, create_user, upload_song, get_song_list_from_page
 
-################################################################################
-# Song Lists (Profile/Homepage/Songs)
-################################################################################
-
-# Profile
+# Profile ######################################################################
 
 def test_profile_songs_one_song(client):
     create_user_and_song(client)
@@ -23,7 +19,7 @@ def test_profile_songs_two_songs(client):
     assert songs[0]["title"] == "title2"
     assert songs[1]["title"] == "song title"
 
-# Homepage
+# Homepage #####################################################################
 
 def test_homepage_songs_two_songs(client):
     create_user(client, "user1", "password", login=True)
@@ -42,7 +38,7 @@ def test_homepage_songs_two_songs(client):
     assert songs[1]["title"] == "song1"
     assert songs[1]["username"] == "user1"
 
-# Songs by tag
+# Songs by tag #################################################################
 
 def test_songs_by_tag_no_user(client):
     create_user(client, "user1", "password", login=True)
index 6c26271c55e0170ca2cd39243bc27c554ff7998b..559fa99fd92af2ae8c5a00b84e3bd19156e221ab 100644 (file)
@@ -6,9 +6,7 @@ from .utils import create_user, create_user_and_song, upload_song
 
 TEST_DATA = Path(__file__).parent / "data"
 
-################################################################################
-# Upload Song
-################################################################################
+# Upload Song ##################################################################
 
 def test_upload_song_success(client):
     create_user(client, "user", "password", login=True)
@@ -68,9 +66,7 @@ def test_upload_song_from_youtube(client):
     assert response.status_code == 200
     assert b"Successfully uploaded &#39;song title&#39;" in response.data
 
-################################################################################
-# Edit Song
-################################################################################
+# Edit Song ####################################################################
 
 def test_edit_invalid_song(client):
     create_user(client, "user", "password", login=True)
@@ -210,9 +206,7 @@ def test_uppercase_tags(client):
     assert b"tag2" not in response.data
     assert b"t2" in response.data
 
-################################################################################
-# Delete Song
-################################################################################
+# Delete Song ##################################################################
 
 def test_delete_song_success(client):
     create_user_and_song(client)
@@ -243,9 +237,7 @@ def test_delete_song_other_users_song(client):
     response = client.get("/delete-song/1")
     assert response.status_code == 401
 
-################################################################################
-# Song mp3 file
-################################################################################
+# Song mp3 file ################################################################
 
 def test_get_song(client):
     create_user_and_song(client)
index 229d5f81621267694eb1085dc85f2624cdf06d20..b4d7d26e572a10c8447f2683dccf49841ff3a56d 100644 (file)
@@ -35,6 +35,16 @@ def create_user_and_song(client, username="user"):
     create_user(client, username, "password", login=True)
     upload_song(client, b"Success", user=username)
 
+def create_user_song_and_comment(client, content):
+    create_user_and_song(client)
+    response = client.post("/comment?threadid=2", data={"content": content})
+    assert response.status_code == 302
+    assert response.headers["Location"] == "/" # No previous page, use homepage
+
+def create_user_song_and_playlist(client, playlist_type="private"):
+    create_user_and_song(client)
+    client.post("/create-playlist", data={"name": "my playlist", "type": playlist_type})
+
 def upload_song(client, msg, error=False, songid=None, user="user", userid=1, filename=TEST_DATA/"sample-3s.mp3", **kwargs):
     song_file = open(filename, "rb")