diff options
Diffstat (limited to 'tool/test-crupest-api.py')
-rwxr-xr-x | tool/test-crupest-api.py | 55 |
1 files changed, 7 insertions, 48 deletions
diff --git a/tool/test-crupest-api.py b/tool/test-crupest-api.py index 5cd461d..c89a0f9 100755 --- a/tool/test-crupest-api.py +++ b/tool/test-crupest-api.py @@ -1,45 +1,23 @@ #!/usr/bin/env python3 -import subprocess -import os -import sys -from os.path import * -import signal -from modules.path import * +import json import time -from rich.console import Console +from os.path import * from urllib.request import urlopen from http.client import * -import json +from rich.console import Console +from modules.path import * console = console = Console() -ensure_log_dir() - -dotnet_project = join(project_dir, "docker", "crupest-api", "CrupestApi") -dotnet_log_path = abspath(join(log_dir, "crupest-api-log")) -dotnet_config_path = abspath(join(project_dir, "crupest-api-config.json")) - -os.environ["CRUPEST_API_CONFIG_FILE"] = dotnet_log_path -os.environ["CRUPEST_API_LOG_FILE"] = dotnet_config_path - -popen = subprocess.Popen( - ["dotnet", "run", "--project", dotnet_project, "--launch-profile", "dev"] -) - -console.print("Sleep for 3s to wait for server startup.") -time.sleep(3) - def do_the_test(): res: HTTPResponse = urlopen("http://localhost:5188/api/todos") - console.print(res) body = res.read() - console.print(body) if res.status != 200: raise Exception("Status code is not 200.") - result = json.load(body) + result = json.loads(body) if not isinstance(result, list): raise Exception("Result is not an array.") if len(result) == 0: @@ -52,29 +30,10 @@ def do_the_test(): raise Exception("Result[0].status is not a string.") -for i in range(0, 2): - console.print(f"Test begin with attempt {i + 1}", style="cyan") - try: - do_the_test() - console.print("Test passed.", style="green") - popen.send_signal(signal.SIGTERM) - popen.wait() - exit(0) - except Exception as e: - console.print(e) - console.print( - "Test failed. Try again after sleep for 1s.", style="red") - time.sleep(1) - try: - console.print( - f"Test begin with attempt {i + 2}, also the final one.", style="cyan") do_the_test() - console.print("Test passed.", style="green") - popen.send_signal(signal.SIGTERM) - popen.wait() + console.print("Test passed!", style="green") exit(0) except Exception as e: console.print(e) - console.print("Final test failed.", style="red") - exit(1) + console.print("Test failed!", style="red") |