Skip to content

Commit

Permalink
Fix test_http
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Mar 2, 2024
1 parent cb2ec6b commit c7af09a
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
TEST_APP_CODE = """
api.export({
async setup(){
await api.register_service(
},
async register_services(){
const service_info1 = await api.register_service(
{
"id": "test_service",
"name": "test_service",
Expand All @@ -31,7 +33,8 @@
}
}
)
await api.register_service(
console.log(`registered test_service: ${service_info1.id}`)
const service_info2 = await api.register_service(
{
"id": "test_service_protected",
"name": "test_service_protected",
Expand All @@ -45,6 +48,8 @@
}
}
)
console.log(`registered test_service: ${service_info2.id}`)
return [service_info1, service_info2]
}
})
"""
Expand Down Expand Up @@ -74,6 +79,7 @@ async def test_services(minio_server, fastapi_server, test_user_token):
async with httpx.AsyncClient(timeout=60.0) as client:
data = await client.get(f"{SERVER_URL}/services/openapi.json")
data = data.json()
assert data.get("detail") != "Not Found"
assert data["info"]["title"] == "Hypha Services"
paths = data["paths"]
assert "/call" in paths
Expand Down Expand Up @@ -105,12 +111,14 @@ async def test_services(minio_server, fastapi_server, test_user_token):
assert data.status_code == 200
assert data.json() == "123"

data = await client.get(f"{SERVER_URL}/services?workspace={workspace}")
data = await client.get(f"{SERVER_URL}/services/list?workspace={workspace}")
print(data.json())
# [{'config': {'visibility': 'public', 'require_context': False, 'workspace': 'VRRVEdTF9of2y4cLmepzBw', 'flags': []}, 'id': '5XCPAyZrW72oBzywEk2oxP:test_service', 'name': 'test_service', 'type': 'test_service', 'description': '', 'docs': {}}]
assert data.status_code == 200
assert data.json()[0]["name"] == "test_service"

await api.disconnect()


# pylint: disable=too-many-statements
async def test_http_proxy(minio_server, fastapi_server, test_user_token):
Expand All @@ -135,15 +143,15 @@ async def test_http_proxy(minio_server, fastapi_server, test_user_token):
wait_for_service=None,
)
plugin = await api.get_plugin(config.id)
assert "setup" in plugin
await plugin.setup()
assert "setup" in plugin and "register_services" in plugin
svc1, svc2 = await plugin.register_services()

service_ws = plugin.config.workspace
assert service_ws
service = await api.get_service("test_service")
service = await api.get_service(svc1["id"])
assert await service.echo("233d") == "233d"

service = await api.get_service("test_service_protected")
service = await api.get_service(svc2["id"])
assert await service.echo("22") == "22"

response = requests.get(f"{SERVER_URL}/workspaces/list")
Expand Down

0 comments on commit c7af09a

Please sign in to comment.