Example #1
0
    def test_download_image_with_tokens(self):
        """
            test the download of images with authentification

            Because we would like to test this stuff on travis as well, we cannot store the tokens inside the
            usual "env" variables (otherwise the test test_download_images_wo_tokens would not work), as well
            as not in any config file. We do need to attache them from the travis environment to the tagger_config

            for this test to work, you should set the below mentioned environment variables before running the tesst
            with nosetests -s test/test_discogs.py
        """
        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 = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))
        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        logger.debug('consumer_key %s' % consumer_key)
        logger.debug('config %s' % config.get("discogs", "consumer_key"))

        discogs_connection = DiscogsConnector(config)
        discogs_connection.fetch_image(os.path.join(self.dummy_dir, 'folder.jpg'), "http://api.discogs.com/image/R-3083-1167766285.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))

        os.remove(os.path.join(self.dummy_dir, 'folder.jpg'))

        discogs_connection.fetch_image(os.path.join(self.dummy_dir, 'folder.jpg'), "http://api.discogs.com/image/R-367882-1193559996.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))
Example #2
0
    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"))
    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"))
    def test_download_image_with_tokens(self):
        """
            test the download of images with authentification

            Because we would like to test this stuff on travis as well, we cannot store the tokens inside the
            usual "env" variables (otherwise the test test_download_images_wo_tokens would not work), as well
            as not in any config file. We do need to attache them from the travis environment to the tagger_config

            for this test to work, you should set the below mentioned environment variables before running the tesst
            with nosetests -s test/test_discogs.py
        """
        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 = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))
        config.set("discogs", "consumer_key", consumer_key)
        config.set("discogs", "consumer_secret", consumer_secret)

        logger.debug('consumer_key %s' % consumer_key)
        logger.debug('config %s' % config.get("discogs", "consumer_key"))

        discogs_connection = DiscogsConnector(config)
        discogs_connection.fetch_image(
            os.path.join(self.dummy_dir, 'folder.jpg'),
            "http://api.discogs.com/image/R-3083-1167766285.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))

        os.remove(os.path.join(self.dummy_dir, 'folder.jpg'))

        discogs_connection.fetch_image(
            os.path.join(self.dummy_dir, 'folder.jpg'),
            "http://api.discogs.com/image/R-367882-1193559996.jpeg")

        assert os.path.exists(os.path.join(self.dummy_dir, 'folder.jpg'))
Example #5
0
    def test_read_token(self):
        """read the token file, if it exists
        """
        config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))
        config.set("discogs", "skip_auth", True)

        discogs_connection = DiscogsConnector(self.tagger_config)
        filename = discogs_connection.construct_token_file()

        if os.path.exists(filename):
            os.remove(filename)

        access_token, access_secret = discogs_connection.read_token()

        assert not access_token
        assert not access_secret

        with open(filename, 'w') as fh:
            fh.write('{0},{1}'.format("token", "secret"))

        access_token, access_secret = discogs_connection.read_token()

        assert access_token
        assert access_secret
    def test_read_token(self):
        """read the token file, if it exists
        """
        config = TaggerConfig(os.path.join(parentdir, "test/empty.conf"))
        config.set("discogs", "skip_auth", True)

        discogs_connection = DiscogsConnector(self.tagger_config)
        filename = discogs_connection.construct_token_file()

        if os.path.exists(filename):
            os.remove(filename)

        access_token, access_secret = discogs_connection.read_token()

        assert not access_token
        assert not access_secret

        with open(filename, 'w') as fh:
            fh.write('{0},{1}'.format("token", "secret"))

        access_token, access_secret = discogs_connection.read_token()

        assert access_token
        assert access_secret
Example #7
0
    p.print_help()
    sys.exit(1)

(options, args) = p.parse_args()

if not options.sourcedir or not os.path.exists(options.sourcedir):
    p.error("Please specify a valid source directory ('-s')")
else:
    options.sourcedir = os.path.abspath(options.sourcedir)

if options.destdir and os.path.exists(options.destdir):
    options.destdir = os.path.abspath(options.destdir)

tagger_config = TaggerConfig(options.conffile)
# options.replaygain = tagger_config.get("batch", "replaygain")
tagger_config.set('details', 'source_dir', options.sourcedir)
# initialize logging
logger_config_file = tagger_config.get("logging", "config_file")
logging.config.fileConfig(logger_config_file)

logger = logging.getLogger(__name__)

# read necessary config options for batch processing
id_file = tagger_config.get("batch", "id_file")
options.searchDiscogs = tagger_config.get('batch', 'searchDiscogs')
# options.parse_cue_files = tagger_config.get('cue', 'parse_cue_files')

file_utils = FileUtils(tagger_config, options)


def getSourceDirs():