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