Files
hair/tests/test_gateway_hairline_routes.py
T

34 lines
1.2 KiB
Python

"""Interface 52 belongs to the GPU worker; the gateway keeps its legacy routes."""
import asyncio
import importlib
import pytest
from starlette.requests import Request
@pytest.mark.parametrize(("name", "path"), [
("hairline_generate", "/api/v1/hairline/generate"),
("hair_grow_22", "/api/v1/hair/grow-22"),
])
def test_hairline_forwarding(monkeypatch, name, path):
gateway = importlib.import_module("gateway.app")
request = Request({"type": "http", "method": "POST", "path": path, "headers": []})
calls = []
async def proxy(actual_request, actual_path):
assert actual_request is request
calls.append(actual_path)
return {"forwarded_to": actual_path}
monkeypatch.setattr(gateway, "_proxy", proxy)
endpoint = getattr(gateway, name)
assert next(route for route in gateway.app.routes if getattr(route, "path", None) == path).endpoint is endpoint
assert asyncio.run(endpoint(request)) == {"forwarded_to": path}
assert calls == [path]
def test_interface52_is_not_exposed_by_gateway():
gateway = importlib.import_module("gateway.app")
assert not any(getattr(route, "path", None) == "/api/v1/hairline/generate-52"
for route in gateway.app.routes)