From e62854a46095fd1a9e511cfe22c01c5088426570 Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Sun, 30 Mar 2025 09:11:30 -0400 Subject: [PATCH] Move test data to subdir --- test/{ => data}/lsp_notes.png | Bin test/{ => data}/sample-3s.mp3 | Bin test/{ => data}/sample-4s.mp4 | Bin test/{ => data}/sample-6s.mp3 | Bin test/test_offline.py | 24 +++++++++++++----------- 5 files changed, 13 insertions(+), 11 deletions(-) rename test/{ => data}/lsp_notes.png (100%) rename test/{ => data}/sample-3s.mp3 (100%) rename test/{ => data}/sample-4s.mp4 (100%) rename test/{ => data}/sample-6s.mp3 (100%) diff --git a/test/lsp_notes.png b/test/data/lsp_notes.png similarity index 100% rename from test/lsp_notes.png rename to test/data/lsp_notes.png diff --git a/test/sample-3s.mp3 b/test/data/sample-3s.mp3 similarity index 100% rename from test/sample-3s.mp3 rename to test/data/sample-3s.mp3 diff --git a/test/sample-4s.mp4 b/test/data/sample-4s.mp4 similarity index 100% rename from test/sample-4s.mp4 rename to test/data/sample-4s.mp4 diff --git a/test/sample-6s.mp3 b/test/data/sample-6s.mp3 similarity index 100% rename from test/sample-6s.mp3 rename to test/data/sample-6s.mp3 diff --git a/test/test_offline.py b/test/test_offline.py index e6cf3ed..1ed9a25 100644 --- a/test/test_offline.py +++ b/test/test_offline.py @@ -14,6 +14,8 @@ from flask import session sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) +TEST_DATA = Path(__file__).parent / "data" + import main @pytest.fixture @@ -188,7 +190,7 @@ def test_upload_pfp(client): _create_user(client, "user", "password", login=True) response = client.post("/edit-profile", data={ "bio": "", - "pfp": open("lsp_notes.png", "rb"), + "pfp": open(TEST_DATA/"lsp_notes.png", "rb"), "fgcolor": "#000000", "bgcolor": "#000000", "accolor": "#000000", @@ -198,7 +200,7 @@ def test_upload_pfp(client): def test_edit_profile_not_logged_in(client): response = client.post("/edit-profile", data={ "bio": "", - "pfp": open("lsp_notes.png", "rb"), + "pfp": open(TEST_DATA/"lsp_notes.png", "rb"), "fgcolor": "#000000", "bgcolor": "#000000", "accolor": "#000000", @@ -209,7 +211,7 @@ def test_get_pfp(client): _create_user(client, "user", "password", login=True) client.post("/edit-profile", data={ "bio": "", - "pfp": open("lsp_notes.png", "rb"), + "pfp": open(TEST_DATA/"lsp_notes.png", "rb"), "fgcolor": "#000000", "bgcolor": "#000000", "accolor": "#000000", @@ -235,7 +237,7 @@ def test_get_pfp_invalid_user(client): # Upload Song ################################################################################ -def _test_upload_song(client, msg, error=False, songid=None, user="user", userid=1, filename="sample-3s.mp3", **kwargs): +def _test_upload_song(client, msg, error=False, songid=None, user="user", userid=1, filename=TEST_DATA/"sample-3s.mp3", **kwargs): song_file = open(filename, "rb") data = { @@ -303,7 +305,7 @@ def test_upload_song_invalid_audio(client): def test_upload_song_from_mp4(client): _create_user(client, "user", "password", login=True) - _test_upload_song(client, b"Successfully uploaded 'song title'", filename="sample-4s.mp4") + _test_upload_song(client, b"Successfully uploaded 'song title'", filename=TEST_DATA/"sample-4s.mp4") @pytest.mark.skip def test_upload_song_from_youtube(client): @@ -350,10 +352,10 @@ def _create_user_and_song(client, username="user"): def test_update_song_success(client): _create_user_and_song(client) - _test_upload_song(client, b"Successfully updated 'song title'", filename="sample-6s.mp3", songid=1) + _test_upload_song(client, b"Successfully updated 'song title'", filename=TEST_DATA/"sample-6s.mp3", songid=1) response = client.get("/song/1/1") assert response.status_code == 200 - with open("sample-6s.mp3", "rb") as expected_file: + with open(TEST_DATA/"sample-6s.mp3", "rb") as expected_file: assert response.data == expected_file.read() @pytest.mark.skip @@ -409,7 +411,7 @@ def test_update_song_invalid_song(client): _create_user_and_song(client) data = { - "song-file": open("sample-3s.mp3", "rb"), + "song-file": open(TEST_DATA/"sample-3s.mp3", "rb"), "title": "song title", "description": "song description", "tags": "tag", @@ -423,7 +425,7 @@ def test_update_song_invalid_id(client): _create_user_and_song(client) data = { - "song-file": open("sample-3s.mp3", "rb"), + "song-file": open(TEST_DATA/"sample-3s.mp3", "rb"), "title": "song title", "description": "song description", "tags": "tag", @@ -438,7 +440,7 @@ def test_update_song_other_users_song(client): _create_user(client, "user2", login=True) data = { - "song-file": open("sample-3s.mp3", "rb"), + "song-file": open(TEST_DATA/"sample-3s.mp3", "rb"), "title": "song title", "description": "song description", "tags": "tag", @@ -508,7 +510,7 @@ def test_delete_song_other_users_song(client): def test_get_song(client): _create_user_and_song(client) response = client.get("/song/1/1") - with open("sample-3s.mp3", "rb") as mp3file: + with open(TEST_DATA/"sample-3s.mp3", "rb") as mp3file: assert response.data == mp3file.read() def test_get_song_invalid_song(client): -- 2.39.5