Skip to content

Commit

Permalink
add unit tests for tracks endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardfritz committed Nov 10, 2023
1 parent b7c8d03 commit 12b5f82
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 3 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-r requirements.txt
ruff==0.1.3
pytest==7.4.3
pytest==7.4.3
httpx==0.25.1
pyfakefs==5.3.0
4 changes: 2 additions & 2 deletions src/pytunes/routers/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@


@router.get("/{track_id}.m3u8")
async def get_track_playlist(track_id: UUID):
def get_track_playlist(track_id: UUID):
return FileResponse(f"/data/.pytunes/{track_id}.m3u8")


@router.get("/{track_id}.{segment_index}.m4a")
async def get_track_segment(track_id: UUID, segment_index: int):
def get_track_segment(track_id: UUID, segment_index: int):
return FileResponse(f"/data/.pytunes/{track_id}.{segment_index}.m4a")
Empty file added src/pytunes/testing/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions src/pytunes/testing/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from fastapi.testclient import TestClient
from pytunes.main import app, get_current_username

app.dependency_overrides[get_current_username] = lambda: "current_username"
client = TestClient(app)
13 changes: 13 additions & 0 deletions tests/test_tracks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from pytunes.testing.client import client


def test_get_track_playlist(fs):
fs.create_file("/data/.pytunes/0beec7b5-ea3f-0fdb-c95d-0dd47f3c5bc2.m3u8")
response = client.get("/tracks/0beec7b5-ea3f-0fdb-c95d-0dd47f3c5bc2.m3u8")
assert response.status_code == 200


def test_get_track_segment(fs):
fs.create_file("/data/.pytunes/0beec7b5-ea3f-0fdb-c95d-0dd47f3c5bc2.0.m4a")
response = client.get("/tracks/0beec7b5-ea3f-0fdb-c95d-0dd47f3c5bc2.0.m4a")
assert response.status_code == 200

0 comments on commit 12b5f82

Please sign in to comment.