pep8
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
#! /usr/bin/env python
|
||||
|
||||
from http import client
|
||||
import logging
|
||||
import json
|
||||
|
||||
|
||||
class TestApi:
|
||||
@staticmethod
|
||||
@staticmethod
|
||||
def __parse_arguments():
|
||||
import argparse
|
||||
|
||||
@@ -14,30 +13,36 @@ class TestApi:
|
||||
"testApi"
|
||||
)
|
||||
|
||||
argParser.add_argument("--endpoint",
|
||||
argParser.add_argument(
|
||||
"--endpoint",
|
||||
default="shiai"
|
||||
)
|
||||
argParser.add_argument("--host",
|
||||
argParser.add_argument(
|
||||
"--host",
|
||||
default="cwsvjudo.bplaced.net"
|
||||
)
|
||||
argParser.add_argument("--path",
|
||||
argParser.add_argument(
|
||||
"--path",
|
||||
default="participo/api"
|
||||
)
|
||||
argParser.add_argument("--key",
|
||||
argParser.add_argument(
|
||||
"--key",
|
||||
default=None
|
||||
)
|
||||
argParser.add_argument("--configFile",
|
||||
argParser.add_argument(
|
||||
"--configFile",
|
||||
type=argparse.FileType('r'),
|
||||
default="testApi.config.yaml"
|
||||
)
|
||||
)
|
||||
_LOG_LEVEL = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
|
||||
argParser.add_argument("--logLevel",
|
||||
argParser.add_argument(
|
||||
"--logLevel",
|
||||
choices=_LOG_LEVEL,
|
||||
default="WARNING"
|
||||
)
|
||||
|
||||
return argParser.parse_args()
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.config = self.__parse_arguments()
|
||||
self.config.logLevel = getattr(logging, self.config.logLevel)
|
||||
@@ -46,8 +51,9 @@ class TestApi:
|
||||
with self.config.configFile as cf:
|
||||
from yaml import safe_load
|
||||
configData = safe_load(cf)
|
||||
|
||||
# @todo: add the attributes from the config file to the config (if not already set)
|
||||
|
||||
# @todo: add the attributes from the config file to the config (if not
|
||||
# already set)
|
||||
if not self.config.key and 'apiKey' in configData:
|
||||
self.config.key = configData['apiKey']
|
||||
|
||||
@@ -60,6 +66,7 @@ class TestApi:
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class apiCall:
|
||||
@staticmethod
|
||||
def call(
|
||||
@@ -71,8 +78,10 @@ class apiCall:
|
||||
|
||||
r = requests.get(
|
||||
url=f"http://{host}/{url}",
|
||||
# @todo The client always awaits this timeout. Even when the meaningful body is already received.params=
|
||||
# - I don't see any of the examples out there do it different from me.
|
||||
# @todo The client always awaits this timeout. Even when the
|
||||
# meaningful body is already received.params=
|
||||
# - I don't see any of the examples out there do it different from
|
||||
# me.
|
||||
# - The browser doesn't seem to have this problem.
|
||||
timeout=10,
|
||||
headers=headers
|
||||
@@ -80,8 +89,9 @@ class apiCall:
|
||||
|
||||
try:
|
||||
return r.json()
|
||||
except:
|
||||
logging.error(f"failed to parse json: {r.text}")
|
||||
except Exception as e:
|
||||
logging.error(f"Exception {repr(e)} ({e}) while parsing json:")
|
||||
logging.error(r.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -96,6 +106,5 @@ if __name__ == "__main__":
|
||||
indent=2
|
||||
)
|
||||
)
|
||||
except:
|
||||
logging.error("failed to parse to json:")
|
||||
logging.error(response)
|
||||
except Exception as e:
|
||||
logging.error(f"Exception {repr(e)} ({e}) while parsing json:")
|
||||
|
||||
Reference in New Issue
Block a user