From 5dc1db3d4b415acc3869add60f2f076d4d4cbd43 Mon Sep 17 00:00:00 2001 From: Robbie Court Date: Tue, 22 Sep 2026 13:08:34 +0000 Subject: [PATCH] Preview every id shape, not just the underscored ones The id pattern required an underscore, so get_preview answered 400 for every FlyBase id and every dataset or publication -- FBgn0038978, FBtp0106402, FBti0004391, FBrf0247641, FBal0331598, Court2017, Chiang2010 -- although get_term_info resolves all of them, and the datasets even carry thumbnails. Those are a large share of real /reports/ traffic, and a dataset is exactly the sort of link someone shares. Widened to [A-Za-z][A-Za-z0-9_]+ : letters, digits and underscores from a letter. It still refuses the label-style URLs FlyBase points at VFB thumbnails (braces, spaces, a slash) and anything with a path in it. Over-matching is cheap here. get_term_info answers 200 with an empty shell for an id it does not know, every field null, so the preview handlers now require a Name as well as an Id and 404 otherwise -- which is what lets a caller fall back to its ordinary redirect instead of being handed a blank card. Tests cover all three id families, the empty shell, and the FlyBase label URL. --- src/test/test_link_preview.py | 22 ++++++++++++++++++---- src/vfbquery/ha_api.py | 8 +++++++- src/vfbquery/link_preview.py | 12 +++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/test/test_link_preview.py b/src/test/test_link_preview.py index 5ba3d6b..7703d7e 100644 --- a/src/test/test_link_preview.py +++ b/src/test/test_link_preview.py @@ -44,13 +44,27 @@ def _class_with_example(): # --- id validation ----------------------------------------------------------- -@pytest.mark.parametrize("value", ["FBbt_00003748", "VFB_jrchjrch", "VFBexp_FBtp0000001", "GO_0001872"]) -def test_is_term_id_accepts_vfb_shapes(value): +@pytest.mark.parametrize("value", [ + # underscored ontology ids + "FBbt_00003748", "VFB_jrchjrch", "VFBexp_FBtp0000001", "GO_0001872", + "GENO_0000346", "FBdv_00007133", "FBbi_00000537", + # FlyBase ids -- no underscore at all + "FBgn0038978", "FBtp0106402", "FBti0004391", "FBrf0247641", "FBal0331598", + # dataset / publication names + "Court2017", "Chiang2010", "Robie2017", +]) +def test_is_term_id_accepts_every_shape_get_term_info_resolves(value): assert link_preview.is_term_id(value) -@pytest.mark.parametrize("value", ["", None, "medulla", "