diff --git a/service/src/main/inse/projects/test_eu_cordis_search_client.py b/service/src/main/inse/projects/test_eu_cordis_search_client.py index f6e7d5c3..a596f9ed 100644 --- a/service/src/main/inse/projects/test_eu_cordis_search_client.py +++ b/service/src/main/inse/projects/test_eu_cordis_search_client.py @@ -1,7 +1,18 @@ import pytest + +from inse import config from inse.projects import eu_cordis_projects_client as eu_cordis_search_client +requires_inse_elasticsearch = pytest.mark.skipif( + not ( + config.settings.elasticsearch_inse_url + and config.settings.elasticsearch_inse_api_key + ), + reason="INSE Elasticsearch is not configured", +) + + @pytest.mark.anyio async def test_active_period_filter_matches_projects_overlapping_interval(): query, _, _ = await eu_cordis_search_client._build_eu_cordis_search_query( @@ -18,6 +29,7 @@ async def test_active_period_filter_matches_projects_overlapping_interval(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_title(): """Test searching EU CORDIS projects by title.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -35,6 +47,7 @@ async def test_search_eu_cordis_projects_by_title(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_keywords(): """Test searching EU CORDIS projects by keywords.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -51,6 +64,7 @@ async def test_search_eu_cordis_projects_by_keywords(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_framework_programme(): """Test filtering EU CORDIS projects by framework programme.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -67,6 +81,7 @@ async def test_search_eu_cordis_projects_by_framework_programme(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_status(): """Test filtering EU CORDIS projects by status.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -83,6 +98,7 @@ async def test_search_eu_cordis_projects_by_status(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_funding_years(): """Test filtering EU CORDIS projects by funding start years.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -101,6 +117,7 @@ async def test_search_eu_cordis_projects_by_funding_years(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_country(): """Test filtering EU CORDIS projects by country.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -120,6 +137,7 @@ async def test_search_eu_cordis_projects_by_country(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_organization_name(): """Test filtering EU CORDIS projects by organization name.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -139,6 +157,7 @@ async def test_search_eu_cordis_projects_by_organization_name(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_organization_id(): """Test filtering EU CORDIS projects by organization ID.""" # Use a known organization ID (e.g., Max Planck Society) @@ -160,6 +179,7 @@ async def test_search_eu_cordis_projects_by_organization_id(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_project_type(): """Test filtering EU CORDIS projects by project type (FP7, H2020, HEU).""" from inse.projects.model import EuCordisProjectType @@ -192,6 +212,7 @@ async def test_search_eu_cordis_projects_by_project_type(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_with_sorting(): """Test sorting EU CORDIS projects.""" # Test ascending sort by title @@ -222,6 +243,7 @@ async def test_search_eu_cordis_projects_with_sorting(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_pagination(): """Test pagination of EU CORDIS project search results.""" # Get first page @@ -251,6 +273,7 @@ async def test_search_eu_cordis_projects_pagination(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_get_enriched_cordis_project_by_id(): """Test fetching an enriched EU CORDIS project by ID.""" # Use a known project ID (e.g., an H2020 project) @@ -269,6 +292,7 @@ async def test_get_enriched_cordis_project_by_id(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_get_enriched_cordis_project_by_id_not_found(): """Test fetching a non-existent EU CORDIS project.""" project = await eu_cordis_search_client.get_enriched_cordis_project_by_id("nonexistent_id") @@ -286,6 +310,7 @@ async def test_get_enriched_cordis_project_by_id_empty(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_get_dois_by_cordis_eu_project_id(): """Test retrieving DOIs for a CORDIS EU project.""" known_id = "101016442" # Example H2020 project ID @@ -295,6 +320,7 @@ async def test_get_dois_by_cordis_eu_project_id(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_get_openalex_authors_for_cordis_project_ids(): """Test retrieving OpenAlex authors for CORDIS project IDs.""" project_ids = ["101016442"] # Example H2020 project ID @@ -312,6 +338,7 @@ async def test_get_openalex_authors_for_cordis_project_ids(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_with_multiple_filters(): """Test combining multiple filters in EU CORDIS project search.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -334,6 +361,7 @@ async def test_search_eu_cordis_projects_with_multiple_filters(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_empty_results(): """Test search that should return no results.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -347,6 +375,7 @@ async def test_search_eu_cordis_projects_empty_results(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_by_funding_scheme(): """Test filtering EU CORDIS projects by funding scheme.""" res = await eu_cordis_search_client.search_eu_cordis_projects( @@ -363,6 +392,7 @@ async def test_search_eu_cordis_projects_by_funding_scheme(): @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_eu_cordis_projects_with_fuzzy_topic_search(): """Test fuzzy search with OpenAlex topic IDs.""" # This test requires known OpenAlex topic IDs diff --git a/service/src/main/inse/projects/test_projects_dfg.py b/service/src/main/inse/projects/test_projects_dfg.py index bc331c62..ac7cc3c2 100644 --- a/service/src/main/inse/projects/test_projects_dfg.py +++ b/service/src/main/inse/projects/test_projects_dfg.py @@ -2,10 +2,21 @@ from unittest.mock import AsyncMock, patch import pytest +from inse import config from inse.projects import projects_search_client +requires_inse_elasticsearch = pytest.mark.skipif( + not ( + config.settings.elasticsearch_inse_url + and config.settings.elasticsearch_inse_api_key + ), + reason="INSE Elasticsearch is not configured", +) + + @pytest.mark.anyio +@requires_inse_elasticsearch async def test_search_dfg_projects(): # Test search with name res = await projects_search_client.search_dfg_projects( @@ -51,6 +62,7 @@ async def test_search_dfg_projects_returns_empty_page_without_enrichment_crash() @pytest.mark.anyio +@requires_inse_elasticsearch async def test_get_dfg_project_by_id(): # Get by ID of the project we found or a known one known_id = 164008977 diff --git a/service/src/main/inse/works/test_search_client.py b/service/src/main/inse/works/test_search_client.py index 83405f9f..c427d1ee 100644 --- a/service/src/main/inse/works/test_search_client.py +++ b/service/src/main/inse/works/test_search_client.py @@ -179,7 +179,7 @@ from unittest.mock import AsyncMock, patch async def test_search_author_works_passes_institution_filter_to_query(): with patch("inse.integrations.elasticsearch.search", new_callable=AsyncMock) as mock_search: mock_search.return_value = {"hits": {"total": {"value": 1}, "hits": []}} - client = OpenAlexWorksSearchClient(index="openalex-works") + client = OpenAlexWorksSearchClient(index="openalex-works", api_key="test-key") await client.search_author_works( "A5023888391", @@ -201,7 +201,7 @@ async def test_search_author_works_passes_institution_filter_to_query(): async def test_search_author_works_passes_topic_filter_to_query(): with patch("inse.integrations.elasticsearch.search", new_callable=AsyncMock) as mock_search: mock_search.return_value = {"hits": {"total": {"value": 1}, "hits": []}} - client = OpenAlexWorksSearchClient(index="openalex-works") + client = OpenAlexWorksSearchClient(index="openalex-works", api_key="test-key") await client.search_author_works( "A5023888391", @@ -243,7 +243,7 @@ async def test_search_author_works_passes_topic_filter_to_query(): async def test_search_author_works_calls_elasticsearch_index_with_api_key(): with patch("inse.integrations.elasticsearch.search", new_callable=AsyncMock) as mock_search: mock_search.return_value = {"hits": {"total": {"value": 0}, "hits": []}} - client = OpenAlexWorksSearchClient(index="openalex-works") + client = OpenAlexWorksSearchClient(index="openalex-works", api_key="test-key") result = await client.search_author_works("A5023888391", page=1, size=20) @@ -254,7 +254,7 @@ async def test_search_author_works_calls_elasticsearch_index_with_api_key(): async def test_search_work_filters_by_work_id(): with patch("inse.integrations.elasticsearch.search", new_callable=AsyncMock) as mock_search: mock_search.return_value = {"hits": {"total": {"value": 1}, "hits": []}} - client = OpenAlexWorksSearchClient(index="openalex-works") + client = OpenAlexWorksSearchClient(index="openalex-works", api_key="test-key") await client.search_work("W2741809807")