reformat, added trainee debug target
This commit is contained in:
14
homepage/participo/.vscode/launch.json
vendored
14
homepage/participo/.vscode/launch.json
vendored
@@ -15,6 +15,16 @@
|
||||
"POST",
|
||||
"--input", "testShiai.json"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "getTrainees",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "testApi.py",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"args": [
|
||||
"GET",
|
||||
"--endpoint", "trainees" ]
|
||||
} ]
|
||||
}
|
||||
@@ -5,49 +5,32 @@ import json
|
||||
|
||||
|
||||
class TestApi:
|
||||
|
||||
@staticmethod
|
||||
def __parse_arguments():
|
||||
import argparse
|
||||
|
||||
argParser = argparse.ArgumentParser(
|
||||
"testApi"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"method",
|
||||
choices=['GET', 'POST']
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--endpoint",
|
||||
default="shiai"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--host",
|
||||
default="cwsvjudo.bplaced.net"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--path",
|
||||
default="participo/api"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--key",
|
||||
default=None
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--configFile",
|
||||
type=argparse.FileType('r'),
|
||||
default="testApi.config.yaml"
|
||||
)
|
||||
argParser = argparse.ArgumentParser("testApi")
|
||||
argParser.add_argument("method", choices=['GET', 'POST'])
|
||||
argParser.add_argument("--endpoint", default="shiai")
|
||||
argParser.add_argument("--host", default="cwsvjudo.bplaced.net")
|
||||
argParser.add_argument("--path", default="participo/api")
|
||||
argParser.add_argument("--key", default=None)
|
||||
argParser.add_argument("--configFile",
|
||||
type=argparse.FileType('r'),
|
||||
default="testApi.config.yaml")
|
||||
_LOG_LEVEL = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]
|
||||
argParser.add_argument(
|
||||
"--logLevel",
|
||||
choices=_LOG_LEVEL,
|
||||
default="WARNING"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"--input", "-i",
|
||||
type=argparse.FileType("r"),
|
||||
default="-"
|
||||
)
|
||||
argParser.add_argument("--logLevel",
|
||||
choices=_LOG_LEVEL,
|
||||
default="WARNING")
|
||||
argParser.add_argument("--input",
|
||||
"-i",
|
||||
type=argparse.FileType("r"),
|
||||
default="-")
|
||||
argParser.add_argument("--output",
|
||||
"-o",
|
||||
type=argparse.FileType("w"),
|
||||
default="-")
|
||||
|
||||
return argParser.parse_args()
|
||||
|
||||
@@ -70,11 +53,8 @@ class TestApi:
|
||||
method=self.config.method,
|
||||
host=self.config.host,
|
||||
url="/".join([self.config.path, self.config.endpoint]),
|
||||
headers={
|
||||
"Authorization": f"Basic {self.config.key}"
|
||||
},
|
||||
input=load_json(self.config.input)
|
||||
)
|
||||
headers={"Authorization": f"Basic {self.config.key}"},
|
||||
input=load_json(self.config.input))
|
||||
|
||||
|
||||
def load_json(jsonFile):
|
||||
@@ -82,7 +62,9 @@ def load_json(jsonFile):
|
||||
with jsonFile as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
class apiCall:
|
||||
|
||||
@staticmethod
|
||||
def call(
|
||||
method: str,
|
||||
@@ -93,19 +75,15 @@ class apiCall:
|
||||
) -> dict:
|
||||
import requests
|
||||
|
||||
if(method=="GET"):
|
||||
r = requests.get(
|
||||
url=f"http://{host}/{url}",
|
||||
timeout=10,
|
||||
headers=headers
|
||||
)
|
||||
elif(method=="POST"):
|
||||
r = requests.post(
|
||||
json=input,
|
||||
url=f"http://{host}/{url}",
|
||||
timeout=10,
|
||||
headers=headers
|
||||
)
|
||||
if (method == "GET"):
|
||||
r = requests.get(url=f"http://{host}/{url}",
|
||||
timeout=10,
|
||||
headers=headers)
|
||||
elif (method == "POST"):
|
||||
r = requests.post(json=input,
|
||||
url=f"http://{host}/{url}",
|
||||
timeout=10,
|
||||
headers=headers)
|
||||
else:
|
||||
logging.error("This line should never been reached!")
|
||||
|
||||
@@ -122,11 +100,6 @@ if __name__ == "__main__":
|
||||
response = testApi.apiCall()
|
||||
|
||||
try:
|
||||
print(
|
||||
json.dumps(
|
||||
response,
|
||||
indent=2
|
||||
)
|
||||
)
|
||||
print(json.dumps(response, indent=2))
|
||||
except Exception as e:
|
||||
logging.error(f"Exception {repr(e)} ({e}) while parsing json:")
|
||||
|
||||
Reference in New Issue
Block a user