replytoid INTEGER,
created TEXT NOT NULL,
content TEXT NOT NULL,
- FOREIGN KEY(songid) REFERENCES songs(songid),
- FOREIGN KEY(userid) REFERENCES users(userid)
+ FOREIGN KEY(songid) REFERENCES songs(songid) ON DELETE CASCADE,
+ FOREIGN KEY(userid) REFERENCES users(userid) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_comments_by_song ON song_comments(songid);
CREATE INDEX IF NOT EXISTS idx_comments_by_user ON song_comments(userid);
notificationid INTEGER PRIMARY KEY,
commentid INTEGER NOT NULL,
targetuserid INTEGER NOT NULL,
- FOREIGN KEY(commentid) REFERENCES song_comments(commentid),
- FOREIGN KEY(targetuserid) REFERENCES users(userid)
+ FOREIGN KEY(commentid) REFERENCES song_comments(commentid) ON DELETE CASCADE,
+ FOREIGN KEY(targetuserid) REFERENCES users(userid) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_song_comment_notifications_by_target ON song_comment_notifications(targetuserid);
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"] == "None" # No previous page, use homepage
+
+ 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.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?songid=1", 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?songid=1", 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
+