Skip to content

Commit

Permalink
tests: contrib: Add test to search by ROR and country
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 authored and tmorrell committed Feb 25, 2025
1 parent 344b548 commit 3e9131d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
31 changes: 27 additions & 4 deletions tests/contrib/affiliations/test_affiliations_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ def _create_affiliations(service, identity):
"title": {
"en": "Northwestern University",
},
"identifiers": [{"identifier": "000e0be47", "scheme": "ror"}],
},
{
"acronym": "NU",
"id": "chnu",
"name": "Northwestern University",
"title": {
"en": "Northwestern University",
},
"country_name": "Switzerland",
},
{
"acronym": "LONG",
Expand All @@ -135,10 +145,10 @@ def test_affiliations_prefix_search(
"""Test a successful search."""
_create_affiliations(service, identity)

# Should show 1 result
# Should show 2 results
res = client.get(f"{prefix}?q=uni", headers=h)
assert res.status_code == 200
assert res.json["hits"]["total"] == 1
assert res.json["hits"]["total"] == 2


def test_affiliations_suggest_sort(
Expand All @@ -164,9 +174,10 @@ def test_affiliations_suggest_sort(
# Should show 2 results, but id=nu as first due to acronym
res = client.get(f"{prefix}?suggest=NU", headers=h)
assert res.status_code == 200
assert res.json["hits"]["total"] == 2
assert res.json["hits"]["total"] == 3
assert res.json["hits"]["hits"][0]["id"] == "nu"
assert res.json["hits"]["hits"][1]["id"] == "cern" # due to nucleaire
assert res.json["hits"]["hits"][1]["id"] == "chnu"
assert res.json["hits"]["hits"][2]["id"] == "cern" # due to nucleaire

# Should show a result and not error out for longer names
res = client.get(
Expand All @@ -176,3 +187,15 @@ def test_affiliations_suggest_sort(
assert res.status_code == 200
assert res.json["hits"]["total"] == 1
assert res.json["hits"]["hits"][0]["id"] == "LONG"

# Search affiliations with ROR ID
res = client.get(f"{prefix}?suggest=000e0be47", headers=h)
assert res.status_code == 200
assert res.json["hits"]["total"] == 1
assert res.json["hits"]["hits"][0]["id"] == "nu"

# Search affiliations with country
res = client.get(f"{prefix}?suggest=Switzerland", headers=h)
assert res.status_code == 200
assert res.json["hits"]["total"] == 1
assert res.json["hits"]["hits"][0]["id"] == "chnu"
7 changes: 7 additions & 0 deletions tests/contrib/funders/test_funders_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def example_funders(service, identity, indexer):
"en": "European Organization for Nuclear Research",
"fr": "Conseil Européen pour la Recherche Nucléaire",
},
"identifiers": [{"identifier": "01ggx4157", "scheme": "ror"}],
},
{"id": "0aaaaaa11", "name": "OTHER", "country": "CH", "title": {"en": "CERN"}},
{
Expand Down Expand Up @@ -144,6 +145,12 @@ def test_funders_suggest_sort(client, h, prefix, example_funders):
assert res.status_code == 200
assert res.json["hits"]["total"] == 0

# Search affiliations with identifier
res = client.get(f"{prefix}?suggest=01ggx4157", headers=h)
assert res.status_code == 200
assert res.json["hits"]["total"] == 1
assert res.json["hits"]["hits"][0]["name"] == "CERN"


def test_funders_delete(
client_with_credentials, h, prefix, identity, service, funder_full_data
Expand Down

0 comments on commit 3e9131d

Please sign in to comment.