From 51a8691722fab0ec5cc849c53479bf08ebc6346e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Thu, 4 Jan 2024 10:10:13 +0800 Subject: [PATCH] fixbug: fix unit test --- metagpt/tools/metagpt_oas3_api_svc.py | 8 +++++++- metagpt/tools/openapi_v3_hello.py | 2 +- tests/metagpt/tools/test_metagpt_oas3_api_svc.py | 15 ++++++++------- tests/metagpt/tools/test_openapi_v3_hello.py | 15 ++++++++------- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/metagpt/tools/metagpt_oas3_api_svc.py b/metagpt/tools/metagpt_oas3_api_svc.py index 319e7efb2..8e9f4a0da 100644 --- a/metagpt/tools/metagpt_oas3_api_svc.py +++ b/metagpt/tools/metagpt_oas3_api_svc.py @@ -5,6 +5,12 @@ @Author : mashenquan @File : metagpt_oas3_api_svc.py @Desc : MetaGPT OpenAPI Specification 3.0 REST API service + + curl -X 'POST' \ + 'http://localhost:8080/openapi/greeting/dave' \ + -H 'accept: text/plain' \ + -H 'Content-Type: application/json' \ + -d '{}' """ from pathlib import Path @@ -15,7 +21,7 @@ import connexion def oas_http_svc(): """Start the OAS 3.0 OpenAPI HTTP service""" print("http://localhost:8080/oas3/ui/") - specification_dir = Path(__file__).parent.parent.parent / ".well-known" + specification_dir = Path(__file__).parent.parent.parent / "docs/.well-known" app = connexion.AsyncApp(__name__, specification_dir=str(specification_dir)) app.add_api("metagpt_oas3_api.yaml") app.add_api("openapi.yaml") diff --git a/metagpt/tools/openapi_v3_hello.py b/metagpt/tools/openapi_v3_hello.py index c8f5de42d..d1c83eac2 100644 --- a/metagpt/tools/openapi_v3_hello.py +++ b/metagpt/tools/openapi_v3_hello.py @@ -23,7 +23,7 @@ async def post_greeting(name: str) -> str: if __name__ == "__main__": - specification_dir = Path(__file__).parent.parent.parent / ".well-known" + specification_dir = Path(__file__).parent.parent.parent / "docs/.well-known" app = connexion.AsyncApp(__name__, specification_dir=str(specification_dir)) app.add_api("openapi.yaml", arguments={"title": "Hello World Example"}) app.run(port=8082) diff --git a/tests/metagpt/tools/test_metagpt_oas3_api_svc.py b/tests/metagpt/tools/test_metagpt_oas3_api_svc.py index 1135860eb..5f52b28cc 100644 --- a/tests/metagpt/tools/test_metagpt_oas3_api_svc.py +++ b/tests/metagpt/tools/test_metagpt_oas3_api_svc.py @@ -24,13 +24,14 @@ async def test_oas2_svc(): process = subprocess.Popen(["python", str(script_pathname)], cwd=str(workdir), env=env) await asyncio.sleep(5) - url = "http://localhost:8080/openapi/greeting/dave" - headers = {"accept": "text/plain", "Content-Type": "application/json"} - data = {} - response = requests.post(url, headers=headers, json=data) - assert response.text == "Hello dave\n" - - process.terminate() + try: + url = "http://localhost:8080/openapi/greeting/dave" + headers = {"accept": "text/plain", "Content-Type": "application/json"} + data = {} + response = requests.post(url, headers=headers, json=data) + assert response.text == "Hello dave\n" + finally: + process.terminate() if __name__ == "__main__": diff --git a/tests/metagpt/tools/test_openapi_v3_hello.py b/tests/metagpt/tools/test_openapi_v3_hello.py index 3f3f79829..5726cf8e0 100644 --- a/tests/metagpt/tools/test_openapi_v3_hello.py +++ b/tests/metagpt/tools/test_openapi_v3_hello.py @@ -24,13 +24,14 @@ async def test_hello(): process = subprocess.Popen(["python", str(script_pathname)], cwd=workdir, env=env) await asyncio.sleep(5) - url = "http://localhost:8082/openapi/greeting/dave" - headers = {"accept": "text/plain", "Content-Type": "application/json"} - data = {} - response = requests.post(url, headers=headers, json=data) - assert response.text == "Hello dave\n" - - process.terminate() + try: + url = "http://localhost:8082/openapi/greeting/dave" + headers = {"accept": "text/plain", "Content-Type": "application/json"} + data = {} + response = requests.post(url, headers=headers, json=data) + assert response.text == "Hello dave\n" + finally: + process.terminate() if __name__ == "__main__":