-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5669d3
commit cfa2444
Showing
11 changed files
with
87 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from unittest.mock import Mock | ||
|
||
from fastapi.testclient import TestClient | ||
|
||
from pytunes.dependencies import get_db | ||
from pytunes.main import app, get_current_username | ||
|
||
mock_current_username = "current_username" | ||
app.dependency_overrides[get_current_username] = lambda: mock_current_username | ||
|
||
mock_db = Mock() | ||
app.dependency_overrides[get_db] = lambda: mock_db | ||
|
||
client = TestClient(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from unittest.mock import patch | ||
from uuid import uuid4 | ||
|
||
from pytunes import models | ||
from pytunes.testing.setup import client | ||
|
||
|
||
@patch( | ||
"pytunes.routers.albums.crud.get_album_tracks", | ||
return_value=[ | ||
models.Track(id=uuid4(), name="foo"), | ||
models.Track(id=uuid4(), name="bar"), | ||
], | ||
) | ||
@patch("pytunes.routers.albums.track_to_playlist_item", return_value="playlist_item") | ||
def test_get_album_playlist(mock_get_album_tracks, mock_track_to_playlist_item): | ||
album_id = uuid4() | ||
|
||
response = client.get(f"/albums/{album_id}.m3u") | ||
|
||
assert response.status_code == 200 | ||
assert response.text == "\n".join(["#EXTM3U", "playlist_item", "playlist_item"]) | ||
assert response.headers["content-type"] == "audio/x-mpegurl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
from pytunes.testing.client import client | ||
from uuid import uuid4 | ||
|
||
from pytunes.testing.setup 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") | ||
track_id = uuid4() | ||
fs.create_file(f"/data/.pytunes/{track_id}.m3u8") | ||
|
||
response = client.get(f"/tracks/{track_id}.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") | ||
track_id = uuid4() | ||
fs.create_file(f"/data/.pytunes/{track_id}.0.m4a") | ||
|
||
response = client.get(f"/tracks/{track_id}.0.m4a") | ||
|
||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
from uuid import UUID | ||
from pytunes.util import sha1_to_uuid | ||
from unittest.mock import Mock | ||
from uuid import UUID, uuid4 | ||
|
||
from fastapi.datastructures import URL | ||
|
||
from pytunes import models | ||
from pytunes.util import sha1_to_uuid, track_to_playlist_item | ||
|
||
|
||
def test_sha1_to_uuid(): | ||
assert sha1_to_uuid("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33") == UUID( | ||
"0beec7b5-ea3f-0fdb-c95d-0dd47f3c5bc2" | ||
) | ||
|
||
|
||
def test_track_to_playlist_item(): | ||
track_id = uuid4() | ||
track_name = "foo" | ||
artist_name = "bar" | ||
track = models.Track( | ||
id=track_id, name=track_name, artists=[models.Artist(name=artist_name)] | ||
) | ||
track_url = f"http://testserver/tracks/{track_id}.m3u8" | ||
mock_request = Mock() | ||
mock_request.url_for = Mock(return_value=URL(track_url)) | ||
|
||
playlist_item = track_to_playlist_item(mock_request, track) | ||
|
||
assert playlist_item == "\n".join( | ||
[f"#EXTINF:-1,{artist_name} - {track_name}", track_url] | ||
) |