Exemple #1
0
def main(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--config-file',
                        help='Specify a configuration file')
    parser.add_argument('-e', '--endpoint',
                        help='Guacamole endpoint URL')
    parser.add_argument('-s', '--shortener',
                        help='Tamales endpoint URL')
    parser.add_argument('filename',
                        help='file to upload')
    args = parser.parse_args(args)

    settings = get_settings(args.config_file)

    endpoint = args.endpoint or settings.get('general', 'endpoint')
    shortener = args.shortener or settings.get('general', 'shortener')

    if not endpoint:
        error_msg = 'You must specify an endpoint URL using the --endpoint ' \
                    'command option or via the a configuration file by ' \
                    'default in {0}'.format(CONFIG_FILE)
        return error_msg

    client = GuacamoleClient(endpoint)
    url = client.send(args.filename)
    if not url:
        error_msg = 'Oops! It seems there\'s something wrong ' \
                    'with the endpoint {0}'.format(endpoint)
        return error_msg

    if shortener:
        client = TamalesClient(shortener)
        url = client.shorten(url)
        if not url:
            error_msg = 'Oops! It seems there\'s something wrong ' \
                        'with the URL shortener service {0}'.format(shortener)
            return error_msg
        print(url)
    else:
        print(url)
Exemple #2
0
class GuacamoleClientTest(unittest.TestCase):
    def setUp(self):
        self.endpoint = "http://localhost/files/"
        self.filename = "test-image.jpg"
        self.filepath = "tests/fixtures/%s" % self.filename
        self.client = GuacamoleClient(self.endpoint)

    def test_client_send(self):
        with requests_mock.Mocker() as m:
            m.post(self.endpoint, text='{"uri": "h/a/s/h/%s"}' % self.filename)

            expected_url = "http://localhost/files/h/a/s/h/test-image.jpg"
            received_url = self.client.send(self.filepath)
            self.assertEqual(expected_url, received_url)
Exemple #3
0
 def setUp(self):
     self.endpoint = "http://localhost/files/"
     self.filename = "test-image.jpg"
     self.filepath = "tests/fixtures/%s" % self.filename
     self.client = GuacamoleClient(self.endpoint)