|
3 | 3 | import pytest |
4 | 4 |
|
5 | 5 | from deepset_mcp.api.exceptions import UnexpectedAPIError |
6 | | -from deepset_mcp.tools.haystack_service import list_component_families |
| 6 | +from deepset_mcp.tools.haystack_service import get_component_definition, list_component_families |
7 | 7 | from test.unit.conftest import BaseFakeClient |
8 | 8 |
|
9 | 9 |
|
@@ -31,6 +31,76 @@ def haystack_service(self) -> FakeHaystackServiceResource: |
31 | 31 | return self._resource |
32 | 32 |
|
33 | 33 |
|
| 34 | +@pytest.mark.asyncio |
| 35 | +async def test_get_component_definition_success() -> None: |
| 36 | + # Sample component definition similar to the example provided |
| 37 | + component_type = "haystack.components.converters.xlsx.XLSXToDocument" |
| 38 | + response: dict[str, Any] = { |
| 39 | + "component_schema": { |
| 40 | + "definitions": { |
| 41 | + "Components": { |
| 42 | + "XLSXToDocument": { |
| 43 | + "title": "XLSXToDocument", |
| 44 | + "description": "Converts XLSX files into Documents.", |
| 45 | + "properties": { |
| 46 | + "type": { |
| 47 | + "const": component_type, |
| 48 | + "family": "converters", |
| 49 | + "family_description": "Convert data into a format your pipeline can query.", |
| 50 | + }, |
| 51 | + "init_parameters": { |
| 52 | + "properties": { |
| 53 | + "sheet_name": { |
| 54 | + "_annotation": "typing.Union[str, int, list, None]", |
| 55 | + "description": "The name of the sheet to read.", |
| 56 | + "default": None, |
| 57 | + }, |
| 58 | + "table_format": { |
| 59 | + "_annotation": "str", |
| 60 | + "description": "The format to convert the Excel file to.", |
| 61 | + "default": "csv", |
| 62 | + }, |
| 63 | + } |
| 64 | + }, |
| 65 | + }, |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + resource = FakeHaystackServiceResource(get_component_schemas_response=response) |
| 73 | + client = FakeClient(resource) |
| 74 | + result = await get_component_definition(client, component_type) |
| 75 | + |
| 76 | + # Check that all required information is present |
| 77 | + assert component_type in result |
| 78 | + assert "XLSXToDocument" in result |
| 79 | + assert "converters" in result |
| 80 | + assert "Convert data into a format" in result |
| 81 | + assert "sheet_name" in result |
| 82 | + assert "table_format" in result |
| 83 | + assert "default: csv" in result |
| 84 | + |
| 85 | + |
| 86 | +@pytest.mark.asyncio |
| 87 | +async def test_get_component_definition_not_found() -> None: |
| 88 | + response: dict[str, Any] = {"component_schema": {"definitions": {"Components": {}}}} |
| 89 | + resource = FakeHaystackServiceResource(get_component_schemas_response=response) |
| 90 | + client = FakeClient(resource) |
| 91 | + result = await get_component_definition(client, "nonexistent.component") |
| 92 | + assert "Component not found" in result |
| 93 | + |
| 94 | + |
| 95 | +@pytest.mark.asyncio |
| 96 | +async def test_get_component_definition_api_error() -> None: |
| 97 | + resource = FakeHaystackServiceResource(exception=UnexpectedAPIError(status_code=500, message="API Error")) |
| 98 | + client = FakeClient(resource) |
| 99 | + result = await get_component_definition(client, "some.component") |
| 100 | + assert "Failed to retrieve component definition" in result |
| 101 | + assert "API Error" in result |
| 102 | + |
| 103 | + |
34 | 104 | @pytest.mark.asyncio |
35 | 105 | async def test_list_component_families_no_families() -> None: |
36 | 106 | response: dict[str, Any] = {"component_schema": {"definitions": {"Components": {}}}} |
|
0 commit comments