Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chamini2 committed Feb 21, 2024
1 parent 26bfb3f commit f979220
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion projects/fal/src/fal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,11 +826,12 @@ async def not_found_exception_handler(request: Request, exc: HTTPException):
# This is supposed to make it easier to understand to the user
# that the error comes from the app and not our platform.
try:
print(exc.detail, exc.detail == "Not Found")
if exc.detail == "Not Found":
return JSONResponse(
{"detail": f"Path {request.url.path} not found"}, 404
)
finally:
except Exception:
# If it's not a generic 404, just return the original message.
return JSONResponse({"detail": exc.detail}, 404)

Expand Down
26 changes: 26 additions & 0 deletions projects/fal/tests/test_apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
from typing import Generator

import fastapi
import pytest
from fastapi import WebSocket
from openapi_fal_rest.api.applications import app_metadata
Expand Down Expand Up @@ -79,6 +80,10 @@ def subtract(input: Input) -> Output:
allow_origins=("*"),
)

@app.exception_handler(404)
async def http_exception_handler(request, exc):
return fastapi.responses.JSONResponse("FAILED INSIDE THE APP", status_code=404)

run(app, host="0.0.0.0", port=8080)


Expand Down Expand Up @@ -325,6 +330,27 @@ def test_app_no_serve_spec_metadata(
), f"openapi should not be present in metadata {metadata}"


def test_404_response(
calculator_app: str, test_app: str, request: pytest.FixtureRequest
):
try:
apps.run(test_app, path="/other", arguments={"lhs": 1, "rhs": 2})
except fastapi.HTTPException as e:
assert e.status_code == 404
assert "Path /other not found" in e.detail
else:
assert False, "Expected 404 response"

try:
apps.run(calculator_app, path="/other", arguments={"lhs": 1, "rhs": 2})
except fastapi.HTTPException as e:
assert e.status_code == 404
# Custom responses do not have the default message
assert "INSIDE APP" in e.detail
else:
assert False, "Expected 404 response"


def test_app_update_app(aliased_app: tuple[str, str]):
app_revision, app_alias = aliased_app

Expand Down

0 comments on commit f979220

Please sign in to comment.