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
7 changes: 4 additions & 3 deletions app/api/lapis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

class Lapis:
"""Base class for LAPIS API queries."""

def __init__(self, server_ip):
self.server_ip = server_ip
# Normalize URL by removing trailing slashes to prevent double-slash issues
self.server_ip = server_ip.rstrip("/")

@staticmethod
def parse_url_hostname(url_string):
Expand Down Expand Up @@ -40,7 +41,7 @@ def fetch_locations(self, default_locations=None) -> list[str]:
locations = st.session_state.locations
return locations
# Use the full server_ip URL directly instead of parsing it
location_url = f'{self.server_ip.rstrip("/")}/sample/aggregated?fields=locationName&limit=100&orderBy=locationName&dataFormat=JSON&downloadAsFile=false'
location_url = f'{self.server_ip}/sample/aggregated?fields=locationName&limit=100&orderBy=locationName&dataFormat=JSON&downloadAsFile=false'
try:
logging.info(f"Attempting to fetch locations from: {location_url}")
st.toast("Attempting to fetch locations from API...", icon="🔄") # Temporary toast
Expand Down
2 changes: 1 addition & 1 deletion app/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
lapis_address: "https://lapis.wasap.genspectrum.org/"
lapis_address: "https://lapis.wasap.genspectrum.org/covid"
cov_spectrum_api: "https://lapis.cov-spectrum.org"

curated_variant_definitions:
Expand Down
26 changes: 26 additions & 0 deletions app/tests/test_wiseloculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,35 @@
sys.path.insert(0, str(Path(__file__).parent.parent))

from api.wiseloculus import WiseLoculusLapis
from api.lapis import Lapis
from interface import MutationType


# Tests for URL normalization (trailing slash handling)
def test_lapis_normalizes_trailing_slash():
"""Test that Lapis base class strips trailing slashes from server_ip."""
lapis = Lapis("https://example.com/")
assert lapis.server_ip == "https://example.com", "Trailing slash should be stripped"


def test_lapis_preserves_url_without_trailing_slash():
"""Test that Lapis base class preserves URLs without trailing slashes."""
lapis = Lapis("https://example.com")
assert lapis.server_ip == "https://example.com", "URL without trailing slash should remain unchanged"


def test_lapis_normalizes_multiple_trailing_slashes():
"""Test that Lapis strips multiple trailing slashes."""
lapis = Lapis("https://example.com///")
assert lapis.server_ip == "https://example.com", "Multiple trailing slashes should be stripped"


def test_wiseloculus_inherits_url_normalization():
"""Test that WiseLoculusLapis inherits URL normalization from Lapis."""
api = WiseLoculusLapis("https://lapis.wasap.genspectrum.org/")
assert api.server_ip == "https://lapis.wasap.genspectrum.org", "WiseLoculusLapis should inherit URL normalization"


def test_mutations_to_and_query_empty():
"""Test _mutations_to_and_query with empty list."""
api = WiseLoculusLapis("http://test-server.com")
Expand Down
Loading