From b09350c052f089389d60aca903d63c9bdc9c5e95 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 28 Feb 2023 22:08:26 -0600 Subject: [PATCH] Fix to return only enabled content types via the new config/types API - Previously was return all core content types even if they had not been setup - Add test to validate only configured content types are returned by the api/config/types API endpoint --- src/khoj/routers/api.py | 2 +- tests/test_client.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/khoj/routers/api.py b/src/khoj/routers/api.py index ad6d9919..b9f2a3b8 100644 --- a/src/khoj/routers/api.py +++ b/src/khoj/routers/api.py @@ -32,7 +32,7 @@ def get_config_types(): return [ search_type.value for search_type in SearchType - if any(search_type.value == configured_content_type[0] for configured_content_type in state.config.content_type) + if any(search_type.value == ctype[0] and ctype[1] for ctype in state.config.content_type) or search_type.name in state.config.content_type.plugins.keys() ] diff --git a/tests/test_client.py b/tests/test_client.py index 95e31048..c9510c82 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -76,6 +76,16 @@ def test_regenerate_with_valid_content_type(client): assert response.status_code == 200 +# ---------------------------------------------------------------------------------------------------- +def test_get_configured_types_via_api(client): + # Act + response = client.get(f"/api/config/types") + + # Assert + assert response.status_code == 200 + assert response.json() == ["org", "image", "plugin1"] + + # ---------------------------------------------------------------------------------------------------- def test_image_search(client, content_config: ContentConfig, search_config: SearchConfig): # Arrange