1- from typing import Dict , Any
1+ from typing import Any
22
33import pytest
44
55from deepset_mcp .api .exceptions import UnexpectedAPIError
6- from deepset_mcp .api .haystack_service .resource import HaystackServiceResource
7- from deepset_mcp .tools .component import list_component_families
6+ from deepset_mcp .tools .haystack_service import list_component_families
87from test .unit .conftest import BaseFakeClient
98
109
11- class FakeHaystackServiceResource (HaystackServiceResource ):
12- def __init__ (self , get_component_schemas_response : Dict [str , Any ] | None = None , exception : Exception | None = None ):
10+ class FakeHaystackServiceResource :
11+ def __init__ (
12+ self , get_component_schemas_response : dict [str , Any ] | None = None , exception : Exception | None = None
13+ ):
1314 self ._get_component_schemas_response = get_component_schemas_response
1415 self ._exception = exception
1516
16- async def get_component_schemas (self ) -> Dict [str , Any ]:
17+ async def get_component_schemas (self ) -> dict [str , Any ]:
1718 if self ._exception :
1819 raise self ._exception
1920 if self ._get_component_schemas_response is not None :
@@ -30,23 +31,9 @@ def haystack_service(self) -> FakeHaystackServiceResource:
3031 return self ._resource
3132
3233
33- @pytest .mark .asyncio
34- async def test_list_component_families_empty_response () -> None :
35- resource = FakeHaystackServiceResource (get_component_schemas_response = {})
36- client = FakeClient (resource )
37- result = await list_component_families (client )
38- assert "unexpected response structure" in result
39-
40-
4134@pytest .mark .asyncio
4235async def test_list_component_families_no_families () -> None :
43- response = {
44- "component_schema" : {
45- "definitions" : {
46- "Components" : {}
47- }
48- }
49- }
36+ response : dict [str , Any ] = {"component_schema" : {"definitions" : {"Components" : {}}}}
5037 resource = FakeHaystackServiceResource (get_component_schemas_response = response )
5138 client = FakeClient (resource )
5239 result = await list_component_families (client )
@@ -60,38 +47,21 @@ async def test_list_component_families_success() -> None:
6047 "definitions" : {
6148 "Components" : {
6249 "Component1" : {
63- "properties" : {
64- "type" : {
65- "family" : "converters" ,
66- "family_description" : "Convert data format"
67- }
68- }
69- },
70- "Component2" : {
71- "properties" : {
72- "type" : {
73- "family" : "readers" ,
74- "family_description" : "Read data"
75- }
76- }
50+ "properties" : {"type" : {"family" : "converters" , "family_description" : "Convert data format" }}
7751 },
52+ "Component2" : {"properties" : {"type" : {"family" : "readers" , "family_description" : "Read data" }}},
7853 # Should be ignored - same family as Component1
7954 "Component3" : {
80- "properties" : {
81- "type" : {
82- "family" : "converters" ,
83- "family_description" : "Convert data format"
84- }
85- }
86- }
55+ "properties" : {"type" : {"family" : "converters" , "family_description" : "Convert data format" }}
56+ },
8757 }
8858 }
8959 }
9060 }
9161 resource = FakeHaystackServiceResource (get_component_schemas_response = response )
9262 client = FakeClient (resource )
9363 result = await list_component_families (client )
94-
64+
9565 assert "Available Haystack component families" in result
9666 assert "**converters**" in result
9767 assert "Convert data format" in result
@@ -108,12 +78,3 @@ async def test_list_component_families_api_error() -> None:
10878 result = await list_component_families (client )
10979 assert "Failed to retrieve component families" in result
11080 assert "API Error" in result
111-
112-
113- @pytest .mark .asyncio
114- async def test_list_component_families_unexpected_error () -> None :
115- resource = FakeHaystackServiceResource (exception = ValueError ("Unexpected error" ))
116- client = FakeClient (resource )
117- result = await list_component_families (client )
118- assert "An unexpected error occurred" in result
119- assert "Unexpected error" in result
0 commit comments