Skip to content

Commit 62a9dd1

Browse files
committed
feat: enhance query URL generation and add regression tests for query buttons
1 parent f15f766 commit 62a9dd1

2 files changed

Lines changed: 60 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ public/*
22
.DS_Store
33
/.venv
44
transcript.en.vtt
5+
__pycache__
6+
__pycache__/
7+
__pycache__/*.pyc

vfbterms.py

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import datetime
1111
import traceback
1212
import time
13+
from urllib.parse import quote
1314

1415
# Suppress the urllib3 warning about OpenSSL
1516
warnings.filterwarnings('ignore', category=Warning)
@@ -134,6 +135,13 @@ def get_report_url(identifier):
134135
"""Create the VFB report URL path for a term identifier."""
135136
return f'/reports/{identifier}'
136137

138+
def get_query_results_url(term_id, query_name):
139+
"""Create a VFB viewer URL for a term query result set."""
140+
if not query_name:
141+
return f'{VFB_BROWSER_BASE}?id={term_id}'
142+
query = quote(f'{term_id},{query_name}', safe=',')
143+
return f'{VFB_BROWSER_BASE}?q={query}'
144+
137145
def is_known_id(identifier):
138146
"""Check if an identifier matches a known VFB prefix."""
139147
return any(identifier.startswith(p) for p in KNOWN_PREFIXES)
@@ -317,7 +325,7 @@ def format_query_preview(query, term_id):
317325
lines.append("")
318326
lines.append("</div>")
319327
lines.append("")
320-
lines.append(f'<a href="{VFB_BROWSER_BASE}?id={term_id}" class="btn btn-outline-primary btn-sm">View all {count} results in VFB &rarr;</a>')
328+
lines.append(f'<a href="{get_query_results_url(term_id, query_name)}" class="btn btn-outline-primary btn-sm">View all {count} results in VFB &rarr;</a>')
321329
lines.append("")
322330

323331
return "\n".join(lines)
@@ -753,25 +761,68 @@ def test_report_link_regression():
753761

754762
return all_pass
755763

764+
def test_query_button_regression():
765+
"""Ensure query preview buttons open the matching VFB query."""
766+
print("=" * 60)
767+
print("Test 2: Query button regression")
768+
print("=" * 60)
769+
770+
query_preview = format_query_preview(
771+
{
772+
"label": "Neurons with some part in adult intercalary segment",
773+
"query": "NeuronsPartHere",
774+
"count": 666,
775+
"preview_results": {
776+
"rows": [
777+
{
778+
"label": "[DNb08](FBbt_20011340)",
779+
"id": "FBbt_20011340",
780+
"tags": "Adult|Cholinergic|Nervous_system|primary_neuron",
781+
},
782+
]
783+
},
784+
},
785+
"FBbt_00003013",
786+
)
787+
788+
expected_query_url = f'{VFB_BROWSER_BASE}?q=FBbt_00003013,NeuronsPartHere'
789+
fallback_url = f'{VFB_BROWSER_BASE}?id=FBbt_00003013'
790+
791+
checks = {
792+
"Query button uses VFB query URL": expected_query_url in query_preview,
793+
"Query button no longer uses term-only URL": fallback_url not in query_preview,
794+
"Helper falls back to term URL when missing query": get_query_results_url("FBbt_00003013", "") == fallback_url,
795+
}
796+
797+
all_pass = True
798+
for check_name, result in checks.items():
799+
status = "PASS" if result else "FAIL"
800+
if not result:
801+
all_pass = False
802+
print(f" [{status}] {check_name}")
803+
804+
return all_pass
805+
756806
def test_medulla_page():
757807
"""Test page generation for medulla (class) and fru-M-200266 (individual)."""
758808
result0 = test_hero_card_regression()
759809
result1 = test_report_link_regression()
810+
result2 = test_query_button_regression()
760811

761812
print()
762813
print("=" * 60)
763-
print("Test 2: Class term — medulla (FBbt_00003748)")
814+
print("Test 3: Class term — medulla (FBbt_00003748)")
764815
print("=" * 60)
765-
result2 = test_term_page("FBbt_00003748", "class")
816+
result3 = test_term_page("FBbt_00003748", "class")
766817

767818
print()
768819
print("=" * 60)
769-
print("Test 3: Individual term — fru-M-200266 (VFB_00000001)")
820+
print("Test 4: Individual term — fru-M-200266 (VFB_00000001)")
770821
print("=" * 60)
771-
result3 = test_term_page("VFB_00000001", "individual")
822+
result4 = test_term_page("VFB_00000001", "individual")
772823

773824
print()
774-
if result0 and result1 and result2 and result3:
825+
if result0 and result1 and result2 and result3 and result4:
775826
print("All tests PASSED")
776827
return True
777828
else:

0 commit comments

Comments
 (0)