Example #1
0
def test_default_values():

    config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))

    assert config.getboolean("details", "keep_original")
    assert not config.getboolean("details", "use_style")
    assert config.getboolean("details", "use_lower_filenames")

    assert config.get("file-formatting", "image") == "image"
def test_default_values():

    config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))

    assert config.getboolean("details", "keep_original")
    assert not config.getboolean("details", "use_style")
    assert config.getboolean("details", "use_lower_filenames")

    assert config.get("file-formatting", "image") == "image"
Example #3
0
def test_overload_config():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == None

    config.read(os.path.join(parentdir, "test/track_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == "myself"
Example #4
0
def test_set_values():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert not config.getboolean("details", "keep_original")
    assert config.getboolean("details", "use_style")

    assert config.get("file-formatting", "image") == "XXIMGXX"

    # not overwritten value should stay the same
    assert config.getboolean("details", "use_lower_filenames")
def test_overload_config():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == None

    config.read(os.path.join(parentdir, "test/track_values.conf"))

    assert config.getboolean("details", "use_style")
    assert config.get("tags", "encoder") == "myself"
def test_set_values():

    config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

    assert not config.getboolean("details", "keep_original")
    assert config.getboolean("details", "use_style")

    assert config.get("file-formatting", "image") == "XXIMGXX"

    # not overwritten value should stay the same
    assert config.getboolean("details", "use_lower_filenames")
class TestFileHandler(TestTaggerUtilFiles):

    def setUp(self):
        TestTaggerUtilFiles.setUp(self)
        self.target_file_name = "test.flac"

    def tearDown(self):
        TestTaggerUtilFiles.tearDown(self)
        self.tagger_config = None

    def test_remove_source_dir(self):
        self.album.sourcedir = self.source_dir

        assert self.tagger_config.getboolean("details", "keep_original")

        testFileHandler = FileHandler(self.album, self.tagger_config)

        target_file = os.path.join(self.album.sourcedir, "id.txt")
        shutil.copyfile(self.source_copy_file, target_file)

        assert os.path.exists(target_file)

        testFileHandler.remove_source_dir()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(target_file)

        # construct config with only default values
        self.tagger_config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

        assert not self.tagger_config.getboolean("details", "keep_original")

        testFileHandler = FileHandler(self.album, self.tagger_config)

        assert os.path.exists(target_file)

        testFileHandler.remove_source_dir()

        assert not os.path.exists(self.album.sourcedir)
        assert not os.path.exists(target_file)

    def test_copy_files(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler.copy_files()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(self.album.target_dir)

        disc_dir = os.path.join(self.album.target_dir, self.album.disc(1).target_dir)
        assert os.path.exists(disc_dir)

        disc_dir = os.path.join(self.album.target_dir, self.album.disc(2).target_dir)
        assert os.path.exists(disc_dir)

        track_file = os.path.join(self.album.target_dir,
            self.album.disc(1).target_dir, self.album.disc(1).track(1).new_file)
        assert os.path.exists(track_file)

        track_file = os.path.join(self.album.target_dir,
            self.album.disc(1).target_dir, self.album.disc(1).track(20).new_file)
        assert os.path.exists(track_file)

        track_file = os.path.join(self.album.target_dir,
            self.album.disc(2).target_dir, self.album.disc(2).track(1).new_file)
        assert os.path.exists(track_file)

        track_file = os.path.join(self.album.target_dir,
            self.album.disc(2).target_dir, self.album.disc(2).track(20).new_file)
        assert os.path.exists(track_file)

    def test_embed_coverart_track(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler.copy_files()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(self.album.target_dir)

        track = self.album.disc(1).track(1)
        track_file = os.path.join(self.album.target_dir,
            self.album.disc(1).target_dir, track.new_file)

        source_file = "test/files/cover.jpeg"
        target_dir = os.path.join(self.album.target_dir, self.album.disc(1).target_dir)
        image_file = os.path.join(target_dir, "cover.jpeg")
        shutil.copyfile(source_file, image_file)
        imgdata = open(image_file).read()

        testFileHandler.embed_coverart_track(self.album.disc(1), track, imgdata)

        assert os.path.exists(track_file)

        metadata = MediaFile(track_file)

        assert not metadata.art == None

        track = self.album.disc(1).track(2)
        track_file = os.path.join(self.album.target_dir,
            self.album.disc(1).target_dir, track.new_file)
        metadata = MediaFile(track_file)

        assert metadata.art == None

    def test_embed_coverart_album(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler.copy_files()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(self.album.target_dir)

        source_file = "test/files/cover.jpeg"
        image_file = os.path.join(self.album.target_dir, "folder.jpg")
        shutil.copyfile(source_file, image_file)

        testFileHandler.embed_coverart_album()

        track = self.album.disc(1).track(1)
        track_file = os.path.join(self.album.target_dir,
            self.album.disc(1).target_dir, track.new_file)
        metadata = MediaFile(track_file)

        assert not metadata.art == None

    def test_copy_other_files(self):
        assert not self.tagger_config.getboolean("details", "copy_other_files")

        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler = FileHandler(self.album, self.tagger_config)

        testFileHandler.copy_other_files()

        album_target_dir = self.album.target_dir
        assert not os.path.exists(os.path.join(album_target_dir, "id.txt"))

        disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir)
        assert not os.path.exists(os.path.join(disc_target_dir, "album.cue"))

        disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir)
        assert not os.path.exists(os.path.join(disc_target_dir, "album.cue"))

        # construct config with only default values
        self.tagger_config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

        assert self.tagger_config.getboolean("details", "copy_other_files")

        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testFileHandler.copy_other_files()

        album_target_dir = self.album.target_dir
        logger.debug("album_target_dir: %s" % album_target_dir)
        assert os.path.exists(os.path.join(album_target_dir, "id.txt"))

        disc_target_dir = os.path.join(album_target_dir, self.album.disc(1).target_dir)
        assert os.path.exists(os.path.join(disc_target_dir, "album.cue"))

        disc_target_dir = os.path.join(album_target_dir, self.album.disc(2).target_dir)
        assert os.path.exists(os.path.join(disc_target_dir, "album.cue"))

    def test_create_done_file(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album)

        self.copy_files(self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        assert not os.path.exists(os.path.join(self.album.sourcedir, "dt.done"))

        testFileHandler.create_done_file()

        assert os.path.exists(os.path.join(self.album.sourcedir, "dt.done"))

    def test_get_images(self):
        """ It downloads only one image, since this is the default configuration
            This test needs network connection, as well as authentication support
        """
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, self.tagger_config, self.album)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        # the following stuff is only needed in the test, since we cannot use
        # a config option for these values ;-(
        # we are unfortunately treated to login every time this method is called ;-(

        consumer_key = None
        consumer_secret = None

        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_KEY"):
            consumer_key = os.environ.get('TRAVIS_DISCOGS_CONSUMER_KEY')
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_SECRET"):
            consumer_secret = os.environ.get("TRAVIS_DISCOGS_CONSUMER_SECRET")

        config = self.tagger_config
        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        discogs_connection = DiscogsConnector(config)
        testFileHandler = FileHandler(self.album, config)
        testFileHandler.get_images(discogs_connection)

        onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f))]
        logger.debug("files: %s " % onlyfiles)

        assert os.path.exists(os.path.join(self.album.target_dir, "folder.jpg"))
        assert not os.path.exists(os.path.join(self.album.target_dir, "image-01.jpg"))

    def test_get_images_wo_folderjpg(self):
        """ Downloads several images from discogs, using authentication
            This test needs network connection, as well as authentication support
        """
        # construct config with only default values
        config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, config, self.album)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        # the following stuff is only needed in the test, since we cannot use
        # a config option for these values ;-(
        # we are unfortunately treated to login every time this method is called ;-(

        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_KEY"):
            consumer_key = os.environ.get('TRAVIS_DISCOGS_CONSUMER_KEY')
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_SECRET"):
            consumer_secret = os.environ.get("TRAVIS_DISCOGS_CONSUMER_SECRET")

        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        discogs_connection = DiscogsConnector(config)
        testFileHandler = FileHandler(self.album, config)
        testFileHandler.get_images(discogs_connection)

        onlyfiles = [ f for f in listdir(self.album.target_dir) if isfile(join(self.album.target_dir, f))]
        logger.debug("files: %s " % onlyfiles)

        logger.debug('checking %s' % self.album.target_dir)

        assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-01.jpg"))
        assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-02.jpg"))
        assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-03.jpg"))
        assert os.path.exists(os.path.join(self.album.target_dir, "XXIMGXX-04.jpg"))

    test_get_images.needs_network = True
    test_get_images.needs_authentication = True
    test_get_images_wo_folderjpg.needs_network = True
    test_get_images_wo_folderjpg.needs_authentication = True
Example #8
0
class TestFileHandler(TestTaggerUtilFiles):
    def setUp(self):
        TestTaggerUtilFiles.setUp(self)
        self.target_file_name = "test.flac"

    def tearDown(self):
        TestTaggerUtilFiles.tearDown(self)
        self.tagger_config = None

    def test_remove_source_dir(self):
        self.album.sourcedir = self.source_dir

        assert self.tagger_config.getboolean("details", "keep_original")

        testFileHandler = FileHandler(self.album, self.tagger_config)

        target_file = os.path.join(self.album.sourcedir, "id.txt")
        shutil.copyfile(self.source_copy_file, target_file)

        assert os.path.exists(target_file)

        testFileHandler.remove_source_dir()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(target_file)

        # construct config with only default values
        self.tagger_config = TaggerConfig(
            os.path.join(parentdir, "test/test_values.conf"))

        assert not self.tagger_config.getboolean("details", "keep_original")

        testFileHandler = FileHandler(self.album, self.tagger_config)

        assert os.path.exists(target_file)

        testFileHandler.remove_source_dir()

        assert not os.path.exists(self.album.sourcedir)
        assert not os.path.exists(target_file)

    def test_copy_files(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir,
                                   self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler.copy_files()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(self.album.target_dir)

        disc_dir = os.path.join(self.album.target_dir,
                                self.album.disc(1).target_dir)
        assert os.path.exists(disc_dir)

        disc_dir = os.path.join(self.album.target_dir,
                                self.album.disc(2).target_dir)
        assert os.path.exists(disc_dir)

        track_file = os.path.join(self.album.target_dir,
                                  self.album.disc(1).target_dir,
                                  self.album.disc(1).track(1).new_file)
        assert os.path.exists(track_file)

        track_file = os.path.join(self.album.target_dir,
                                  self.album.disc(1).target_dir,
                                  self.album.disc(1).track(20).new_file)
        assert os.path.exists(track_file)

        track_file = os.path.join(self.album.target_dir,
                                  self.album.disc(2).target_dir,
                                  self.album.disc(2).track(1).new_file)
        assert os.path.exists(track_file)

        track_file = os.path.join(self.album.target_dir,
                                  self.album.disc(2).target_dir,
                                  self.album.disc(2).track(20).new_file)
        assert os.path.exists(track_file)

    def test_embed_coverart_track(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir,
                                   self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler.copy_files()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(self.album.target_dir)

        track = self.album.disc(1).track(1)
        track_file = os.path.join(self.album.target_dir,
                                  self.album.disc(1).target_dir,
                                  track.new_file)

        source_file = "test/files/cover.jpeg"
        target_dir = os.path.join(self.album.target_dir,
                                  self.album.disc(1).target_dir)
        image_file = os.path.join(target_dir, "cover.jpeg")
        shutil.copyfile(source_file, image_file)
        imgdata = open(image_file).read()

        testFileHandler.embed_coverart_track(self.album.disc(1), track,
                                             imgdata)

        assert os.path.exists(track_file)

        metadata = MediaFile(track_file)

        assert not metadata.art == None

        track = self.album.disc(1).track(2)
        track_file = os.path.join(self.album.target_dir,
                                  self.album.disc(1).target_dir,
                                  track.new_file)
        metadata = MediaFile(track_file)

        assert metadata.art == None

    def test_embed_coverart_album(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir,
                                   self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler.copy_files()

        assert os.path.exists(self.album.sourcedir)
        assert os.path.exists(self.album.target_dir)

        source_file = "test/files/cover.jpeg"
        image_file = os.path.join(self.album.target_dir, "folder.jpg")
        shutil.copyfile(source_file, image_file)

        testFileHandler.embed_coverart_album()

        track = self.album.disc(1).track(1)
        track_file = os.path.join(self.album.target_dir,
                                  self.album.disc(1).target_dir,
                                  track.new_file)
        metadata = MediaFile(track_file)

        assert not metadata.art == None

    def test_copy_other_files(self):
        assert not self.tagger_config.getboolean("details", "copy_other_files")

        testTagUtils = TaggerUtils(self.source_dir, self.target_dir,
                                   self.tagger_config, self.album)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        testFileHandler = FileHandler(self.album, self.tagger_config)

        testFileHandler.copy_other_files()

        album_target_dir = self.album.target_dir
        assert not os.path.exists(os.path.join(album_target_dir, "id.txt"))

        disc_target_dir = os.path.join(album_target_dir,
                                       self.album.disc(1).target_dir)
        assert not os.path.exists(os.path.join(disc_target_dir, "album.cue"))

        disc_target_dir = os.path.join(album_target_dir,
                                       self.album.disc(2).target_dir)
        assert not os.path.exists(os.path.join(disc_target_dir, "album.cue"))

        # construct config with only default values
        self.tagger_config = TaggerConfig(
            os.path.join(parentdir, "test/test_values.conf"))

        assert self.tagger_config.getboolean("details", "copy_other_files")

        testTagUtils = TaggerUtils(self.source_dir, self.target_dir,
                                   self.tagger_config, self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        self.copy_files(self.album)

        testFileHandler.copy_other_files()

        album_target_dir = self.album.target_dir
        logger.debug("album_target_dir: %s" % album_target_dir)
        assert os.path.exists(os.path.join(album_target_dir, "id.txt"))

        disc_target_dir = os.path.join(album_target_dir,
                                       self.album.disc(1).target_dir)
        assert os.path.exists(os.path.join(disc_target_dir, "album.cue"))

        disc_target_dir = os.path.join(album_target_dir,
                                       self.album.disc(2).target_dir)
        assert os.path.exists(os.path.join(disc_target_dir, "album.cue"))

    def test_create_done_file(self):
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir,
                                   self.tagger_config, self.album)

        self.copy_files(self.album)

        testFileHandler = FileHandler(self.album, self.tagger_config)

        assert not os.path.exists(os.path.join(self.album.sourcedir,
                                               "dt.done"))

        testFileHandler.create_done_file()

        assert os.path.exists(os.path.join(self.album.sourcedir, "dt.done"))

    def test_get_images(self):
        """ It downloads only one image, since this is the default configuration
            This test needs network connection, as well as authentication support
        """
        testTagUtils = TaggerUtils(self.source_dir, self.target_dir,
                                   self.tagger_config, self.album)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        # the following stuff is only needed in the test, since we cannot use
        # a config option for these values ;-(
        # we are unfortunately treated to login every time this method is called ;-(

        consumer_key = None
        consumer_secret = None

        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_KEY"):
            consumer_key = os.environ.get('TRAVIS_DISCOGS_CONSUMER_KEY')
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_SECRET"):
            consumer_secret = os.environ.get("TRAVIS_DISCOGS_CONSUMER_SECRET")

        config = self.tagger_config
        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        discogs_connection = DiscogsConnector(config)
        testFileHandler = FileHandler(self.album, config)
        testFileHandler.get_images(discogs_connection)

        onlyfiles = [
            f for f in listdir(self.album.target_dir)
            if isfile(join(self.album.target_dir, f))
        ]
        logger.debug("files: %s " % onlyfiles)

        assert os.path.exists(os.path.join(self.album.target_dir,
                                           "folder.jpg"))
        assert not os.path.exists(
            os.path.join(self.album.target_dir, "image-01.jpg"))

    def test_get_images_wo_folderjpg(self):
        """ Downloads several images from discogs, using authentication
            This test needs network connection, as well as authentication support
        """
        # construct config with only default values
        config = TaggerConfig(os.path.join(parentdir, "test/test_values.conf"))

        testTagUtils = TaggerUtils(self.source_dir, self.target_dir, config,
                                   self.album)

        self.copy_files(self.album)

        testTagUtils._get_target_list()

        # the following stuff is only needed in the test, since we cannot use
        # a config option for these values ;-(
        # we are unfortunately treated to login every time this method is called ;-(

        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_KEY"):
            consumer_key = os.environ.get('TRAVIS_DISCOGS_CONSUMER_KEY')
        if os.environ.has_key("TRAVIS_DISCOGS_CONSUMER_SECRET"):
            consumer_secret = os.environ.get("TRAVIS_DISCOGS_CONSUMER_SECRET")

        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        discogs_connection = DiscogsConnector(config)
        testFileHandler = FileHandler(self.album, config)
        testFileHandler.get_images(discogs_connection)

        onlyfiles = [
            f for f in listdir(self.album.target_dir)
            if isfile(join(self.album.target_dir, f))
        ]
        logger.debug("files: %s " % onlyfiles)

        logger.debug('checking %s' % self.album.target_dir)

        assert os.path.exists(
            os.path.join(self.album.target_dir, "XXIMGXX-01.jpg"))
        assert os.path.exists(
            os.path.join(self.album.target_dir, "XXIMGXX-02.jpg"))
        assert os.path.exists(
            os.path.join(self.album.target_dir, "XXIMGXX-03.jpg"))
        assert os.path.exists(
            os.path.join(self.album.target_dir, "XXIMGXX-04.jpg"))

    test_get_images.needs_network = True
    test_get_images.needs_authentication = True
    test_get_images_wo_folderjpg.needs_network = True
    test_get_images_wo_folderjpg.needs_authentication = True