11# SPDX-License-Identifier: Apache-2.0
22# Copyright 2022 Atlan Pte. Ltd.
3+ import math
34from dataclasses import dataclass , field
45from datetime import datetime
56from time import sleep , time
@@ -335,8 +336,6 @@ def _assert_search_results(results, expected_sorts, size, TOTAL_ASSETS, bulk=Fal
335336
336337@patch .object (LOGGER , "debug" )
337338def test_search_pagination (mock_logger , client : AtlanClient ):
338- size = 2
339-
340339 # Avoid testing on integration tests objects
341340 exclude_sdk_terms = [
342341 Asset .NAME .wildcard ("psdk_*" ),
@@ -352,13 +351,22 @@ def test_search_pagination(mock_logger, client: AtlanClient):
352351 dsl = DSL (
353352 query = query ,
354353 post_filter = Term .with_type_name (value = "AtlasGlossaryTerm" ),
355- size = size ,
354+ size = 0 , # to get the total count
356355 )
356+
357357 request = IndexSearchRequest (dsl = dsl )
358358 results = client .asset .search (criteria = request )
359359 # Assigning this here to ensure the total assets
360360 # remain constant across different test cases
361361 TOTAL_ASSETS = results .count
362+
363+ # set page_size to divide into ~5 API calls
364+ size = max (1 , math .ceil (TOTAL_ASSETS / 5 ))
365+ request .dsl .size = size
366+
367+ # Now, we can test different test scenarios for search() with the dynamic page size
368+ results = client .asset .search (criteria = request )
369+
362370 expected_sorts = [Asset .GUID .order (SortOrder .ASCENDING )]
363371 _assert_search_results (results , expected_sorts , size , TOTAL_ASSETS )
364372
@@ -385,7 +393,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
385393 FluentSearch (where_nots = exclude_sdk_terms )
386394 .where (CompoundQuery .active_assets ())
387395 .where (CompoundQuery .asset_type (AtlasGlossaryTerm ))
388- .page_size (2 )
396+ .page_size (size )
389397 ).to_request ()
390398 results = client .asset .search (criteria = request )
391399 expected_sorts = [Asset .GUID .order (SortOrder .ASCENDING )]
@@ -396,7 +404,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
396404 FluentSearch (where_nots = exclude_sdk_terms )
397405 .where (CompoundQuery .active_assets ())
398406 .where (CompoundQuery .asset_type (AtlasGlossaryTerm ))
399- .page_size (2 )
407+ .page_size (size )
400408 ).to_request ()
401409 results = client .asset .search (criteria = request , bulk = True )
402410 expected_sorts = [
@@ -413,7 +421,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
413421 FluentSearch (where_nots = exclude_sdk_terms )
414422 .where (CompoundQuery .active_assets ())
415423 .where (CompoundQuery .asset_type (AtlasGlossaryTerm ))
416- .page_size (2 )
424+ .page_size (size )
417425 ).execute (client , bulk = True )
418426 expected_sorts = [
419427 Asset .CREATE_TIME .order (SortOrder .ASCENDING ),
@@ -431,7 +439,7 @@ def test_search_pagination(mock_logger, client: AtlanClient):
431439 FluentSearch (where_nots = exclude_sdk_terms )
432440 .where (CompoundQuery .active_assets ())
433441 .where (CompoundQuery .asset_type (AtlasGlossaryTerm ))
434- .page_size (2 )
442+ .page_size (size )
435443 ).to_request ()
436444 results = client .asset .search (criteria = request )
437445 expected_sorts = [
0 commit comments