def setupLibrary(self, file_count): """Add an album to the library with ``file_count`` items. """ album = Album(id=1) album.add(self.lib) fixture_glob = os.path.join(_common.RSRC, '*.mp3') for src in glob(fixture_glob)[0:file_count]: dst = os.path.join(self.libdir, os.path.basename(src)) shutil.copy(src, dst) item = Item.from_path(dst) item.album_id = 1 item.add(self.lib) self._reset_replaygain(item)
def setUp(self): super(WebPluginTest, self).setUp() # Add fixtures for track in self.lib.items(): track.remove() self.lib.add(Item(title=u'title', path='', id=1)) self.lib.add(Item(title=u'another title', path='', id=2)) self.lib.add(Album(album=u'album', id=3)) self.lib.add(Album(album=u'another album', id=4)) web.app.config['TESTING'] = True web.app.config['lib'] = self.lib self.client = web.app.test_client()
def test_delete_album_query_readonly(self): web.app.config['READONLY'] = True # Create a temporary album album_id = self.lib.add( Album(album='test_delete_album_query_ro', test_delete_album_query_ro=1)) # Check we can find the temporary album we just created response = self.client.get('/album/query/test_delete_album_query_ro') res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(len(res_json['results']), 1) # Try to delete album response = self.client.delete( '/album/query/test_delete_album_query_ro') self.assertEqual(response.status_code, 405) # Check the album has not gone response = self.client.get('/album/query/test_delete_album_query_ro') res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(len(res_json['results']), 1) # Remove it self.lib.get_album(album_id).remove()
def setUp(self): super(WebPluginTest, self).setUp() self.log = logging.getLogger('beets.web') if platform.system() == 'Windows': self.path_prefix = u'C:' else: self.path_prefix = u'' # Add fixtures for track in self.lib.items(): track.remove() # Add library elements. Note that self.lib.add overrides any "id=<n>" # and assigns the next free id number. # The following adds will create items #1, #2 and #3 path1 = self.path_prefix + os.sep + \ os.path.join(b'path_1').decode('utf-8') self.lib.add(Item(title=u'title', path=path1, album_id=2, artist='AAA Singers')) path2 = self.path_prefix + os.sep + \ os.path.join(b'somewhere', b'a').decode('utf-8') self.lib.add(Item(title=u'another title', path=path2, artist='AAA Singers')) path3 = self.path_prefix + os.sep + \ os.path.join(b'somewhere', b'abc').decode('utf-8') self.lib.add(Item(title=u'and a third', testattr='ABC', path=path3, album_id=2)) # The following adds will create albums #1 and #2 self.lib.add(Album(album=u'album', albumtest='xyz')) path4 = self.path_prefix + os.sep + \ os.path.join(b'somewhere2', b'art_path_2').decode('utf-8') self.lib.add(Album(album=u'other album', artpath=path4)) web.app.config['TESTING'] = True web.app.config['lib'] = self.lib web.app.config['INCLUDE_PATHS'] = False web.app.config['READONLY'] = True self.client = web.app.test_client()
def test_multi_format_album_playlist(self): config['importfeeds']['formats'] = 'm3u_multi' album = Album(album='album/name', id=1) item_path = os.path.join('path', 'to', 'item') item = Item(title='song', album_id=1, path=item_path) self.lib.add(album) self.lib.add(item) self.importfeeds.album_imported(self.lib, album) playlist_path = os.path.join(self.feeds_dir, os.listdir(self.feeds_dir)[0]) self.assertTrue(playlist_path.endswith('album_name.m3u')) with open(playlist_path) as playlist: self.assertIn(item_path, playlist.read())
def test_playlist_in_subdir(self): config['importfeeds']['formats'] = 'm3u' config['importfeeds']['m3u_name'] = 'subdir/imported.m3u' album = Album(album='album/name', id=1) item_path = os.path.join('path', 'to', 'item') item = Item(title='song', album_id=1, path=item_path) self.lib.add(album) self.lib.add(item) self.importfeeds.album_imported(self.lib, album) playlist = os.path.join(self.feeds_dir, config['importfeeds']['m3u_name'].get()) playlist_subdir = os.path.dirname(playlist) self.assertTrue(os.path.isdir(playlist_subdir)) self.assertTrue(os.path.isfile(playlist))
def test_delete_album_id(self): web.app.config['READONLY'] = False # Create a temporary album album_id = self.lib.add( Album(album='test_delete_album_id', test_delete_album_id=1)) # Check we can find the temporary album we just created response = self.client.get('/album/' + str(album_id)) res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(res_json['id'], album_id) # Delete album by id response = self.client.delete('/album/' + str(album_id)) res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) # Check the album has gone response = self.client.get('/album/' + str(album_id)) self.assertEqual(response.status_code, 404)
def test_delete_album_query(self): web.app.config['READONLY'] = False # Create a temporary album self.lib.add( Album(album='test_delete_album_query', test_delete_album_query=1)) # Check we can find the temporary album we just created response = self.client.get('/album/query/test_delete_album_query') res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(len(res_json['results']), 1) # Delete album response = self.client.delete('/album/query/test_delete_album_query') res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) # Check the album has gone response = self.client.get('/album/query/test_delete_album_query') res_json = json.loads(response.data.decode('utf-8')) self.assertEqual(response.status_code, 200) self.assertEqual(len(res_json['results']), 0)