Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Adding favicon to Kedro Demo #1509

Merged
merged 21 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ Please follow the established format:
## Bug fixes and other changes

- Fix to search for a '<lambda' Python function in the sidebar. (#1497)
- Add favicon to Kedro-Viz. (#1509)
- Remove python upper-bound requirements and add KedroVizPythonVersion warning. (#1506)


# Release 6.4.0

## Major features and improvements
Expand Down
7 changes: 6 additions & 1 deletion package/kedro_viz/api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import secure
from fastapi import FastAPI, HTTPException
from fastapi.requests import Request
from fastapi.responses import HTMLResponse, JSONResponse, Response
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, Response
from fastapi.staticfiles import StaticFiles
from jinja2 import Environment, FileSystemLoader

Expand Down Expand Up @@ -72,6 +72,11 @@ def create_api_app_from_project(
# this is used as an etag embedded in the frontend for client to use when making requests.
app_etag = _create_etag()

# Serve the favicon.ico file from the "html" directory
@app.get("/favicon.ico", include_in_schema=False)
async def favicon():
return FileResponse(_HTML_DIR / "favicon.ico")

@app.get("/")
@app.get("/experiment-tracking")
async def index():
Expand Down
10 changes: 10 additions & 0 deletions package/tests/test_api/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ def test_reload_endpoint_return_304_when_content_has_not_changed(
# when the etag has changed, the server will return a 200
response = client.get("/api/reload", headers={"If-None-Match": "new etag"})
assert response.status_code == 200


class TestFaviconEndpoint:
def test_favicon_endpoint(self, client):
response = client.get("/favicon.ico")
assert response.status_code == 200
assert response.headers["content-type"] in [
"image/x-icon",
"image/vnd.microsoft.icon",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ - we have 2 content-types here, is it because of linux and windows tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here 'image/x-icon' is commonly used MIME type for ICO files, some server configurations might use 'image/vnd.microsoft.icon' as ICO files content type, in fact our test setup uses 'image/vnd.microsoft.icon' as ICO files content type. So added both content type for checks.

]