-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests to cover protocol.album_art
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from io import BytesIO | ||
from mopidy_mpd.protocol import album_art | ||
from unittest import mock | ||
from mopidy.models import Album, Track, Image | ||
|
||
from tests import protocol | ||
|
||
|
||
def mock_get_images(self, uris): | ||
result = {} | ||
for uri in uris: | ||
result[uri] = [Image(uri="dummy:/albumart.jpg", width=128, height=128)] | ||
return result | ||
|
||
|
||
class AlbumArtTest(protocol.BaseTestCase): | ||
def test_albumart_for_track_without_art(self): | ||
track = Track( | ||
uri="dummy:/à", | ||
name="a nàme", | ||
album=Album(uri="something:àlbum:12345"), | ||
) | ||
self.backend.library.dummy_library = [track] | ||
self.core.tracklist.add(uris=[track.uri]).get() | ||
|
||
self.core.playback.play().get() | ||
|
||
self.send_request("albumart /home/test/music.flac 0") | ||
self.assertInResponse("binary: 0") | ||
|
||
@mock.patch.object( | ||
protocol.core.library.LibraryController, "get_images", mock_get_images | ||
) | ||
def test_albumart(self): | ||
track = Track( | ||
uri="dummy:/à", | ||
name="a nàme", | ||
album=Album(uri="something:àlbum:12345"), | ||
) | ||
self.backend.library.dummy_library = [track] | ||
self.core.tracklist.add(uris=[track.uri]).get() | ||
|
||
self.core.playback.play().get() | ||
|
||
## | ||
expected = b"result" | ||
|
||
with mock.patch.object( | ||
album_art, "urlopen", return_value=BytesIO(expected) | ||
): | ||
self.send_request("albumart /home/test/music.flac 0") | ||
|
||
self.assertInResponse("binary: " + str(len(expected))) |