def test_settings(self):
     # test looking up clusters or clients without specifying which
     settings = config.get_settings('dev')
     self.assertTrue(isinstance(settings, dict))
     self.assertEqual(settings['client_id'], "dev client_id")
Example #2
0
    def init_api(self, api_class=None):
        """
        Initialize a janrain.capture.Api() instance for the credentials that
        were specified on the command line or environment variables. This
        method will use the first credentials it finds, looking in the
        following order:

        1. A client_id and client_secret specified on the command line
        2. A configuration key specified on the command line
        3. The default client as specified with a flag on the command line
        4. The CAPTURE_CLIENT_ID and CAPTURE_CLIENT_SECRET environment vars

        Returns:
            A janrain.capture.Api instance

        """
        if not self._parsed_args:
            raise Exception("You must call the parse_args() method before " \
                            "the init_api() method.")

        args = self._parsed_args

        if args.client_id and args.client_secret:
            credentials = {
                'client_id': args.client_id,
                'client_secret': args.client_secret
            }

        elif args.config_key:
            credentials = config.get_settings(args.config_key)

        elif args.default_client:
            credentials = config.default_client()

        elif 'CAPTURE_CLIENT_ID' in os.environ \
            and 'CAPTURE_CLIENT_SECRET' in os.environ:
            credentials = {
                'client_id': os.environ['CAPTURE_CLIENT_ID'],
                'client_secret': os.environ['CAPTURE_CLIENT_SECRET']
            }

        else:
            message = "You did not specify credentials to authenticate " \
                      "with the Capture API."
            raise JanrainCredentialsError(message)

        if args.apid_uri:
            credentials['apid_uri'] = args.apid_uri

        elif 'apid_uri' not in credentials:
            if 'CAPTURE_APID_URI' in os.environ:
                credentials['apid_uri'] = os.environ['CAPTURE_APID_URI']
            else:
                message = "You did not specify the URL to the Capture API"
                raise JanrainCredentialsError(message)

        defaults = {k: credentials[k] for k in ('client_id', 'client_secret')}

        if api_class:
            return api_class(credentials['apid_uri'], defaults)
        else:
            return Api(credentials['apid_uri'], defaults)
Example #3
0
    def init_api(self, api_class=None):
        """
        Initialize a janrain.capture.Api() instance for the credentials that
        were specified on the command line or environment variables. This
        method will use the first credentials it finds, looking in the
        following order:

        1. A client_id and client_secret specified on the command line
        2. A configuration key specified on the command line
        3. The default client as specified with a flag on the command line
        4. The CAPTURE_CLIENT_ID and CAPTURE_CLIENT_SECRET environment vars

        Returns:
            A janrain.capture.Api instance

        """
        if not self._parsed_args:
            raise Exception("You must call the parse_args() method before " \
                            "the init_api() method.")

        args = self._parsed_args

        if args.client_id and args.client_secret:
            credentials = {
                'client_id': args.client_id,
                'client_secret': args.client_secret
            }

        elif args.config_key:
            credentials = config.get_settings(args.config_key)

        elif args.default_client:
            credentials = config.default_client()

        elif 'CAPTURE_CLIENT_ID' in os.environ \
            and 'CAPTURE_CLIENT_SECRET' in os.environ:
            credentials = {
                'client_id': os.environ['CAPTURE_CLIENT_ID'],
                'client_secret': os.environ['CAPTURE_CLIENT_SECRET']
            }

        else:
            message = "You did not specify credentials to authenticate " \
                      "with the Capture API."
            raise JanrainCredentialsError(message)

        if args.apid_uri:
            credentials['apid_uri'] = args.apid_uri

        elif 'apid_uri' not in credentials:
            if 'CAPTURE_APID_URI' in os.environ:
                credentials['apid_uri'] = os.environ['CAPTURE_APID_URI']
            else:
                message = "You did not specify the URL to the Capture API"
                raise JanrainCredentialsError(message)

        defaults = {k: credentials[k] for k in ('client_id', 'client_secret')}

        if api_class:
            return api_class(credentials['apid_uri'], defaults)
        else:
            return Api(credentials['apid_uri'], defaults)