pip install -r dev-requirements.txt
- name: Run pytest
+ working-directory: ./test
run: |
- pytest test.py
+ pytest test_offline.py
deploy-test-instance:
+ needs: run-offline-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
# Restart service
sudo systemctl restart littlesongplace-test.service
+
+ run-online-tests:
+ runs-on: ubuntu-latest
+ needs: [run-offline-tests, deploy-test-instance]
+ steps:
+ - uses: actions/checkout@v1
+
+ - name: Set up Python
+ uses: actions/setup-python@v3
+ with:
+ python-version: "3.11"
+
+ - name: Install Dependencies
+ run: |
+ python -m pip install --upgrade pip
+ pip install -r dev-requirements.txt
+
+ - name: Run pytest
+ working-directory: ./test
+ run: |
+ pytest test_online.py
+
-r requirements.txt
pytest
+requests
app = Flask(__name__)
app.secret_key = os.environ["SECRET_KEY"] if "SECRET_KEY" in os.environ else "dev"
app.config["MAX_CONTENT_LENGTH"] = 50 * 1024 * 1024
-app.logger.addHandler(handler)
if "DATA_DIR" in os.environ:
# Running on server behind proxy
################################################################################
def _test_upload_song(client, msg, error=False, songid=None, user="user", **kwargs):
- song_file = open("test/sample-3s.mp3", "rb")
+ song_file = open("sample-3s.mp3", "rb")
data = {
"song": song_file,
_create_user_and_song(client)
data = {
- "song": open("test/sample-3s.mp3", "rb"),
+ "song": open("sample-3s.mp3", "rb"),
"title": "song title",
"description": "song description",
"tags": "tag",
_create_user_and_song(client)
data = {
- "song": open("test/sample-3s.mp3", "rb"),
+ "song": open("sample-3s.mp3", "rb"),
"title": "song title",
"description": "song description",
"tags": "tag",
_create_user(client, "user2", login=True)
data = {
- "song": open("test/sample-3s.mp3", "rb"),
+ "song": open("sample-3s.mp3", "rb"),
"title": "song title",
"description": "song description",
"tags": "tag",
def test_get_song(client):
_create_user_and_song(client)
response = client.get("/song/1/1")
- with open("test/sample-3s.mp3", "rb") as mp3file:
+ with open("sample-3s.mp3", "rb") as mp3file:
assert response.data == mp3file.read()
def test_get_song_invalid_song(client):
--- /dev/null
+import html
+import json
+import re
+
+import requests
+import pytest
+
+HOST = "http://littlesong.place:8000"
+
+def url(path):
+ return HOST + path
+
+@pytest.fixture(scope="module")
+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()
+ yield s
+
+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]
+
+def test_upload_and_delete_song(s):
+ response = s.post(
+ url("/upload-song"),
+ files={"song": open("sample-3s.mp3", "rb")},
+ data={
+ "title": "song title",
+ "description": "song description",
+ "tags": "tag1, tag2",
+ "collabs": "p1, p2",
+ },
+ )
+ response.raise_for_status()
+ songs = _get_song_list_from_page(response.text)
+ song = songs[0]
+
+ # Check song uploaded correctly
+ assert song["title"] == "song title"
+ assert song["description"] == "song description"
+ assert song["tags"] == ["tag1", "tag2"]
+ assert song["collaborators"] == ["p1", "p2"]
+
+ # Delete song
+ songid = song["songid"]
+ 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)
+