コード例 #1
0
 def test_login(self, mock_test_auth):
     mock_test_auth.return_value = False
     self.requests.post.return_value.status_code = 200
     self.requests.post.return_value.url = '/something'
     apiclient.GaiaClient('foo', 'bar')
     self.requests.post.assert_called_once_with(
         apiclient.gurl('login'),
         data={'username': '******', 'password': '******', 'next': '/'})
コード例 #2
0
ファイル: test_apiclient.py プロジェクト: kk7ds/gaiagpsclient
 def test_login(self, mock_test_auth):
     mock_test_auth.return_value = False
     self.requests.post.return_value.status_code = 200
     self.requests.post.return_value.url = '/something'
     apiclient.GaiaClient('foo', 'bar')
     self.requests.post.assert_called_once_with(
         apiclient.gurl('register/addDevice'),
         data={
             'email': 'foo',
             'password': '******'
         })
コード例 #3
0
    def setUp(self):
        try:
            username = os.environ['GAIA_USER']
            password = os.environ['GAIA_PASS']
        except KeyError:
            raise Exception('Specify gaia credentials in '
                            'GAIA_USER and GAIA_PASS environment variables')

        self.api = apiclient.GaiaClient(username, password,
                                        cookies=self.cookies)

        # Clean up from any previous runs
        self._clean(verbose=True)
コード例 #4
0
ファイル: test_apiclient.py プロジェクト: kk7ds/gaiagpsclient
 def get_api(self, mock_test_auth):
     mock_test_auth.return_value = True
     return apiclient.GaiaClient('foo', 'bar')
コード例 #5
0
ファイル: test_apiclient.py プロジェクト: kk7ds/gaiagpsclient
 def test_login_not_needed(self, mock_test_auth):
     mock_test_auth.return_value = True
     apiclient.GaiaClient('foo', 'bar')
     self.requests.post.assert_not_called()
     mock_test_auth.assert_called_once_with()
コード例 #6
0
def main():
    parser = argparse.ArgumentParser(
        description='Command line client for gaiagps.com')
    parser.add_argument('--user', help='Gaia username')
    parser.add_argument('--pass', metavar='PASS', dest='pass_',
                        help='Gaia password (prompt if unspecified)', )
    parser.add_argument('--debug', help='Enable debug output',
                        action='store_true')
    parser.add_argument('--verbose', help='Enable verbose output',
                        action='store_true')

    cmds = parser.add_subparsers(dest='cmd')

    command_classes = [Waypoint, Folder, Test, Tree, Track, Upload]
    commands = {}

    for ccls in command_classes:
        command_name = ccls.__name__.lower()
        commands[command_name] = ccls
        try:
            helptxt, desctxt = ccls.__doc__.split('\n', 1)
        except ValueError:
            helptxt = ccls.__doc__
            desctxt = ''
        ccls.opts(cmds.add_parser(command_name,
                                  description=desctxt.strip(),
                                  help=helptxt.strip()))

    args = parser.parse_args()

    logging.basicConfig(level=logging.WARNING)
    root_logger = logging.getLogger()
    if args.debug:
        root_logger.setLevel(logging.DEBUG)
        import http.client
        http.client.HTTPConnection.debuglevel = 1
    elif args.verbose:
        root_logger.setLevel(logging.INFO)

    if not args.cmd:
        parser.print_help()
        return 1
    else:
        is_terminal = os.isatty(sys.stdin.fileno())
        if args.user and not args.pass_ and is_terminal:
            args.pass_ = getpass.getpass()

        with cookiejar() as cookies:
            try:
                client = apiclient.GaiaClient(args.user, args.pass_,
                                              cookies=cookies)
            except Exception as e:
                print('Unable to access Gaia: %s' % e)
                return 1

        command = commands[args.cmd](client, verbose=args.verbose)
        try:
            return command.dispatch(parser, args)
        except (apiclient.NotFound, RuntimeError) as e:
            print(e)
            return 1