Example #1
0
 def test_local_only_gets_fs_image(self):
     _common.touch(os.path.join(self.dpath, 'art.jpg'))
     album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN)
     artpath = fetchart.art_for_album(album, [self.dpath],
                                      None, local_only=True)
     self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
     self.assertEqual(len(responses.calls), 0)
Example #2
0
 def test_local_only_gets_fs_image(self):
     _common.touch(os.path.join(self.dpath, 'art.jpg'))
     album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN)
     artpath = self.plugin.art_for_album(album, [self.dpath],
                                         local_only=True)
     self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
     self.assertEqual(len(responses.calls), 0)
Example #3
0
 def test_main_interface_gives_precedence_to_fs_art(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     fetchart.urllib.urlretrieve = \
             MockUrlRetrieve('anotherpath', 'image/jpeg')
     album = AlbumInfo(None, None, None, None, None, asin='xxxx')
     artpath = fetchart.art_for_album(album, self.dpath)
     self.assertEqual(artpath, os.path.join(self.dpath, 'a.jpg'))
Example #4
0
    def test_removing_last_item_in_album_with_albumart_prunes_dir(self):
        artfile = os.path.join(self.temp_dir, 'testart.jpg')
        touch(artfile)
        self.ai.set_art(artfile)

        parent = os.path.dirname(self.i.path)
        self.lib.remove(self.i, True)
        self.assertNotExists(parent)
Example #5
0
    def test_removing_last_item_in_album_with_albumart_prunes_dir(self):
        artfile = os.path.join(self.temp_dir, 'testart.jpg')
        touch(artfile)
        self.ai.set_art(artfile)

        parent = os.path.dirname(self.i.path)
        self.lib.remove(self.i, True)
        self.assertNotExists(parent)
Example #6
0
    def setUp(self):
        super(SafeMoveCopyTest, self).setUp()

        self.path = os.path.join(self.temp_dir, 'testfile')
        touch(self.path)
        self.otherpath = os.path.join(self.temp_dir, 'testfile2')
        touch(self.otherpath)
        self.dest = self.path + '.dest'
Example #7
0
    def setUp(self):
        super(SafeMoveCopyTest, self).setUp()

        self.path = os.path.join(self.temp_dir, 'testfile')
        touch(self.path)
        self.otherpath = os.path.join(self.temp_dir, 'testfile2')
        touch(self.otherpath)
        self.dest = self.path + '.dest'
Example #8
0
 def test_local_only_gets_fs_image(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     mock_retrieve = MockUrlRetrieve('image/jpeg')
     fetchart.urllib.urlretrieve = mock_retrieve
     album = _common.Bag(mb_albumid='releaseid', asin='xxxx')
     artpath = fetchart.art_for_album(album, [self.dpath], local_only=True)
     self.assertEqual(artpath, os.path.join(self.dpath, 'a.jpg'))
     self.assertFalse(self.urlopen_called)
     self.assertFalse(mock_retrieve.fetched)
Example #9
0
 def test_local_only_gets_fs_image(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     mock_retrieve = MockUrlRetrieve('image/jpeg')
     fetchart.urllib.urlretrieve = mock_retrieve
     album = _common.Bag(mb_albumid='releaseid', asin='xxxx')
     artpath = fetchart.art_for_album(album, self.dpath, local_only=True)
     self.assertEqual(artpath, os.path.join(self.dpath, 'a.jpg'))
     self.assertFalse(self.urlopen_called)
     self.assertFalse(mock_retrieve.fetched)
Example #10
0
    def test_move_avoids_collision_with_existing_file(self):
        # Make a conflicting file at the destination.
        dest = self.lib.destination(self.i)
        os.makedirs(os.path.dirname(dest))
        touch(dest)

        self.lib.move(self.i)
        self.assertNotEqual(self.i.path, dest)
        self.assertEqual(os.path.dirname(self.i.path), os.path.dirname(dest))
Example #11
0
    def test_move_avoids_collision_with_existing_file(self):
        # Make a conflicting file at the destination.
        dest = self.lib.destination(self.i)
        os.makedirs(os.path.dirname(dest))
        touch(dest)

        self.lib.move(self.i)
        self.assertNotEqual(self.i.path, dest)
        self.assertEqual(os.path.dirname(self.i.path),
                         os.path.dirname(dest))
Example #12
0
 def setUp(self):
     # Make library and item.
     self.lib = beets.library.Library(':memory:')
     self.libdir = os.path.abspath(os.path.join(_common.RSRC, 'testlibdir'))
     self.lib.directory = self.libdir
     self.i = item()
     self.i.path = self.lib.destination(self.i)
     # Make a music file.
     util.mkdirall(self.i.path)
     touch(self.i.path)
     # Make an album with the item.
     self.ai = self.lib.add_album((self.i,))
Example #13
0
 def setUp(self):
     # Make library and item.
     self.lib = beets.library.Library(':memory:')
     self.libdir = os.path.abspath(os.path.join(_common.RSRC, 'testlibdir'))
     self.lib.directory = self.libdir
     self.i = item()
     self.i.path = self.lib.destination(self.i)
     # Make a music file.
     util.mkdirall(self.i.path)
     touch(self.i.path)
     # Make an album with the item.
     self.ai = self.lib.add_album((self.i, ))
Example #14
0
 def setUp(self):
     self.base = os.path.join(_common.RSRC, 'testdir')
     os.mkdir(self.base)
     touch(os.path.join(self.base, 'x.mp3'))
     touch(os.path.join(self.base, 'x.1.mp3'))
     touch(os.path.join(self.base, 'x.2.mp3'))
     touch(os.path.join(self.base, 'y.mp3'))
Example #15
0
    def setUp(self):
        super(RemoveTest, self).setUp()

        # Make library and item.
        self.lib = beets.library.Library(':memory:')
        self.libdir = os.path.abspath(os.path.join(self.temp_dir, 'testlibdir'))
        self.lib.directory = self.libdir
        self.i = item(self.lib)
        self.i.path = self.i.destination()
        # Make a music file.
        util.mkdirall(self.i.path)
        touch(self.i.path)
        # Make an album with the item.
        self.ai = self.lib.add_album((self.i,))
Example #16
0
    def test_setart_copies_image(self):
        os.remove(self.art)

        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2, ))
        self.lib.move(i2, True)

        self.assertEqual(ai.artpath, None)
        ai.set_art(newart)
        self.assertTrue(os.path.exists(ai.artpath))
Example #17
0
    def test_setart_copies_image(self):
        os.remove(self.art)

        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2,))
        self.lib.move(i2, True)
        
        self.assertEqual(ai.artpath, None)
        ai.set_art(newart)
        self.assertTrue(os.path.exists(ai.artpath))
Example #18
0
    def setUp(self):
        super(RemoveTest, self).setUp()

        # Make library and item.
        self.lib = beets.library.Library(':memory:')
        self.libdir = os.path.join(self.temp_dir, 'testlibdir')
        self.lib.directory = self.libdir
        self.i = item(self.lib)
        self.i.path = self.i.destination()
        # Make a music file.
        util.mkdirall(self.i.path)
        touch(self.i.path)
        # Make an album with the item.
        self.ai = self.lib.add_album((self.i,))
Example #19
0
 def setUp(self):
     self.base = os.path.join(_common.RSRC, 'testdir')
     os.mkdir(self.base)
     touch(os.path.join(self.base, 'x.mp3'))
     touch(os.path.join(self.base, 'x.1.mp3'))
     touch(os.path.join(self.base, 'x.2.mp3'))
     touch(os.path.join(self.base, 'y.mp3'))
Example #20
0
 def setUp(self):
     # Make library and item.
     self.lib = beets.library.Library(':memory:')
     self.lib.path_formats = \
         [('default', join('$albumartist', '$album', '$title'))]
     self.libdir = os.path.join(_common.RSRC, 'testlibdir')
     self.lib.directory = self.libdir
     self.i = item()
     # Make a file for the item.
     self.i.path = self.lib.destination(self.i)
     util.mkdirall(self.i.path)
     touch(self.i.path)
     # Make an album.
     self.ai = self.lib.add_album((self.i, ))
     # Alternate destination dir.
     self.otherdir = os.path.join(_common.RSRC, 'testotherdir')
Example #21
0
    def test_setart_to_existing_art_works(self):
        os.remove(self.art)

        # Original art.
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2, ))
        self.lib.move(i2, True)
        ai.set_art(newart)

        # Set the art again.
        ai.set_art(ai.artpath)
        self.assertTrue(os.path.exists(ai.artpath))
Example #22
0
    def test_setart_to_existing_but_unset_art_works(self):
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2, ))
        self.lib.move(i2, True)

        # Copy the art to the destination.
        artdest = ai.art_destination(newart)
        shutil.copy(newart, artdest)

        # Set the art again.
        ai.set_art(artdest)
        self.assertTrue(os.path.exists(ai.artpath))
Example #23
0
 def setUp(self):
     # Make library and item.
     self.lib = beets.library.Library(':memory:')
     self.lib.path_formats = \
         [('default', join('$albumartist', '$album', '$title'))]
     self.libdir = os.path.join(_common.RSRC, 'testlibdir')
     self.lib.directory = self.libdir
     self.i = item()
     # Make a file for the item.
     self.i.path = self.lib.destination(self.i)
     util.mkdirall(self.i.path)
     touch(self.i.path)
     # Make an album.
     self.ai = self.lib.add_album((self.i,))
     # Alternate destination dir.
     self.otherdir = os.path.join(_common.RSRC, 'testotherdir')
Example #24
0
    def test_setart_to_existing_but_unset_art_works(self):
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2,))
        self.lib.move(i2, True)

        # Copy the art to the destination.
        artdest = ai.art_destination(newart)
        shutil.copy(newart, artdest)

        # Set the art again.
        ai.set_art(artdest)
        self.assertTrue(os.path.exists(ai.artpath))
Example #25
0
    def test_setart_to_existing_art_works(self):
        os.remove(self.art)

        # Original art.
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2,))
        self.lib.move(i2, True)
        ai.set_art(newart)

        # Set the art again.
        ai.set_art(ai.artpath)
        self.assertTrue(os.path.exists(ai.artpath))
Example #26
0
    def setUp(self):
        super(UniquePathTest, self).setUp()

        self.base = os.path.join(self.temp_dir, 'testdir')
        os.mkdir(self.base)
        touch(os.path.join(self.base, 'x.mp3'))
        touch(os.path.join(self.base, 'x.1.mp3'))
        touch(os.path.join(self.base, 'x.2.mp3'))
        touch(os.path.join(self.base, 'y.mp3'))
Example #27
0
    def setUp(self):
        super(UniquePathTest, self).setUp()

        self.base = os.path.join(self.temp_dir, 'testdir')
        os.mkdir(self.base)
        touch(os.path.join(self.base, 'x.mp3'))
        touch(os.path.join(self.base, 'x.1.mp3'))
        touch(os.path.join(self.base, 'x.2.mp3'))
        touch(os.path.join(self.base, 'y.mp3'))
Example #28
0
    def test_setart_to_conflicting_file_gets_new_path(self):
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2, ))
        self.lib.move(i2, True)

        # Make a file at the destination.
        artdest = ai.art_destination(newart)
        touch(artdest)

        # Set the art.
        ai.set_art(newart)
        self.assertNotEqual(artdest, ai.artpath)
        self.assertEqual(os.path.dirname(artdest), os.path.dirname(ai.artpath))
Example #29
0
 def setUp(self):
     # Make library and item.
     self.lib = beets.library.Library(':memory:')
     self.libdir = os.path.abspath(os.path.join(_common.RSRC, 'testlibdir'))
     self.lib.directory = self.libdir
     self.i = item()
     self.i.path = self.lib.destination(self.i)
     # Make a music file.
     util.mkdirall(self.i.path)
     touch(self.i.path)
     # Make an album.
     self.ai = self.lib.add_album((self.i,))
     # Make an art file too.
     self.art = self.lib.get_album(self.i).art_destination('something.jpg')
     touch(self.art)
     self.ai.artpath = self.art
     # Alternate destination dir.
     self.otherdir = os.path.join(_common.RSRC, 'testotherdir')
Example #30
0
    def setUp(self):
        super(UpdateTest, self).setUp()

        self.io.install()

        self.libdir = os.path.join(self.temp_dir, "testlibdir")

        # Copy a file into the library.
        self.lib = library.Library(":memory:", self.libdir)
        self.i = library.Item.from_path(os.path.join(_common.RSRC, "full.mp3"))
        self.lib.add(self.i, True)
        self.album = self.lib.add_album([self.i])

        # Album art.
        artfile = os.path.join(_common.RSRC, "testart.jpg")
        _common.touch(artfile)
        self.album.set_art(artfile)
        os.remove(artfile)
Example #31
0
    def setUp(self):
        self.io = _common.DummyIO()
        self.io.install()

        self.libdir = os.path.join(_common.RSRC, 'testlibdir')
        os.mkdir(self.libdir)

        # Copy a file into the library.
        self.lib = library.Library(':memory:', self.libdir)
        self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3'))
        self.lib.add(self.i, True)
        self.album = self.lib.add_album([self.i])

        # Album art.
        artfile = os.path.join(_common.RSRC, 'testart.jpg')
        _common.touch(artfile)
        self.album.set_art(artfile)
        os.remove(artfile)
Example #32
0
    def setUp(self):
        self.io = _common.DummyIO()
        self.io.install()

        self.libdir = os.path.join(_common.RSRC, 'testlibdir')
        os.mkdir(self.libdir)

        # Copy a file into the library.
        self.lib = library.Library(':memory:', self.libdir)
        self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3'))
        self.lib.add(self.i, True)
        self.album = self.lib.add_album([self.i])

        # Album art.
        artfile = os.path.join(_common.RSRC, 'testart.jpg')
        _common.touch(artfile)
        self.album.set_art(artfile)
        os.remove(artfile)
Example #33
0
    def test_setart_to_conflicting_file_gets_new_path(self):
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = 'someArtist'
        ai = self.lib.add_album((i2,))
        self.lib.move(i2, True)

        # Make a file at the destination.
        artdest = ai.art_destination(newart)
        touch(artdest)

        # Set the art.
        ai.set_art(newart)
        self.assertNotEqual(artdest, ai.artpath)
        self.assertEqual(os.path.dirname(artdest),
                         os.path.dirname(ai.artpath))
Example #34
0
 def setUp(self):
     # Make library and item.
     self.lib = beets.library.Library(':memory:')
     self.libdir = os.path.abspath(os.path.join(_common.RSRC, 'testlibdir'))
     self.lib.directory = self.libdir
     self.i = item()
     self.i.path = self.lib.destination(self.i)
     # Make a music file.
     util.mkdirall(self.i.path)
     touch(self.i.path)
     # Make an album.
     self.ai = self.lib.add_album((self.i, ))
     # Make an art file too.
     self.art = self.lib.get_album(self.i).art_destination('something.jpg')
     touch(self.art)
     self.ai.artpath = self.art
     # Alternate destination dir.
     self.otherdir = os.path.join(_common.RSRC, 'testotherdir')
Example #35
0
    def setUp(self):
        super(ArtImporterTest, self).setUp()

        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(self.temp_dir, 'tmpcover.jpg')
        _common.touch(self.art_file)
        self.old_afa = fetchart.art_for_album
        self.afa_response = self.art_file

        def art_for_album(i, p, maxwidth=None, local_only=False):
            return self.afa_response

        fetchart.art_for_album = art_for_album

        # Test library.
        self.libpath = os.path.join(self.temp_dir, 'tmplib.blb')
        self.libdir = os.path.join(self.temp_dir, 'tmplib')
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, 'album'))
        itempath = os.path.join(self.libdir, 'album', 'test.mp3')
        shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib._connection().commit()

        # The plugin and import configuration.
        self.plugin = fetchart.FetchArtPlugin()
        self.session = _common.import_session(self.lib)

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album = self.album
        info = AlbumInfo(
            album='some album',
            album_id='albumid',
            artist='some artist',
            artist_id='artistid',
            tracks=[],
        )
        self.task.set_choice(AlbumMatch(0, info, {}, set(), set()))
Example #36
0
    def setUp(self):
        super(UpdateTest, self).setUp()

        self.io.install()

        self.libdir = os.path.join(self.temp_dir, 'testlibdir')

        # Copy a file into the library.
        self.lib = library.Library(':memory:', self.libdir)
        self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3'))
        self.lib.add(self.i, True)
        self.album = self.lib.add_album([self.i])

        # Album art.
        artfile = os.path.join(_common.RSRC, 'testart.jpg')
        _common.touch(artfile)
        self.album.set_art(artfile)
        self.album.store()
        os.remove(artfile)
Example #37
0
    def setUp(self):
        super(ArtImporterTest, self).setUp()

        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(self.temp_dir, 'tmpcover.jpg')
        _common.touch(self.art_file)
        self.old_afa = fetchart.art_for_album
        self.afa_response = self.art_file

        def art_for_album(i, p, maxwidth=None, local_only=False):
            return self.afa_response

        fetchart.art_for_album = art_for_album

        # Test library.
        self.libpath = os.path.join(self.temp_dir, 'tmplib.blb')
        self.libdir = os.path.join(self.temp_dir, 'tmplib')
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, 'album'))
        itempath = os.path.join(self.libdir, 'album', 'test.mp3')
        shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib._connection().commit()

        # The plugin and import configuration.
        self.plugin = fetchart.FetchArtPlugin()
        self.session = _common.import_session(self.lib)

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album = self.album
        info = AlbumInfo(
            album='some album',
            album_id='albumid',
            artist='some artist',
            artist_id='artistid',
            tracks=[],
        )
        self.task.set_choice(AlbumMatch(0, info, {}, set(), set()))
Example #38
0
    def setUp(self):
        super(UpdateTest, self).setUp()

        self.io.install()

        self.libdir = os.path.join(self.temp_dir, 'testlibdir')

        # Copy a file into the library.
        self.lib = library.Library(':memory:', self.libdir)
        self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3'))
        self.lib.add(self.i)
        self.i.move(True)
        self.album = self.lib.add_album([self.i])

        # Album art.
        artfile = os.path.join(self.temp_dir, 'testart.jpg')
        _common.touch(artfile)
        self.album.set_art(artfile)
        self.album.store()
        os.remove(artfile)
Example #39
0
    def setUp(self):
        super(ArtFileTest, self).setUp()

        # Make library and item.
        self.lib = beets.library.Library(':memory:')
        self.libdir = os.path.join(self.temp_dir, 'testlibdir')
        self.lib.directory = self.libdir
        self.i = item(self.lib)
        self.i.path = self.i.destination()
        # Make a music file.
        util.mkdirall(self.i.path)
        touch(self.i.path)
        # Make an album.
        self.ai = self.lib.add_album((self.i,))
        # Make an art file too.
        self.art = self.lib.get_album(self.i).art_destination('something.jpg')
        touch(self.art)
        self.ai.artpath = self.art
        self.ai.store()
        # Alternate destination dir.
        self.otherdir = os.path.join(self.temp_dir, 'testotherdir')
Example #40
0
 def setUp(self):
     self.base = os.path.join(_common.RSRC, 'testdir')
     os.mkdir(self.base)
     touch(os.path.join(self.base, 'y'))
     touch(os.path.join(self.base, 'x'))
     os.mkdir(os.path.join(self.base, 'd'))
     touch(os.path.join(self.base, 'd', 'z'))
Example #41
0
 def test_precedence_amongst_correct_files(self):
     _common.touch(os.path.join(self.dpath, 'back.jpg'))
     _common.touch(os.path.join(self.dpath, 'front.jpg'))
     _common.touch(os.path.join(self.dpath, 'front-cover.jpg'))
     fn = fetchart.art_in_path(self.dpath,
                               ('cover', 'front', 'back'), False)
     self.assertEqual(fn, os.path.join(self.dpath, 'front-cover.jpg'))
Example #42
0
 def setUp(self):
     self.base = os.path.join(_common.RSRC, 'testdir')
     os.mkdir(self.base)
     touch(os.path.join(self.base, 'y'))
     touch(os.path.join(self.base, 'x'))
     os.mkdir(os.path.join(self.base, 'd'))
     touch(os.path.join(self.base, 'd', 'z'))
Example #43
0
 def test_precedence_amongst_correct_files(self):
     _common.touch(os.path.join(self.dpath, 'back.jpg'))
     _common.touch(os.path.join(self.dpath, 'front.jpg'))
     _common.touch(os.path.join(self.dpath, 'front-cover.jpg'))
     fn = fetchart.art_in_path(self.dpath, ('cover', 'front', 'back'),
                               False)
     self.assertEqual(fn, os.path.join(self.dpath, 'front-cover.jpg'))
Example #44
0
    def setUp(self):
        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(_common.RSRC, 'tmpcover.jpg')
        _common.touch(self.art_file)
        self.old_afa = art.art_for_album
        art.art_for_album = lambda a, b: self.art_file

        # Test library.
        self.libpath = os.path.join(_common.RSRC, 'tmplib.blb')
        self.libdir = os.path.join(_common.RSRC, 'tmplib')
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, 'album'))
        itempath = os.path.join(self.libdir, 'album', 'test.mp3')
        shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib._connection().commit()

        # Set up an art-fetching coroutine.
        self.config = _common.iconfig(self.lib)
        self.config.art = True
        self.coro = importer.fetch_art(self.config)
        self.coro.next()

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album_id = self.album.id
        info = AlbumInfo(
            album = 'some album',
            album_id = 'albumid',
            artist = 'some artist',
            artist_id = 'artistid',
            tracks = [TrackInfo('one',  'trackid', 'some artist',
                                'artistid', 1)],
        )
        self.task.set_choice((info, [self.i]))
Example #45
0
    def setUp(self):
        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(_common.RSRC, 'tmpcover.jpg')
        _common.touch(self.art_file)
        self.old_afa = art.art_for_album
        art.art_for_album = lambda a, b: self.art_file

        # Test library.
        self.libpath = os.path.join(_common.RSRC, 'tmplib.blb')
        self.libdir = os.path.join(_common.RSRC, 'tmplib')
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, 'album'))
        itempath = os.path.join(self.libdir, 'album', 'test.mp3')
        shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib.save()

        # Set up an art-fetching coroutine.
        self.config = _common.iconfig(self.lib)
        self.config.art = True
        self.coro = importer.fetch_art(self.config)
        self.coro.next()

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album_id = self.album.id
        info = AlbumInfo(
            album='some album',
            album_id='albumid',
            artist='some artist',
            artist_id='artistid',
            tracks=[TrackInfo('one', 'trackid', 'some artist', 'artistid', 1)],
        )
        self.task.set_choice((info, [self.i]))
Example #46
0
    def setUp(self):
        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(_common.RSRC, "tmpcover.jpg")
        _common.touch(self.art_file)
        self.old_afa = art.art_for_album
        art.art_for_album = lambda a, b: self.art_file

        # Test library.
        self.libpath = os.path.join(_common.RSRC, "tmplib.blb")
        self.libdir = os.path.join(_common.RSRC, "tmplib")
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, "album"))
        itempath = os.path.join(self.libdir, "album", "test.mp3")
        shutil.copyfile(os.path.join(_common.RSRC, "full.mp3"), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib.save()

        # Set up an art-fetching coroutine.
        self.config = _common.iconfig(self.lib)
        self.config.art = True
        self.coro = importer.fetch_art(self.config)
        self.coro.next()

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album_id = self.album.id
        info = AlbumInfo(
            album="some album",
            album_id="albumid",
            artist="some artist",
            artist_id="artistid",
            tracks=[TrackInfo("one", "trackid", "some artist", "artistid", 1)],
        )
        self.task.set_choice((info, [self.i]))
Example #47
0
    def test_setart_sets_permissions(self):
        os.remove(self.art)

        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        os.chmod(newart, 0400)  # read-only

        try:
            i2 = item()
            i2.path = self.i.path
            i2.artist = 'someArtist'
            ai = self.lib.add_album((i2, ))
            self.lib.move(i2, True)
            ai.set_art(newart)

            mode = stat.S_IMODE(os.stat(ai.artpath).st_mode)
            self.assertTrue(mode & stat.S_IRGRP)
            self.assertTrue(os.access(ai.artpath, os.W_OK))

        finally:
            # Make everything writable so it can be cleaned up.
            os.chmod(newart, 0777)
            os.chmod(ai.artpath, 0777)
Example #48
0
    def test_setart_sets_permissions(self):
        os.remove(self.art)

        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        os.chmod(newart, 0400) # read-only
        
        try:
            i2 = item()
            i2.path = self.i.path
            i2.artist = 'someArtist'
            ai = self.lib.add_album((i2,))
            self.lib.move(i2, True)
            ai.set_art(newart)
            
            mode = stat.S_IMODE(os.stat(ai.artpath).st_mode)
            self.assertTrue(mode & stat.S_IRGRP)
            self.assertTrue(os.access(ai.artpath, os.W_OK))
            
        finally:
            # Make everything writable so it can be cleaned up.
            os.chmod(newart, 0777)
            os.chmod(ai.artpath, 0777)
Example #49
0
    def setUp(self):
        super(WalkTest, self).setUp()

        self.base = os.path.join(self.temp_dir, 'testdir')
        os.mkdir(self.base)
        touch(os.path.join(self.base, 'y'))
        touch(os.path.join(self.base, 'x'))
        os.mkdir(os.path.join(self.base, 'd'))
        touch(os.path.join(self.base, 'd', 'z'))
Example #50
0
    def setUp(self):
        super(WalkTest, self).setUp()

        self.base = os.path.join(self.temp_dir, 'testdir')
        os.mkdir(self.base)
        touch(os.path.join(self.base, 'y'))
        touch(os.path.join(self.base, 'x'))
        os.mkdir(os.path.join(self.base, 'd'))
        touch(os.path.join(self.base, 'd', 'z'))
Example #51
0
 def test_appropriately_named_file_takes_precedence(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     _common.touch(os.path.join(self.dpath, 'cover.jpg'))
     fn = fetchart.art_in_path(self.dpath)
     self.assertEqual(fn, os.path.join(self.dpath, 'cover.jpg'))
Example #52
0
 def test_removing_last_item_prunes_dir_with_blacklisted_file(self):
     parent = os.path.dirname(self.i.path)
     touch(os.path.join(parent, '.DS_Store'))
     self.lib.remove(self.i, True)
     self.assertNotExists(parent)
Example #53
0
 def setUp(self):
     self.path = os.path.join(_common.RSRC, 'testfile')
     touch(self.path)
     self.otherpath = os.path.join(_common.RSRC, 'testfile2')
     touch(self.otherpath)
     self.dest = self.path + '.dest'
Example #54
0
 def setUp(self):
     self.path = os.path.join(_common.RSRC, 'testfile')
     touch(self.path)
Example #55
0
 def test_removing_last_item_prunes_dir_with_blacklisted_file(self):
     parent = os.path.dirname(self.i.path)
     touch(os.path.join(parent, '.DS_Store'))
     self.lib.remove(self.i, True)
     self.assertNotExists(parent)
Example #56
0
 def test_removing_last_item_preserves_nonempty_dir(self):
     parent = os.path.dirname(self.i.path)
     touch(os.path.join(parent, 'dummy.txt'))
     self.lib.remove(self.i, True)
     self.assertExists(parent)
Example #57
0
 def setUp(self):
     self.path = os.path.join(_common.RSRC, 'testfile')
     touch(self.path)
Example #58
0
 def setUp(self):
     self.path = os.path.join(_common.RSRC, 'testfile')
     touch(self.path)
     self.otherpath = os.path.join(_common.RSRC, 'testfile2')
     touch(self.otherpath)
     self.dest = self.path + '.dest'
Example #59
0
 def test_non_image_file_not_identified(self):
     _common.touch(os.path.join(self.dpath, 'a.txt'))
     fn = fetchart.art_in_path(self.dpath)
     self.assertEqual(fn, None)