Skip to content

Commit eded2ae

Browse files
committed
AI-1172 test: update tests wrt merge and add other testing values
1 parent bdb322d commit eded2ae

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

integtests/tools/test_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from integtests.conftest import BucketDef, ConfigDef, TableDef
77
from keboola_mcp_server.client import KeboolaClient
8-
from keboola_mcp_server.tools.search import GlobalSearchOutput, global_search
8+
from keboola_mcp_server.tools.search import GlobalSearchOutput, find_ids_by_name
99

1010
LOG = logging.getLogger(__name__)
1111

@@ -29,7 +29,7 @@ async def test_global_search_end_to_end(
2929
pytest.skip('Global search is not available. Please enable it in the project settings.')
3030

3131
# Search for test items by name prefix 'test' which should match our test data
32-
result = await global_search(
32+
result = await find_ids_by_name(
3333
ctx=mcp_context, name_prefixes=['test'], item_types=tuple(), limit=50, offset=0 # Search all types
3434
)
3535

tests/tools/test_search.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
DEFAULT_GLOBAL_SEARCH_LIMIT,
1111
GlobalSearchOutput,
1212
ItemsGroup,
13-
global_search,
13+
find_ids_by_name,
1414
)
1515

1616

@@ -234,6 +234,20 @@ def test_from_api_responses(self, parsed_global_search_response):
234234
# Check group counts
235235
for group in result.groups.values():
236236
assert group.count == 1
237+
if group.type == 'table':
238+
assert group.items[0].additional_info['bucket_id'] is not None
239+
assert group.items[0].additional_info['bucket_name'] is not None
240+
elif group.type == 'configuration':
241+
assert group.items[0].additional_info['component_id'] is not None
242+
assert group.items[0].additional_info['component_name'] is not None
243+
elif group.type == 'configuration-row':
244+
assert group.items[0].additional_info['component_id'] is not None
245+
assert group.items[0].additional_info['component_name'] is not None
246+
assert group.items[0].additional_info['configuration_id'] is not None
247+
assert group.items[0].additional_info['configuration_name'] is not None
248+
elif group.type == 'flow':
249+
assert group.items[0].additional_info['component_id'] is not None
250+
assert group.items[0].additional_info['component_name'] is not None
237251

238252
def test_from_api_responses_empty(self):
239253
"""Test creating answer from empty API response."""
@@ -246,11 +260,11 @@ def test_from_api_responses_empty(self):
246260

247261

248262
class TestGlobalSearchTool:
249-
"""Test cases for the global_search tool function."""
263+
"""Test cases for the find_ids_by_name tool function."""
250264

251265
@pytest.mark.asyncio
252266
async def test_global_search_success(
253-
self, mocker: MockerFixture, mcp_context_client: Context, mock_global_search_response
267+
self, mocker: MockerFixture, mcp_context_client: Context, mock_global_search_response: dict[str, Any]
254268
):
255269
"""Test successful global search."""
256270
keboola_client = KeboolaClient.from_state(mcp_context_client.session.state)
@@ -259,7 +273,7 @@ async def test_global_search_success(
259273
mock_response = GlobalSearchResponse.model_validate(mock_global_search_response)
260274
keboola_client.storage_client.global_search = mocker.AsyncMock(return_value=mock_response)
261275

262-
result = await global_search(
276+
result = await find_ids_by_name(
263277
ctx=mcp_context_client,
264278
name_prefixes=['test', 'table'],
265279
item_types=('table', 'configuration'),
@@ -270,6 +284,16 @@ async def test_global_search_success(
270284
assert isinstance(result, GlobalSearchOutput)
271285
assert result.counts['table'] == 1
272286
assert result.counts['configuration'] == 1
287+
assert result.counts['configuration-row'] == 1
288+
assert result.counts['flow'] == 1
289+
assert len(result.groups['table'].items) == 1
290+
assert len(result.groups['configuration'].items) == 1
291+
assert result.groups['configuration-row'].count == 1
292+
assert result.groups['flow'].count == 1
293+
assert result.groups['table'].items[0].id == mock_response.items[0].id
294+
assert result.groups['configuration'].items[0].id == mock_response.items[1].id
295+
assert result.groups['configuration-row'].items[0].id == mock_response.items[2].id
296+
assert result.groups['flow'].items[0].id == mock_response.items[3].id
273297

274298
# Verify the storage client was called with correct parameters
275299
keboola_client.storage_client.global_search.assert_called_once_with(
@@ -287,7 +311,7 @@ async def test_global_search_default_parameters(
287311
mock_response = GlobalSearchResponse.model_validate(mock_global_search_response)
288312
keboola_client.storage_client.global_search = mocker.AsyncMock(return_value=mock_response)
289313

290-
result = await global_search(ctx=mcp_context_client, name_prefixes=['test'])
314+
result = await find_ids_by_name(ctx=mcp_context_client, name_prefixes=['test'])
291315

292316
assert isinstance(result, GlobalSearchOutput)
293317

@@ -308,7 +332,7 @@ async def test_global_search_limit_out_of_range(
308332
keboola_client.storage_client.global_search = mocker.AsyncMock(return_value=mock_response)
309333

310334
# Test with limit too high
311-
await global_search(ctx=mcp_context_client, name_prefixes=['test'], limit=200)
335+
await find_ids_by_name(ctx=mcp_context_client, name_prefixes=['test'], limit=200)
312336

313337
# Should use default limit
314338
keboola_client.storage_client.global_search.assert_called_with(
@@ -317,7 +341,7 @@ async def test_global_search_limit_out_of_range(
317341

318342
# Test with limit too low
319343
keboola_client.storage_client.global_search.reset_mock()
320-
await global_search(ctx=mcp_context_client, name_prefixes=['test'], limit=0)
344+
await find_ids_by_name(ctx=mcp_context_client, name_prefixes=['test'], limit=0)
321345

322346
# Should use default limit
323347
keboola_client.storage_client.global_search.assert_called_with(
@@ -335,7 +359,7 @@ async def test_global_search_negative_offset(
335359
mock_response = GlobalSearchResponse.model_validate(mock_global_search_response)
336360
keboola_client.storage_client.global_search = mocker.AsyncMock(return_value=mock_response)
337361

338-
await global_search(ctx=mcp_context_client, name_prefixes=['test'], offset=-10)
362+
await find_ids_by_name(ctx=mcp_context_client, name_prefixes=['test'], offset=-10)
339363

340364
# Should use offset 0
341365
keboola_client.storage_client.global_search.assert_called_once_with(
@@ -349,7 +373,7 @@ async def test_global_search_feature_not_enabled(self, mocker: MockerFixture, mc
349373
keboola_client.storage_client.is_enabled = mocker.AsyncMock(return_value=False)
350374

351375
with pytest.raises(ValueError, match='Global search is not enabled'):
352-
await global_search(ctx=mcp_context_client, name_prefixes=['test'])
376+
await find_ids_by_name(ctx=mcp_context_client, name_prefixes=['test'])
353377

354378
@pytest.mark.asyncio
355379
async def test_global_search_joins_prefixes(
@@ -362,7 +386,7 @@ async def test_global_search_joins_prefixes(
362386
mock_response = GlobalSearchResponse.model_validate(mock_global_search_response)
363387
keboola_client.storage_client.global_search = mocker.AsyncMock(return_value=mock_response)
364388

365-
await global_search(ctx=mcp_context_client, name_prefixes=['test', 'table', 'data'])
389+
await find_ids_by_name(ctx=mcp_context_client, name_prefixes=['test', 'table', 'data'])
366390

367391
# Should join with spaces
368392
keboola_client.storage_client.global_search.assert_called_once_with(
@@ -380,7 +404,7 @@ async def test_global_search_with_valid_limit(
380404
mock_response = GlobalSearchResponse.model_validate(mock_global_search_response)
381405
keboola_client.storage_client.global_search = mocker.AsyncMock(return_value=mock_response)
382406

383-
await global_search(ctx=mcp_context_client, name_prefixes=['test'], limit=75)
407+
await find_ids_by_name(ctx=mcp_context_client, name_prefixes=['test'], limit=75)
384408

385409
# Should use the provided limit
386410
keboola_client.storage_client.global_search.assert_called_once_with(

0 commit comments

Comments
 (0)