Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for CISearchView and cantus index functions #1552

Merged
merged 3 commits into from
Jun 21, 2024
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
8 changes: 5 additions & 3 deletions django/cantusdb_project/cantusindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from requests.exceptions import SSLError, Timeout, HTTPError

CANTUS_INDEX_DOMAIN: str = "https://cantusindex.uwaterloo.ca"
OLD_CANTUS_INDEX_DOMAIN: str = "https://cantusindex.org"
DEFAULT_TIMEOUT: float = 2 # seconds
NUMBER_OF_SUGGESTED_CHANTS: int = 3 # this number can't be too large,
# since for each suggested chant, we make a request to Cantus Index.
Expand Down Expand Up @@ -151,10 +152,10 @@ def get_merged_cantus_ids() -> Optional[list[Optional[dict]]]:
# We have to use the old CI domain since the API is still not available on
# cantusindex.uwaterloo.ca. Once it's available, we can use get_json_from_ci_api
# json: Union[dict, list, None] = get_json_from_ci_api(endpoint_path)
uri: str = f"https://cantusindex.org{endpoint_path}"
uri: str = f"{OLD_CANTUS_INDEX_DOMAIN}{endpoint_path}"
try:
response: requests.Response = requests.get(uri, timeout=DEFAULT_TIMEOUT)
except requests.exceptions.Timeout:
except (SSLError, Timeout, HTTPError):
return None
if not response.status_code == 200:
return None
Expand All @@ -178,7 +179,8 @@ def get_ci_text_search(search_term: str) -> Optional[list[Optional[dict]]]:
# We have to use the old CI domain since this API is still not available on
# cantusindex.uwaterloo.ca. Once it's available, we can use get_json_from_ci_api
# json: Union[dict, list, None] = get_json_from_ci_api(uri)
uri: str = f"https://cantusindex.org/json-text/{search_term}"
endpoint_path: str = f"/json-text/{search_term}"
uri: str = f"{OLD_CANTUS_INDEX_DOMAIN}{endpoint_path}"
try:
response: requests.Response = requests.get(
uri,
Expand Down
Loading
Loading