This commit is contained in:
marko
2023-12-31 07:39:34 +01:00
parent 13ea342be8
commit d285f2ba2c

View File

@@ -1,6 +1,5 @@
#! /usr/bin/env python #! /usr/bin/env python
from http import client
import logging import logging
import json import json
@@ -14,24 +13,30 @@ 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"
) )
@@ -47,7 +52,8 @@ class TestApi:
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)