Ejemplo n.º 1
0
 def test_deprecated_create_session(self, auth_mock):
     session = client.create_session(
         api_host=self.api_host,
         api_key=self.api_key,
         api_secret=self.api_secret,
         access_token_path=self.token_issuer_path,
         token_issuer_host=self.token_issuer_host,
         username=self.username,
         password=self.password,
         api_version=self.api_version)
     for attr in [
             "api_key", "api_secret", "api_host", "token_issuer_path",
             "token_issuer_host", "username", "password", "api_version"
     ]:
         assert getattr(self, attr) == getattr(session, attr)
Ejemplo n.º 2
0
def cli(ctx, **kwargs):
    splash = r"""
         _____              _         _ _       _
        |_   _|            | |       (_) |     | |
          | |_ __ _   _ ___| |_ _ __  _| | ___ | |_
          | | '__| | | / __| __| '_ \| | |/ _ \| __|
          | | |  | |_| \__ \ |_| |_) | | | (_) | |_
          \_/_|   \__,_|___/\__| .__/|_|_|\___/ \__|
                               | |
                               |_|
          ___        _   _____ _ _            _
         / _ \      (_) /  __ \ (_)          | |
        / /_\ \_ __  _  | /  \/ |_  ___ _ __ | |_
        |  _  | '_ \| | | |   | | |/ _ \ '_ \| __|
        | | | | |_) | | | \__/\ | |  __/ | | | |_
        \_| |_/ .__/|_|  \____/_|_|\___|_| |_|\__|
              | |
              |_|   """
    splash = (click.style(splash, fg="green") +
              click.style("v{}".format(__version__), fg="red") + "\n")

    values_dict = {}
    config_filename = kwargs.pop("c")

    if config_filename:
        with open(config_filename, "r") as f:
            values_dict = json.load(f)

    # setup verbosity level for global access
    verbosity = kwargs.get("verbose")
    ctx.meta["trustpilot.verbosity"] = verbosity

    # setup logging (increasing information levels)
    # _ : content, url, status_code
    # v : headers
    # vv: logging.INFO level
    # vvv: logging.DEBUG level
    levels = {2: logging.INFO, 3: logging.DEBUG}
    logging_level = levels.get(verbosity, logging.CRITICAL)

    logger.setLevel(logging_level)
    if logging_level > logging.DEBUG:
        # disable urllib3 logging
        client.disable_ssl_warnings()

    if ctx.invoked_subcommand is None:
        click.echo("\n".join([splash, ctx.get_help()]))
        return

    # create default session
    try:
        client.create_session(
            api_host=kwargs.pop("host")
            or values_dict.get("TRUSTPILOT_API_HOST")
            or "https://api.tp-staging.com",
            api_version=kwargs.pop("version")
            or values_dict.get("TRUSTPILOT_API_VERSION") or "v1",
            api_key=kwargs.pop("key") or values_dict["TRUSTPILOT_API_KEY"],
            api_secret=(kwargs.pop("secret")
                        or values_dict.get("TRUSTPILOT_API_SECRET", None)),
            token_issuer_host=(kwargs.pop("token_issuer_host")
                               or values_dict.get(
                                   "TRUSTPILOT_API_TOKEN_ISSUER_HOST", None)),
            username=kwargs.pop("username")
            or values_dict["TRUSTPILOT_USERNAME"],
            password=kwargs.pop("password")
            or values_dict["TRUSTPILOT_PASSWORD"],
        )
    except KeyError as key:
        raise SystemExit("Missing argument: {}".format(key))