From: Chris Fulljames Date: Sat, 1 Feb 2025 13:38:38 +0000 (-0500) Subject: Add online test for comments and activity X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=41b04c14b539a6af6e9bd89fea6502f2f96bc297;p=littlesongplace.git Add online test for comments and activity --- diff --git a/test/test_online.py b/test/test_online.py index d311b8b..3347190 100644 --- a/test/test_online.py +++ b/test/test_online.py @@ -14,11 +14,14 @@ def url(path): def s(): s = requests.Session() # User may already exist, but that's fine - we'll just ignore the signup error - response = s.post(url("/signup"), data={"username": "user", "password": "1234asdf!@#$", "password_confirm": "1234asdf!@#$"}) - response = s.post(url("/login"), data={"username": "user", "password": "1234asdf!@#$"}) - response.raise_for_status() + _login(s, "user", "1234asdf!@#$") yield s +def _login(s, username, password): + s.post(url("/signup"), data={"username": username, "password": password, "password_confirm": password}) + response = s.post(url("/login"), data={"username": username, "password": password}) + response.raise_for_status() + def _get_song_list_from_page(page_contents): matches = re.findall('data-song="(.*)">', page_contents) return [json.loads(html.unescape(m)) for m in matches] @@ -51,3 +54,46 @@ def test_upload_and_delete_song(s): songs = _get_song_list_from_page(response.text) assert not any(song["songid"] == songid for song in songs) +def test_comments_and_activity(s): + # Upload song + response = s.post( + url("/upload-song"), + files={"song": open("sample-3s.mp3", "rb")}, + data={"title": "song title", "description": "", "tags": "", "collabs": ""}, + ) + response.raise_for_status() + songs = _get_song_list_from_page(response.text) + song = songs[0] + songid = song["songid"] + + try: + _login(s, "user1", "1234asdf!@#$") + + # Comment on song as new user + response = s.get( + url(f"/comment?songid={songid}"), + headers={"referer": "/users/user"}) + response.raise_for_status() + response = s.post( + url(f"/comment?songid={songid}"), + headers={"referer": f"/comment?songid={songid}"}, + data={"content": "hey cool song"}) + response.raise_for_status() + assert "hey cool song" in response.text + + # Check activity status as original user + _login(s, "user", "1234asdf!@#$") + response = s.get(url("/new-activity")) + assert response.json()["new_activity"] is True + + # Check activity page + response = s.get(url("/activity")) + assert "hey cool song" in response.text + + finally: + # Delete song + response = s.get(url(f"/delete-song/{songid}"), headers={"referer": "/users/user"}) + response.raise_for_status() + songs = _get_song_list_from_page(response.text) + assert not any(song["songid"] == songid for song in songs) +