22#
33# SPDX-License-Identifier: Apache-2.0
44
5+ from typing import Any
6+
57import pytest
68
79from deepset_mcp .api .custom_components .models import (
810 CustomComponentInstallation ,
9- CustomComponentInstallationList ,
1011)
1112from deepset_mcp .api .exceptions import UnexpectedAPIError
12- from deepset_mcp .api .shared_models import DeepsetUser
13+ from deepset_mcp .api .shared_models import DeepsetUser , PaginatedResponse
1314from deepset_mcp .tools .custom_components import (
1415 get_latest_custom_component_installation_logs ,
1516 list_custom_component_installations ,
2021class FakeCustomComponentsResource :
2122 def __init__ (
2223 self ,
23- installations_response : CustomComponentInstallationList | None = None ,
24+ installations_response : PaginatedResponse [ CustomComponentInstallation ] | None = None ,
2425 latest_logs_response : str | None = None ,
2526 exception : Exception | None = None ,
2627 ):
@@ -29,8 +30,8 @@ def __init__(
2930 self ._exception = exception
3031
3132 async def list_installations (
32- self , limit : int = 20 , page_number : int = 1 , field : str = "created_at" , order : str = "DESC"
33- ) -> CustomComponentInstallationList :
33+ self , limit : int = 20 , after : str | None = None , field : str = "created_at" , order : str = "DESC"
34+ ) -> PaginatedResponse [ CustomComponentInstallation ] :
3435 if self ._exception :
3536 raise self ._exception
3637 if self ._installations_response is not None :
@@ -84,7 +85,7 @@ def users(self) -> FakeUserResource:
8485@pytest .mark .asyncio
8586async def test_list_custom_component_installations () -> None :
8687 """Test listing custom component installations."""
87- mock_installations = CustomComponentInstallationList (
88+ mock_installations = PaginatedResponse [ CustomComponentInstallation ] (
8889 data = [
8990 CustomComponentInstallation (
9091 custom_component_id = "comp_123" ,
@@ -134,7 +135,7 @@ async def test_list_custom_component_installations() -> None:
134135
135136 result = await list_custom_component_installations (client = client , workspace = "test-workspace" )
136137
137- assert isinstance (result , CustomComponentInstallationList )
138+ assert isinstance (result , PaginatedResponse )
138139 assert len (result .data ) == 2
139140 assert result .total == 2
140141 assert result .has_more is False
@@ -168,7 +169,7 @@ async def test_list_custom_component_installations() -> None:
168169@pytest .mark .asyncio
169170async def test_list_custom_component_installations_empty () -> None :
170171 """Test listing custom component installations when none exist."""
171- mock_installations = CustomComponentInstallationList (
172+ mock_installations = PaginatedResponse [ CustomComponentInstallation ] (
172173 data = [],
173174 total = 0 ,
174175 has_more = False ,
@@ -183,7 +184,7 @@ async def test_list_custom_component_installations_empty() -> None:
183184
184185 result = await list_custom_component_installations (client = client , workspace = "test-workspace" )
185186
186- assert isinstance (result , CustomComponentInstallationList )
187+ assert isinstance (result , PaginatedResponse )
187188 assert len (result .data ) == 0
188189 assert result .total == 0
189190 assert result .has_more is False
@@ -192,7 +193,7 @@ async def test_list_custom_component_installations_empty() -> None:
192193@pytest .mark .asyncio
193194async def test_list_custom_component_installations_user_fetch_error () -> None :
194195 """Test listing custom component installations when user fetch fails."""
195- mock_installations = CustomComponentInstallationList (
196+ mock_installations = PaginatedResponse [ CustomComponentInstallation ] (
196197 data = [
197198 CustomComponentInstallation (
198199 custom_component_id = "comp_123" ,
@@ -216,7 +217,7 @@ async def test_list_custom_component_installations_user_fetch_error() -> None:
216217
217218 result = await list_custom_component_installations (client = client , workspace = "test-workspace" )
218219
219- assert isinstance (result , CustomComponentInstallationList )
220+ assert isinstance (result , PaginatedResponse )
220221 assert len (result .data ) == 1
221222 assert result .data [0 ].created_by_user_id == "user_unknown"
222223 assert result .data [0 ].user_info is None # User fetch failed, so user_info should be None
@@ -271,3 +272,62 @@ async def test_get_latest_custom_component_installation_logs_api_error() -> None
271272
272273 result = await get_latest_custom_component_installation_logs (client = client , workspace = "test-workspace" )
273274 assert result == "Failed to retrieve latest installation logs: API Error (Status Code: 500)"
275+
276+
277+ @pytest .mark .asyncio
278+ async def test_list_custom_component_installations_with_pagination_params () -> None :
279+ """Test listing custom component installations with pagination parameters."""
280+ mock_installations = PaginatedResponse [CustomComponentInstallation ](
281+ data = [
282+ CustomComponentInstallation (
283+ custom_component_id = "comp_123" ,
284+ status = "installed" ,
285+ version = "1.0.0" ,
286+ created_by_user_id = "user_123" ,
287+ organization_id = "org-123" ,
288+ logs = [{"level" : "INFO" , "msg" : "Installation complete" }],
289+ )
290+ ],
291+ total = 1 ,
292+ has_more = False ,
293+ )
294+
295+ # Create a custom resource that tracks the parameters passed
296+ class TrackingCustomComponentsResource (FakeCustomComponentsResource ):
297+ def __init__ (self , installations_response : PaginatedResponse [CustomComponentInstallation ]) -> None :
298+ super ().__init__ (installations_response = installations_response )
299+ self .called_with : dict [str , Any ] = {}
300+
301+ async def list_installations (
302+ self , limit : int = 20 , after : str | None = None , field : str = "created_at" , order : str = "DESC"
303+ ) -> PaginatedResponse [CustomComponentInstallation ]:
304+ self .called_with = {"limit" : limit , "after" : after , "field" : field , "order" : order }
305+ return await super ().list_installations (limit , after , field , order )
306+
307+ custom_components_resource = TrackingCustomComponentsResource (installations_response = mock_installations )
308+ user_resource = FakeUserResource (
309+ users = {
310+ "user_123" : DeepsetUser (
311+ user_id = "user_123" , given_name = "John" , family_name = "Doe" , email = "john.doe@example.com"
312+ )
313+ }
314+ )
315+ client = FakeClient (
316+ custom_components_resource = custom_components_resource ,
317+ user_resource = user_resource ,
318+ )
319+
320+ # Test with custom parameters
321+ result = await list_custom_component_installations (
322+ client = client , workspace = "test-workspace" , limit = 50 , after = "cursor_123"
323+ )
324+
325+ # Verify the parameters were passed correctly
326+ assert custom_components_resource .called_with ["limit" ] == 50
327+ assert custom_components_resource .called_with ["after" ] == "cursor_123"
328+ assert custom_components_resource .called_with ["field" ] == "created_at" # default
329+ assert custom_components_resource .called_with ["order" ] == "DESC" # default
330+
331+ # Verify the result
332+ assert isinstance (result , PaginatedResponse )
333+ assert len (result .data ) == 1
0 commit comments