def test_db_changes(self): spl = SmartPlaylistPlugin() nones = None, None pl1 = '1', (u'q1', None), nones pl2 = '2', (u'q2', None), nones pl3 = '3', (u'q3', None), nones spl._unmatched_playlists = set([pl1, pl2, pl3]) spl._matched_playlists = set() spl.matches = Mock(return_value=False) spl.db_change(None, u"nothing") self.assertEqual(spl._unmatched_playlists, set([pl1, pl2, pl3])) self.assertEqual(spl._matched_playlists, set()) spl.matches.side_effect = lambda _, q, __: q == u'q3' spl.db_change(None, u"matches 3") self.assertEqual(spl._unmatched_playlists, set([pl1, pl2])) self.assertEqual(spl._matched_playlists, set([pl3])) spl.matches.side_effect = lambda _, q, __: q == u'q1' spl.db_change(None, u"matches 3") self.assertEqual(spl._matched_playlists, set([pl1, pl3])) self.assertEqual(spl._unmatched_playlists, set([pl2]))
def test_playlist_update(self): spl = SmartPlaylistPlugin() i = Mock(path='/tagada.mp3') i.evaluate_template.side_effect = lambda x, _: x q = Mock() a_q = Mock() lib = Mock() lib.items.return_value = [i] lib.albums.return_value = [] pl = 'my_playlist.m3u', (q, None), (a_q, None) spl._matched_playlists = [pl] dir = mkdtemp() config['smartplaylist']['relative_to'] = False config['smartplaylist']['playlist_dir'] = dir try: spl.update_playlists(lib) except Exception: rmtree(dir) raise lib.items.assert_called_once_with(q, None) lib.albums.assert_called_once_with(a_q, None) m3u_filepath = path.join(dir, pl[0]) self.assertTrue(path.exists(m3u_filepath)) with open(syspath(m3u_filepath), 'r') as f: content = f.read() rmtree(dir) self.assertEqual(content, "/tagada.mp3\n")
def test_playlist_update(self): spl = SmartPlaylistPlugin() i = Mock(path=b'/tagada.mp3') i.evaluate_template.side_effect = lambda x, _: x q = Mock() a_q = Mock() lib = Mock() lib.items.return_value = [i] lib.albums.return_value = [] pl = b'my_playlist.m3u', (q, None), (a_q, None) spl._matched_playlists = [pl] dir = bytestring_path(mkdtemp()) config['smartplaylist']['relative_to'] = False config['smartplaylist']['playlist_dir'] = py3_path(dir) try: spl.update_playlists(lib) except Exception: rmtree(dir) raise lib.items.assert_called_once_with(q, None) lib.albums.assert_called_once_with(a_q, None) m3u_filepath = path.join(dir, pl[0]) self.assertTrue(path.exists(m3u_filepath)) with open(syspath(m3u_filepath), 'rb') as f: content = f.read() rmtree(dir) self.assertEqual(content, b'/tagada.mp3\n')
def test_db_changes(self): spl = SmartPlaylistPlugin() nones = None, None pl1 = '1', (u'q1', None), nones pl2 = '2', (u'q2', None), nones pl3 = '3', (u'q3', None), nones spl._unmatched_playlists = set([pl1, pl2, pl3]) spl._matched_playlists = set() spl.matches = Mock(return_value=False) spl.db_change(None, u"nothing") self.assertEqual(spl._unmatched_playlists, set([pl1, pl2, pl3])) self.assertEqual(spl._matched_playlists, set()) spl.matches.side_effect = lambda _, q, __: q == u'q3' spl.db_change(None, u"matches 3") self.assertEqual(spl._unmatched_playlists, set([pl1, pl2])) self.assertEqual(spl._matched_playlists, set([pl3])) spl.matches.side_effect = lambda _, q, __: q == u'q1' spl.db_change(None, u"matches 3") self.assertEqual(spl._matched_playlists, set([pl1, pl3])) self.assertEqual(spl._unmatched_playlists, set([pl2]))
def test_db_changes(self): spl = SmartPlaylistPlugin() i1 = MagicMock(Item) i2 = MagicMock(Item) a = MagicMock(Album) i1.get_album.return_value = a q1 = Mock() q1.matches.side_effect = {i1: False, i2: False}.__getitem__ a_q1 = Mock() a_q1.matches.side_effect = {a: True}.__getitem__ q2 = Mock() q2.matches.side_effect = {i1: False, i2: True}.__getitem__ pl1 = '1', (q1, None), (a_q1, None) pl2 = '2', (None, None), (a_q1, None) pl3 = '3', (q2, None), (None, None) spl._unmatched_playlists = set([pl1, pl2, pl3]) spl._matched_playlists = set() spl.db_change(None, i1) self.assertEqual(spl._unmatched_playlists, set([pl2])) self.assertEqual(spl._matched_playlists, set([pl1, pl3])) spl._unmatched_playlists = set([pl1, pl2, pl3]) spl._matched_playlists = set() spl.db_change(None, i2) self.assertEqual(spl._unmatched_playlists, set([pl2])) self.assertEqual(spl._matched_playlists, set([pl1, pl3])) spl._unmatched_playlists = set([pl1, pl2, pl3]) spl._matched_playlists = set() spl.db_change(None, a) self.assertEqual(spl._unmatched_playlists, set([pl3])) self.assertEqual(spl._matched_playlists, set([pl1, pl2])) spl.db_change(None, i2) self.assertEqual(spl._unmatched_playlists, set()) self.assertEqual(spl._matched_playlists, set([pl1, pl2, pl3]))
def test_playlist_update(self): spl = SmartPlaylistPlugin() i = Mock(path=b'/tagada.mp3') i.evaluate_template.side_effect = \ lambda pl, _: pl.replace(b'$title', b'ta:ga:da').decode() lib = Mock() lib.replacements = CHAR_REPLACE lib.items.return_value = [i] lib.albums.return_value = [] q = Mock() a_q = Mock() pl = b'$title-my<playlist>.m3u', (q, None), (a_q, None) spl._matched_playlists = [pl] dir = bytestring_path(mkdtemp()) config['smartplaylist']['relative_to'] = False config['smartplaylist']['playlist_dir'] = py3_path(dir) try: spl.update_playlists(lib) except Exception: rmtree(dir) raise lib.items.assert_called_once_with(q, None) lib.albums.assert_called_once_with(a_q, None) m3u_filepath = path.join(dir, b'ta_ga_da-my_playlist_.m3u') self.assertTrue(path.exists(m3u_filepath)) with open(syspath(m3u_filepath), 'rb') as f: content = f.read() rmtree(dir) self.assertEqual(content, b'/tagada.mp3\n')
def test_playlist_update(self): spl = SmartPlaylistPlugin() i = Mock(path=b'/tagada.mp3') i.evaluate_template.side_effect = \ lambda pl, _: pl.replace(b'$title', b'ta:ga:da').decode() lib = Mock() lib.replacements = CHAR_REPLACE lib.items.return_value = [i] lib.albums.return_value = [] q = Mock() a_q = Mock() pl = b'$title-my<playlist>.m3u', (q, None), (a_q, None) spl._matched_playlists = [pl] dir = bytestring_path(mkdtemp()) config['smartplaylist']['relative_to'] = False config['smartplaylist']['playlist_dir'] = py3_path(dir) try: spl.update_playlists(lib) except Exception: rmtree(dir) raise lib.items.assert_called_once_with(q, None) lib.albums.assert_called_once_with(a_q, None) m3u_filepath = path.join(dir, b'ta_ga_da-my_playlist_.m3u') self.assertTrue(path.exists(m3u_filepath)) with open(syspath(m3u_filepath), 'rb') as f: content = f.read() rmtree(dir) self.assertEqual(content, b'/tagada.mp3\n')