Skip to content

Commit

Permalink
Fix and test population of exhibit icon placeholder for GitHub (#34)
Browse files Browse the repository at this point in the history
* Add a test case for the issue

* Expose homepage

* Fix the server-side placeholder icon being overwritten by empty values
  • Loading branch information
krassowski authored Jul 5, 2024
1 parent 71e899f commit d12aab2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions jupyterlab_gallery/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# We do not want to expose `git_url` as it may contain PAT;
# we want an allow-list over block-list to avoid exposing PAT in case
# if the author of the config makes a typo like `giit` instead of `git`.
EXPOSED_EXHIBIT_KEYS = ["repository", "title", "description", "icon"]
EXPOSED_EXHIBIT_KEYS = ["homepage", "title", "description", "icon"]


class BaseHandler(APIHandler):
Expand Down Expand Up @@ -53,8 +53,8 @@ def get(self):
def _prepare_exhibit(self, exhibit, exhibit_id: int) -> dict:
exposed_config = {k: v for k, v in exhibit.items() if k in EXPOSED_EXHIBIT_KEYS}
return {
**self.gallery_manager.get_exhibit_data(exhibit),
**exposed_config,
**self.gallery_manager.get_exhibit_data(exhibit),
"id": exhibit_id,
}

Expand Down
24 changes: 24 additions & 0 deletions jupyterlab_gallery/tests/test_handlers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import json
from unittest import mock
import pytest

from jupyter_server.utils import url_path_join

from jupyterlab_gallery.manager import GalleryManager


async def test_exhibits(jp_fetch):
response = await jp_fetch("jupyterlab-gallery", "exhibits")
Expand All @@ -10,6 +14,26 @@ async def test_exhibits(jp_fetch):
assert isinstance(payload["exhibits"], list)


@pytest.mark.parametrize("exhibit", [
{
"git": "https://github.com/nebari-dev/nebari.git",
"homepage": "https://github.com/nebari-dev/nebari"
},
{
"git": "https://github.com/nebari-dev/nebari.git",
"homepage": "https://github.com/nebari-dev/nebari",
"icon": None
}
])
async def test_exhibit_generate_github_icon(jp_serverapp, jp_fetch, exhibit):
with mock.patch.object(GalleryManager, 'exhibits', [exhibit]):
response = await jp_fetch("jupyterlab-gallery", "exhibits")
assert response.code == 200
payload = json.loads(response.body)
assert len(payload["exhibits"]) == 1
assert payload["exhibits"][0]["icon"] == 'https://opengraph.githubassets.com/1/nebari-dev/nebari'


async def test_gallery(jp_fetch):
response = await jp_fetch("jupyterlab-gallery", "gallery")
assert response.code == 200
Expand Down

0 comments on commit d12aab2

Please sign in to comment.