Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
abidlabs committed Sep 13, 2024
1 parent cc4ed77 commit 5ca904a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 1 addition & 3 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@


if TYPE_CHECKING: # Only import for type checking (is False at runtime).
from fastapi.applications import FastAPI

from gradio.components.base import Component
from gradio.renderable import Renderable

Expand Down Expand Up @@ -2227,7 +2225,7 @@ def launch(
_frontend: bool = True,
enable_monitoring: bool | None = None,
strict_cors: bool = True,
) -> tuple[FastAPI, str, str]:
) -> tuple[routes.App, str, str]:
"""
Launches a simple web server that serves the demo. Can also be used to create a
public link used by anyone to access the demo from their browser by setting share=True.
Expand Down
16 changes: 14 additions & 2 deletions test/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,29 @@ def test_response_attachment_format(self):
app, _, _ = io.launch(
prevent_thread_lock=True,
allowed_paths=[
os.path.dirname(image_file.name),
os.path.dirname(html_file.name),
image_file.name,
html_file.name,
],
)

html_file2 = tempfile.NamedTemporaryFile(
mode="w", delete=False, suffix=".html", dir=app.uploaded_file_dir
)
html_file2.write("<html>Hello, world!</html>")
html_file2.flush()
html_file2_name = str(Path(app.uploaded_file_dir) / html_file2.name)

client = TestClient(app)

file_response = client.get(f"{API_PREFIX}/file={image_file.name}")
assert file_response.headers["Content-Type"] == "image/png"
assert "inline" in file_response.headers["Content-Disposition"]

file_response = client.get(f"{API_PREFIX}/file={html_file.name}")
assert file_response.headers["Content-Type"] == "text/html; charset=utf-8"
assert "inline" in file_response.headers["Content-Disposition"]

file_response = client.get(f"{API_PREFIX}/file={html_file2_name}")
assert file_response.headers["Content-Type"] == "application/octet-stream"
assert "attachment" in file_response.headers["Content-Disposition"]

Expand Down

0 comments on commit 5ca904a

Please sign in to comment.