Skip to content

Commit

Permalink
Merge pull request #1552 from lucasmarchd01/issue-1391
Browse files Browse the repository at this point in the history
Add tests for `CISearchView` and cantus index functions
  • Loading branch information
lucasmarchd01 authored Jun 21, 2024
2 parents 6da51fa + da68ff5 commit 653bf52
Show file tree
Hide file tree
Showing 5 changed files with 495 additions and 8 deletions.
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

0 comments on commit 653bf52

Please sign in to comment.