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_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_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"), [])
    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 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_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_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_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_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])
Esempio n. 10
0
    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]})
Esempio n. 11
0
    def test_create_playlist(self):
        ml = MediaLibrary()
        ml.create_playlist("something")

        self.assertDictEqual(ml.playlists, {"something": []})
Esempio n. 12
0
 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"))