diff --git a/pkgs/clan-cli/tests/emulate_fastapi.py b/pkgs/clan-cli/tests/emulate_fastapi.py new file mode 100644 index 0000000..1ccdab2 --- /dev/null +++ b/pkgs/clan-cli/tests/emulate_fastapi.py @@ -0,0 +1,145 @@ +import uvicorn +from fastapi import FastAPI +from fastapi.responses import HTMLResponse + +app = FastAPI() + +# bash tests: curl localhost:8000/ap_list_of_services + +@app.get("/health") +async def healthcheck() -> str: + return "200 OK" + +@app.get("/consume_service_from_other_entity", response_class=HTMLResponse) +async def consume_service_from_other_entity() -> HTMLResponse: + html_content = """ + +
+ + + + """ + return HTMLResponse(content=html_content, status_code=200) + +@app.get("/ap_list_of_services", response_class=HTMLResponse) +async def ap_list_of_services() -> HTMLResponse: + html_content = b'''HTTP/1.1 200 OK\r\n\r\n[[ + { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30df", + "service_name": "Carlos Printing", + "service_type": "3D Printing", + "endpoint_url": "http://127.0.0.1:8000", + "status": "unknown", + "other": { + "action": [ + "register", + "deregister", + "delete", + "create" + ] + }, + "entity_did": "did:sov:test:1234" + }, + { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d1", + "service_name": "Luiss Fax", + "service_type": "Fax", + "endpoint_url": "http://127.0.0.1:8000", + "status": "unknown", + "other": { + "action": [ + "register", + "deregister", + "delete", + "create" + ] + }, + "entity_did": "did:sov:test:1235" + }, + { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d2", + "service_name": "Erdems VR-Stream", + "service_type": "VR-Stream", + "endpoint_url": "http://127.0.0.1:8000", + "status": "unknown", + "other": { + "action": [ + "register", + "deregister", + "delete", + "create" + ] + }, + "entity_did": "did:sov:test:1236" + }, + { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d3", + "service_name": "Onurs gallary", + "service_type": "gallary", + "endpoint_url": "http://127.0.0.1:8000", + "status": "unknown", + "other": { + "action": [ + "register", + "deregister", + "delete", + "create" + ] + }, + "entity_did": "did:sov:test:1237" + }, + { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d4", + "service_name": "Saras Game-Shop", + "service_type": "Game-Shop", + "endpoint_url": "http://127.0.0.1:8000", + "status": "unknown", + "other": { + "action": [ + "register", + "deregister", + "delete", + "create" + ] + }, + "entity_did": "did:sov:test:1238" + } +]]''' + return HTMLResponse(content=html_content, status_code=200) + +@app.get("/dlg_list_of_did_resolutions", response_class=HTMLResponse) +async def dlg_list_of_did_resolutions() -> HTMLResponse: + html_content = b'''HTTP/1.1 200 OK\r\n\r\n +[ + { + "did": "did:sov:test:1234", + "name": "C1", + "ip": "127.0.0.1:5100", + "attached": false, + "visible": true, + "other": { + "network": "Carlo1's Home Network", + "roles": [ + "service repository", + "service consumer" + ] + } + }, + { + "did": "did:sov:test:1235", + "name": "C2", + "ip": "127.0.0.1:5100", + "attached": false, + "visible": true, + "other": { + "network": "Carlo2's Home Network", + "roles": [ + "service repository", + "service prosumer" + ] + } + } +]''' + return HTMLResponse(content=html_content, status_code=200) + +uvicorn.run(app, host="localhost", port=8000) \ No newline at end of file diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index 2bb519d..af680d4 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -67,6 +67,65 @@ def test_create_entities(api_client: ApiClient) -> None: assert res.did == own_entity.did assert res.attached is False +def test_producer2(api: TestClient) -> None: + request_body = { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d1", + "service_name": "Luis'''s Fax", + "service_type": "Fax", + "endpoint_url": "http://127.0.0.1:8001", + "status": "unknown", + "other": {"faxen": "dicke"}, + "entity_did": default_entity_did2, + } + paramter = "producer" + get_request = "entity_did="+url.quote(default_entity_did2) + make_test_post_and_get(api, request_body, paramter, get_request) + +def test_producer3(api: TestClient) -> None: + request_body = { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d2", + "service_name": "Erdem'''s VR-Stream", + "service_type": "VR-Stream", + "endpoint_url": "http://127.0.0.1:8002", + "status": "unknown", + "other": {"oculos": "rift"}, + "entity_did": default_entity_did3, + } + paramter = "producer" + get_request = "entity_did="+url.quote(default_entity_did3) + make_test_post_and_get(api, request_body, paramter, get_request) + + +def test_producer4(api: TestClient) -> None: + request_body = { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d3", + "service_name": "Onur'''s gallary", + "service_type": "gallary", + "endpoint_url": "http://127.0.0.1:8003", + "status": "unknown", + "other": {"nice": "pics"}, + "entity_did": default_entity_did4, + } + paramter = "producer" + get_request = "entity_did="+url.quote(default_entity_did4) + make_test_post_and_get(api, request_body, paramter, get_request) + + +def test_producer5(api: TestClient) -> None: + request_body = { + "uuid": "8e285c0c-4e40-430a-a477-26b3b81e30d4", + "service_name": "Sara'''s Game-Shop", + "service_type": "Game-Shop", + "endpoint_url": "http://127.0.0.1:8004", + "status": "unknown", + "other": {"war": "games"}, + "entity_did": default_entity_did5, + } + paramter = "producer" + get_request = "entity_did="+url.quote(default_entity_did5) + make_test_post_and_get(api, request_body, paramter, get_request) + + def test_create_services(api_client: ApiClient) -> None: sapi = ServicesApi(api_client=api_client)