mirror of
https://github.com/Novartis/cellxgene-gateway.git
synced 2026-10-05 10:48:12 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a00403c60e |
@@ -7,7 +7,7 @@
|
|||||||
# OR CONDITIONS OF ANY KIND, either express or implied. See the License for
|
# OR CONDITIONS OF ANY KIND, either express or implied. See the License for
|
||||||
# the specific language governing permissions and limitations under the License.
|
# the specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
import os
|
import html
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from cellxgene_gateway import env, flask_util
|
from cellxgene_gateway import env, flask_util
|
||||||
@@ -19,19 +19,17 @@ def render_annotations(item, item_source):
|
|||||||
url = flask_util.view_url(
|
url = flask_util.view_url(
|
||||||
item_source.get_annotations_subpath(item), item_source.name
|
item_source.get_annotations_subpath(item), item_source.name
|
||||||
)
|
)
|
||||||
new_annotation = f"<a class='new' href='{url}'>new</a>"
|
new_annotation = [f"<a class='new' href='{url}'>new</a>"]
|
||||||
|
|
||||||
annotations = (
|
annotations = (
|
||||||
", ".join(
|
[
|
||||||
[
|
f"<a href='{CacheKey(item, item_source, a).view_url}/'>{html.escape(a.name)}</a>"
|
||||||
f"<a href='{CacheKey(item, item_source, a).view_url}/'>{a.name}</a>"
|
for a in item.annotations
|
||||||
for a in item.annotations
|
]
|
||||||
]
|
|
||||||
)
|
|
||||||
+ ", "
|
|
||||||
if item.annotations
|
if item.annotations
|
||||||
else ""
|
else []
|
||||||
)
|
)
|
||||||
return " | annotations: " + annotations + new_annotation
|
return "| annotations: " + ", ".join(new_annotation + annotations)
|
||||||
|
|
||||||
|
|
||||||
def render_item(item, item_source):
|
def render_item(item, item_source):
|
||||||
|
|||||||
+58
-8
@@ -13,26 +13,76 @@ from cellxgene_gateway.items.item import ItemTree, ItemType
|
|||||||
source = FileItemSource("/tmp")
|
source = FileItemSource("/tmp")
|
||||||
|
|
||||||
|
|
||||||
|
def make_entry(subpath="somepath", annotations=None):
|
||||||
|
return FileItem(
|
||||||
|
subpath=subpath,
|
||||||
|
name="entry",
|
||||||
|
ext=".h5ad",
|
||||||
|
type=ItemType.h5ad,
|
||||||
|
annotations=annotations,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestRenderEntry(unittest.TestCase):
|
class TestRenderEntry(unittest.TestCase):
|
||||||
def test_GIVEN_path_both_slash_THEN_view_has_single_slash(self):
|
def test_GIVEN_path_both_slash_THEN_view_has_single_slash(self):
|
||||||
entry = FileItem(subpath="/somepath/", name="entry", type=ItemType.h5ad)
|
entry = make_entry(subpath="/somepath/")
|
||||||
rendered = render_item(entry, source)
|
rendered = render_item(entry, source)
|
||||||
self.assertIn("view/somepath/entry/'", rendered)
|
self.assertIn("view/somepath/entry.h5ad/'", rendered)
|
||||||
|
|
||||||
def test_GIVEN_path_starts_slash_THEN_view_has_single_slash(self):
|
def test_GIVEN_path_starts_slash_THEN_view_has_single_slash(self):
|
||||||
entry = FileItem(subpath="/somepath", name="entry", type=ItemType.h5ad)
|
entry = make_entry(subpath="/somepath")
|
||||||
rendered = render_item(entry, source)
|
rendered = render_item(entry, source)
|
||||||
self.assertIn("view/somepath/entry/'", rendered)
|
self.assertIn("view/somepath/entry.h5ad/'", rendered)
|
||||||
|
|
||||||
def test_GIVEN_path_ends_slash_THEN_view_has_single_slash(self):
|
def test_GIVEN_path_ends_slash_THEN_view_has_single_slash(self):
|
||||||
entry = FileItem(subpath="somepath/", name="entry", type=ItemType.h5ad)
|
entry = make_entry(subpath="somepath/")
|
||||||
rendered = render_item(entry, source)
|
rendered = render_item(entry, source)
|
||||||
self.assertIn("view/somepath/entry/'", rendered)
|
self.assertIn("view/somepath/entry.h5ad/'", rendered)
|
||||||
|
|
||||||
def test_GIVEN_path_no_slash_THEN_view_has_single_slash(self):
|
def test_GIVEN_path_no_slash_THEN_view_has_single_slash(self):
|
||||||
entry = FileItem(subpath="somepath", name="entry", type=ItemType.h5ad)
|
entry = make_entry(subpath="somepath")
|
||||||
rendered = render_item(entry, source)
|
rendered = render_item(entry, source)
|
||||||
self.assertIn("view/somepath/entry/'", rendered)
|
self.assertIn("view/somepath/entry.h5ad/'", rendered)
|
||||||
|
|
||||||
|
|
||||||
|
class TestRenderAnnotation(unittest.TestCase):
|
||||||
|
def test_GIVEN_no_annotation_THEN_new_alone(self):
|
||||||
|
entry = make_entry(annotations=None)
|
||||||
|
rendered = render_item(entry, source)
|
||||||
|
self.assertIn(
|
||||||
|
"> | annotations: <a class='new' href='/source/Files:/tmp/view/somepath/entry_annotations'>new</a></li>",
|
||||||
|
rendered,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_GIVEN_annotation_THEN_new_before(self):
|
||||||
|
annotation = FileItem(
|
||||||
|
subpath="somepath/entry_annotations",
|
||||||
|
name="annot",
|
||||||
|
ext=".csv",
|
||||||
|
type=ItemType.annotation,
|
||||||
|
)
|
||||||
|
entry = make_entry(annotations=[annotation])
|
||||||
|
rendered = render_item(entry, source)
|
||||||
|
self.assertIn(
|
||||||
|
"> | annotations: <a class='new' href='/source/Files:/tmp/view/somepath/entry_annotations'>new</a>,"
|
||||||
|
" <a href='/source/Files:/tmp/view/somepath/entry_annotations/annot.csv/'>annot</a></li>",
|
||||||
|
rendered,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_GIVEN_annotation_THEN_escaped(self):
|
||||||
|
annotation = FileItem(
|
||||||
|
subpath="somepath/entry_annotations",
|
||||||
|
name="hot&cold",
|
||||||
|
ext=".csv",
|
||||||
|
type=ItemType.annotation,
|
||||||
|
)
|
||||||
|
entry = make_entry(annotations=[annotation])
|
||||||
|
rendered = render_item(entry, source)
|
||||||
|
self.assertIn(
|
||||||
|
"> | annotations: <a class='new' href='/source/Files:/tmp/view/somepath/entry_annotations'>new</a>,"
|
||||||
|
" <a href='/source/Files:/tmp/view/somepath/entry_annotations/hot%26cold.csv/'>hot&cold</a></li>",
|
||||||
|
rendered,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestRenderItemSource(unittest.TestCase):
|
class TestRenderItemSource(unittest.TestCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user