Skip to content

Commit

Permalink
Added unit tests to cover protocol.album_art
Browse files Browse the repository at this point in the history
  • Loading branch information
leso-kn committed Aug 19, 2022
1 parent 9911dca commit be4776c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/protocol/test_albumart.py
@@ -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)))

0 comments on commit be4776c

Please sign in to comment.