|
10 | 10 | import datetime |
11 | 11 | import traceback |
12 | 12 | import time |
| 13 | +from urllib.parse import quote |
13 | 14 |
|
14 | 15 | # Suppress the urllib3 warning about OpenSSL |
15 | 16 | warnings.filterwarnings('ignore', category=Warning) |
@@ -134,6 +135,13 @@ def get_report_url(identifier): |
134 | 135 | """Create the VFB report URL path for a term identifier.""" |
135 | 136 | return f'/reports/{identifier}' |
136 | 137 |
|
| 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 | + |
137 | 145 | def is_known_id(identifier): |
138 | 146 | """Check if an identifier matches a known VFB prefix.""" |
139 | 147 | return any(identifier.startswith(p) for p in KNOWN_PREFIXES) |
@@ -317,7 +325,7 @@ def format_query_preview(query, term_id): |
317 | 325 | lines.append("") |
318 | 326 | lines.append("</div>") |
319 | 327 | 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 →</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 →</a>') |
321 | 329 | lines.append("") |
322 | 330 |
|
323 | 331 | return "\n".join(lines) |
@@ -753,25 +761,68 @@ def test_report_link_regression(): |
753 | 761 |
|
754 | 762 | return all_pass |
755 | 763 |
|
| 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 | + |
756 | 806 | def test_medulla_page(): |
757 | 807 | """Test page generation for medulla (class) and fru-M-200266 (individual).""" |
758 | 808 | result0 = test_hero_card_regression() |
759 | 809 | result1 = test_report_link_regression() |
| 810 | + result2 = test_query_button_regression() |
760 | 811 |
|
761 | 812 | print() |
762 | 813 | print("=" * 60) |
763 | | - print("Test 2: Class term — medulla (FBbt_00003748)") |
| 814 | + print("Test 3: Class term — medulla (FBbt_00003748)") |
764 | 815 | print("=" * 60) |
765 | | - result2 = test_term_page("FBbt_00003748", "class") |
| 816 | + result3 = test_term_page("FBbt_00003748", "class") |
766 | 817 |
|
767 | 818 | print() |
768 | 819 | print("=" * 60) |
769 | | - print("Test 3: Individual term — fru-M-200266 (VFB_00000001)") |
| 820 | + print("Test 4: Individual term — fru-M-200266 (VFB_00000001)") |
770 | 821 | print("=" * 60) |
771 | | - result3 = test_term_page("VFB_00000001", "individual") |
| 822 | + result4 = test_term_page("VFB_00000001", "individual") |
772 | 823 |
|
773 | 824 | print() |
774 | | - if result0 and result1 and result2 and result3: |
| 825 | + if result0 and result1 and result2 and result3 and result4: |
775 | 826 | print("All tests PASSED") |
776 | 827 | return True |
777 | 828 | else: |
|
0 commit comments