Skip to content
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
9 changes: 7 additions & 2 deletions src/vfbquery/term_info_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,13 @@ def get_ext_link(self, show_types: bool = False):
return result

def link(self):
if self.accession and self.accession != "None":
return self.link_base + self.accession + self.link_postfix
# An accession only makes a link when the site has a link_base to hang
# it on; a bare accession would be emitted as a relative URL (e.g.
# ``/org.geppetto.frontend/sample-1099``) and 404. Sites without one
# (placeholders for data not yet published) fall through to their
# homepage, then their iri.
if self.accession and self.accession != "None" and self.link_base:
return self.link_base + self.accession + (self.link_postfix or "")
if self.homepage:
return self.homepage
return self.site.iri
Expand Down
6 changes: 4 additions & 2 deletions src/vfbquery/vfb_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1844,8 +1844,10 @@ def term_info_parse_object(results, short_form):
continue
label = getattr(site, 'label', '') if site else ''
acc = x.accession if getattr(x, 'accession', None) and x.accession != "None" else ''
if acc:
link = (x.link_base or '') + acc + (x.link_postfix or '')
# accession without a link_base would be a broken relative URL;
# fall back to the site's homepage (see Xref.link()).
if acc and getattr(x, 'link_base', None):
link = x.link_base + acc + (x.link_postfix or '')
elif getattr(x, 'homepage', None):
link = x.homepage
else:
Expand Down
28 changes: 28 additions & 0 deletions tests/test_xref_link_fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Xref.link(): an accession is only joined onto a link_base; without one the
link falls back to the site's homepage, then its iri, instead of emitting the
bare accession as a broken relative URL (seen as
``/org.geppetto.frontend/sample-1099`` on the Randel2026 dataset page)."""
from vfbquery.term_info_queries import MinimalEntityInfo, Xref

SITE = MinimalEntityInfo(short_form="larva1099_activity", iri="http://virtualflybrain.org/reports/larva1099_activity",
label="Larva1099 whole-brain calcium imaging")


def test_accession_with_link_base_builds_the_external_link():
x = Xref(site=SITE, link_base="https://vfb.neuroglass.io/studies/", accession="06aeb579", link_postfix="")
assert x.link() == "https://vfb.neuroglass.io/studies/06aeb579"


def test_accession_without_link_base_falls_back_to_homepage():
x = Xref(site=SITE, homepage="https://vfb.neuroglass.io/studies/06aeb579", accession="sample-1099")
assert x.link() == "https://vfb.neuroglass.io/studies/06aeb579"


def test_accession_without_link_base_or_homepage_falls_back_to_site_iri():
x = Xref(site=SITE, accession="463")
assert x.link() == SITE.iri


def test_none_postfix_is_tolerated():
x = Xref(site=SITE, link_base="https://example.org/?q=", accession="1", link_postfix=None)
assert x.link() == "https://example.org/?q=1"
Loading