Exemplo n.º 1
0
 def __init__(self, root='/home/ceda/trovebox'):
     self.client = Trovebox()
     self._storageDir = os.path.join(root, 'raw')
     self._dateDir = os.path.join(root, 'date')
     self._tagsDir = os.path.join(root, 'tags')
     self._albumsDir = os.path.join(root, 'albums')
     self._tags_to_ignore = 'autoupload,January,February,March,April,May,June,July,August,September,October,November,December'.split(
         ',')
Exemplo n.º 2
0
 def test_host_override(self):
     """ Ensure that specifying a host overrides the default config """
     self.create_config("default", "Test Default Host")
     client = Trovebox(host="host_override")
     auth = client.auth
     self.assertEqual(auth.host, "host_override")
     self.assertEqual(auth.consumer_key, "")
     self.assertEqual(auth.consumer_secret, "")
     self.assertEqual(auth.token, "")
     self.assertEqual(auth.token_secret, "")
Exemplo n.º 3
0
 def test_default_config(self):
     """ Ensure the default config is loaded """
     self.create_config("default", "Test Default Host")
     client = Trovebox()
     auth = client.auth
     self.assertEqual(client.host, "Test Default Host")
     self.assertEqual(auth.consumer_key, "default_consumer_key")
     self.assertEqual(auth.consumer_secret, "default_consumer_secret")
     self.assertEqual(auth.token, "default_token")
     self.assertEqual(auth.token_secret, "default_token_secret")
Exemplo n.º 4
0
 def test_full_config_path(self):
     """ Ensure a full custom config path can be loaded """
     self.create_config("path", "Test Path Host")
     full_path = os.path.abspath(CONFIG_PATH)
     client = Trovebox(config_file=os.path.join(full_path, "path"))
     auth = client.auth
     self.assertEqual(client.host, "Test Path Host")
     self.assertEqual(auth.consumer_key, "path_consumer_key")
     self.assertEqual(auth.consumer_secret, "path_consumer_secret")
     self.assertEqual(auth.token, "path_token")
     self.assertEqual(auth.token_secret, "path_token_secret")
Exemplo n.º 5
0
 def test_custom_config(self):
     """ Ensure a custom config can be loaded """
     self.create_config("default", "Test Default Host")
     self.create_config("custom", "Test Custom Host")
     client = Trovebox(config_file="custom")
     auth = client.auth
     self.assertEqual(client.host, "Test Custom Host")
     self.assertEqual(auth.consumer_key, "custom_consumer_key")
     self.assertEqual(auth.consumer_secret, "custom_consumer_secret")
     self.assertEqual(auth.token, "custom_token")
     self.assertEqual(auth.token_secret, "custom_token_secret")
Exemplo n.º 6
0
 def test_partial_config_file(self):
     """ Test that an incomplete config file causes default values to be set """
     self.create_config("incomplete",
                        host=None)  # Don't write the host line
     client = Trovebox(config_file="incomplete")
     auth = client.auth
     self.assertEqual(auth.host, "localhost")
     self.assertEqual(auth.consumer_key, "incomplete_consumer_key")
     self.assertEqual(auth.consumer_secret, "incomplete_consumer_secret")
     self.assertEqual(auth.token, "incomplete_token")
     self.assertEqual(auth.token_secret, "incomplete_token_secret")
Exemplo n.º 7
0
    parser.add_argument('--consumer-secret')
    parser.add_argument('--token')
    parser.add_argument('--token-secret')
    parser.add_argument('--debug',
                        help="Print extra debug information",
                        action="store_true")
    config = parser.parse_args()

    if config.debug:
        logging.basicConfig(level=logging.DEBUG)

    # Host option overrides config file settings
    if config.host:
        client = Trovebox(host=config.host,
                          consumer_key=config.consumer_key,
                          consumer_secret=config.consumer_secret,
                          token=config.token,
                          token_secret=config.token_secret)
    else:
        try:
            client = Trovebox(config_file=config.config)
        except IOError as error:
            print error
            print
            print "You must create a configuration file in ~/.config/trovebox/default"
            print "with the following contents:"
            print "    host = your.host.com"
            print "    consumerKey = your_consumer_key"
            print "    consumerSecret = your_consumer_secret"
            print "    token = your_access_token"
            print "    tokenSecret = your_access_token_secret"
Exemplo n.º 8
0
 def test_host_and_config_file(self):
     """ It's not valid to specify both a host and a config_file """
     self.create_config("custom", "Test Custom Host")
     with self.assertRaises(ValueError):
         Trovebox(config_file="custom", host="host_override")
Exemplo n.º 9
0
 def test_missing_config_files(self):
     """ Ensure that missing config files raise exceptions """
     with self.assertRaises(IOError):
         Trovebox()
     with self.assertRaises(IOError):
         Trovebox(config_file="custom")