|
| 1 | +from collections.abc import Callable |
| 2 | +from datetime import timedelta |
| 3 | +from typing import Any |
| 4 | + |
| 5 | +from tests.mock_yncaconnection import YncaConnectionMock |
| 6 | +from ynca import Playback, PlaybackInfo, Repeat, Shuffle |
| 7 | +from ynca.subunits.deezer import Deezer |
| 8 | + |
| 9 | +SYS = "SYS" |
| 10 | +SUBUNIT = "DEEZER" |
| 11 | + |
| 12 | +INITIALIZE_FULL_RESPONSES = [ |
| 13 | + ( |
| 14 | + (SUBUNIT, "METAINFO"), |
| 15 | + [ |
| 16 | + (SUBUNIT, "ALBUM", "Album"), |
| 17 | + (SUBUNIT, "ARTIST", "Artist"), |
| 18 | + (SUBUNIT, "TRACK", "Track"), |
| 19 | + ], |
| 20 | + ), |
| 21 | + ( |
| 22 | + (SUBUNIT, "AVAIL"), |
| 23 | + [ |
| 24 | + (SUBUNIT, "AVAIL", "Ready"), |
| 25 | + ], |
| 26 | + ), |
| 27 | + ( |
| 28 | + (SUBUNIT, "ELAPSEDTIME"), |
| 29 | + [ |
| 30 | + (SUBUNIT, "ELAPSEDTIME", ""), |
| 31 | + ], |
| 32 | + ), |
| 33 | + ( |
| 34 | + (SUBUNIT, "PLAYBACKINFO"), |
| 35 | + [ |
| 36 | + (SUBUNIT, "PLAYBACKINFO", "Pause"), |
| 37 | + ], |
| 38 | + ), |
| 39 | + ( |
| 40 | + (SUBUNIT, "REPEAT"), |
| 41 | + [ |
| 42 | + (SUBUNIT, "REPEAT", "Single"), |
| 43 | + ], |
| 44 | + ), |
| 45 | + ( |
| 46 | + (SUBUNIT, "SHUFFLE"), |
| 47 | + [ |
| 48 | + (SUBUNIT, "SHUFFLE", "On"), |
| 49 | + ], |
| 50 | + ), |
| 51 | + ( |
| 52 | + (SUBUNIT, "TOTALTIME"), |
| 53 | + [ |
| 54 | + (SUBUNIT, "TOTALTIME", "1:23"), |
| 55 | + ], |
| 56 | + ), |
| 57 | + ( |
| 58 | + (SYS, "VERSION"), |
| 59 | + [ |
| 60 | + (SYS, "VERSION", "Version"), |
| 61 | + ], |
| 62 | + ), |
| 63 | +] |
| 64 | + |
| 65 | + |
| 66 | +def test_initialize( |
| 67 | + connection: YncaConnectionMock, update_callback: Callable[[str, Any], None] |
| 68 | +) -> None: |
| 69 | + connection.get_response_list = INITIALIZE_FULL_RESPONSES |
| 70 | + |
| 71 | + tidal = Deezer(connection) |
| 72 | + tidal.register_update_callback(update_callback) |
| 73 | + |
| 74 | + tidal.initialize() |
| 75 | + |
| 76 | + assert tidal.album == "Album" |
| 77 | + assert tidal.artist == "Artist" |
| 78 | + assert tidal.track == "Track" |
| 79 | + assert tidal.playbackinfo is PlaybackInfo.PAUSE |
| 80 | + assert tidal.repeat == Repeat.SINGLE |
| 81 | + assert tidal.shuffle == Shuffle.ON |
| 82 | + assert tidal.elapsedtime is None |
| 83 | + assert tidal.totaltime == timedelta(minutes=1, seconds=23) |
| 84 | + |
| 85 | + tidal.playback(Playback.PLAY) |
| 86 | + connection.put.assert_called_with(SUBUNIT, "PLAYBACK", "Play") |
0 commit comments