|
| 1 | +from io import BytesIO |
| 2 | +from mopidy_mpd.protocol import album_art |
| 3 | +from unittest import mock |
| 4 | +from mopidy.models import Album, Track, Image |
| 5 | + |
| 6 | +from tests import protocol |
| 7 | + |
| 8 | + |
| 9 | +def mock_get_images(self, uris): |
| 10 | + result = {} |
| 11 | + for uri in uris: |
| 12 | + result[uri] = [Image(uri="dummy:/albumart.jpg", width=128, height=128)] |
| 13 | + return result |
| 14 | + |
| 15 | + |
| 16 | +class AlbumArtTest(protocol.BaseTestCase): |
| 17 | + def test_albumart_for_track_without_art(self): |
| 18 | + track = Track( |
| 19 | + uri="dummy:/à", |
| 20 | + name="a nàme", |
| 21 | + album=Album(uri="something:àlbum:12345"), |
| 22 | + ) |
| 23 | + self.backend.library.dummy_library = [track] |
| 24 | + self.core.tracklist.add(uris=[track.uri]).get() |
| 25 | + |
| 26 | + self.core.playback.play().get() |
| 27 | + |
| 28 | + self.send_request("albumart /home/test/music.flac 0") |
| 29 | + self.assertInResponse("binary: 0") |
| 30 | + |
| 31 | + @mock.patch.object( |
| 32 | + protocol.core.library.LibraryController, "get_images", mock_get_images |
| 33 | + ) |
| 34 | + def test_albumart(self): |
| 35 | + track = Track( |
| 36 | + uri="dummy:/à", |
| 37 | + name="a nàme", |
| 38 | + album=Album(uri="something:àlbum:12345"), |
| 39 | + ) |
| 40 | + self.backend.library.dummy_library = [track] |
| 41 | + self.core.tracklist.add(uris=[track.uri]).get() |
| 42 | + |
| 43 | + self.core.playback.play().get() |
| 44 | + |
| 45 | + ## |
| 46 | + expected = b"result" |
| 47 | + |
| 48 | + with mock.patch.object( |
| 49 | + album_art, "urlopen", return_value=BytesIO(expected) |
| 50 | + ): |
| 51 | + self.send_request("albumart /home/test/music.flac 0") |
| 52 | + |
| 53 | + self.assertInResponse("binary: " + str(len(expected))) |
0 commit comments