def test_accidental_overwrite_throws(self): ml = MediaLibrary() s = song(name="test") ml.add_song(s) self.assertRaises(media_library.AlreadyExistsException, lambda: ml.add_song(song(name="test"), expect_overwrite=False))
def test_to_from(self): ml = MediaLibrary() s1 = song() ml.add_song(s1) ml.create_playlist("test") ml.add_song_to_playlist(s1.alias, "test") self.assertEqual(MediaLibrary.from_primitive(ml.to_primitive()), ml)
def test_empty_to_primitive(self): ml = MediaLibrary() self.assertEqual( ml.to_primitive(), { media_library.VERSION_FIELD: MediaLibrary.VERSION, MediaLibrary.SONGS_FIELD: [], MediaLibrary.PLAYLIST_FIELD: {} })
def test_adding_multiple_songs(self): ml = MediaLibrary() s1 = song() s2 = song() ml.add_song(s1) ml.add_song(s2) self.assertDictEqual(ml.song_map, {s1.alias: s1, s2.alias: s2})
def test_get_playlist(self): ml = MediaLibrary() s = song() ml.create_playlist("test") ml.add_song(s) ml.add_song_to_playlist(s.alias, "test") self.assertListEqual(ml.get_playlist("test"), [s.alias])
def test_v1_parse(self): ml = MediaLibrary() s1 = song() ml.add_song(s1) ml.create_playlist("test") ml.add_song_to_playlist(s1.alias, "test") self.assertEqual(MediaLibrary.parse_v1({ media_library.VERSION_FIELD: 1.0, MediaLibrary.SONGS_FIELD: [s1.to_primitive()], MediaLibrary.PLAYLIST_FIELD: {"test": [s1.alias]}, }), ml)
def test_add_song(self): ml = MediaLibrary() s = song() ml.create_playlist("something") ml.add_song(s) ml.add_song_to_playlist(song_alias=s.alias, playlist_name="something") self.assertDictEqual(ml.playlists, {"something": [s.alias]})
def test_filled_library_to_primitive(self): ml = MediaLibrary() s1 = song() ml.add_song(s1) ml.create_playlist("test") ml.add_song_to_playlist(s1.alias, "test") self.assertEqual( ml.to_primitive(), { media_library.VERSION_FIELD: MediaLibrary.VERSION, MediaLibrary.SONGS_FIELD: [s1.to_primitive()], MediaLibrary.PLAYLIST_FIELD: {"test": [s1.alias]}, } )
def test_add_multiple_songs(self): ml = MediaLibrary() s1 = song() s2 = song() ml.create_playlist("test") ml.add_song(s1) ml.add_song(s2) ml.add_song_to_playlist(song_alias=s1.alias, playlist_name="test") ml.add_song_to_playlist(song_alias=s2.alias, playlist_name="test") self.assertDictEqual(ml.playlists, {"test": [s1.alias, s2.alias]})
def test_cant_add_song_directly(self): """Make sure users can't change playlists by getting them.""" ml = MediaLibrary() s = song() ml.create_playlist("test") ml.add_song(s) self.assertRaisesRegex(media_library.IllegalArgument, ".*Song{.*Song", lambda: ml.add_song_to_playlist(s, "test"))
def __init__(self, media_library: Optional[MediaLibrary] = None): if not media_library: media_library = MediaLibrary() self.media_library = media_library self.vlc_player = Player() self.devices = AudioDevices( vlc.libvlc_audio_output_device_enum(self.vlc_player.mp)) self.switch_oracle = oracles.SwitchOracle() self.queueing_oracle = oracles.ChainOracle() self.interrupt_oracle = oracles.InterruptOracle(self.switch_oracle) self.switch_oracle.set_oracle(self.queueing_oracle) self.vlc_player.play_oracle(self.interrupt_oracle)
def test_list_songs_with_songs_works(self): ml = MediaLibrary() s1 = song() s2 = song() s3 = song() ml.add_song(s1) ml.add_song(s2) ml.add_song(s3) self.assertListEqual(ml.list_songs(), [s1, s2, s3])
def test_multiple_playlists(self): ml = MediaLibrary() s1 = song() s2 = song() ml.add_song(s1) ml.add_song(s2) ml.create_playlist("test-1") ml.create_playlist("test-2") ml.add_song_to_playlist(s1.alias, "test-1") ml.add_song_to_playlist(s2.alias, "test-2") self.assertDictEqual(ml.playlists, {"test-1": [s1.alias], "test-2": [s2.alias]})
def test_overwrite_works_when_expected(self): ml = MediaLibrary() s1 = song(name="test") s2 = song(name="test") ml.add_song(s1) ml.add_song(s2, expect_overwrite=True) self.assertDictEqual(ml.song_map, {"test": s2})
def test_add_song(self): ml = MediaLibrary() s = song() ml.add_song(s) self.assertDictEqual(ml.song_map, {s.alias: s})
def __init__(self): self.ml = MediaLibrary() self.controller = Controller(self.ml) self.console = Console() self.console_output = self.console.start() self.media_server = v1_server.MediaServer(self.controller, self.ml)
def get_controller() -> Controller: ml = MediaLibrary() return Controller(ml)
def test_create_playlist(self): ml = MediaLibrary() ml.create_playlist("something") self.assertDictEqual(ml.playlists, {"something": []})
def test_adding_non_song_throws(self): ml = MediaLibrary() self.assertRaisesRegex(media_library.IllegalArgument, ".*'alias'.*'str'", lambda: ml.add_song("alias"))
def test_list_songs_without_songs_works(self): ml = MediaLibrary() self.assertListEqual(ml.list_songs(), [])
def test_checks_uri(self): ml = MediaLibrary() self.assertRaises(media_library.NotFoundException, lambda: ml.add_song(song(uri="C:\\something\\ invalid.mp3")))
def test_get_playlist_write_protected(self): """Make sure users can't change playlists by getting them.""" ml = MediaLibrary() s1 = song() s2 = song() ml.create_playlist("test") ml.add_song(s1) ml.add_song(s2) ml.add_song_to_playlist(s1.alias, "test") ml.get_playlist("test").append(s2.alias) self.assertListEqual(ml.get_playlist("test"), [s1.alias])
def test_song_missing(self): ml = MediaLibrary() s1 = song() ml.add_song(s1) ml.create_playlist("test") self.assertRaises(media_library.NotFoundException, lambda: ml.add_song_to_playlist("garbage", "test"))
def test_overwrite_erases_playlist(self): ml = MediaLibrary() s = song() ml.add_song(s) ml.create_playlist("test") ml.add_song_to_playlist(s.alias, "test") ml.create_playlist("test", expect_overwrite=True) self.assertListEqual(ml.get_playlist("test"), [])