File tree Expand file tree Collapse file tree
hyperbrowser/client/managers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010)
1111from ...web_payload_utils import build_batch_fetch_start_payload
1212from ...web_payload_utils import build_batch_fetch_get_params
13- from ...web_pagination_utils import initialize_paginated_job_response
13+ from ...web_pagination_utils import (
14+ initialize_paginated_job_response ,
15+ merge_paginated_page_response ,
16+ )
1417from ....polling import (
1518 build_fetch_operation_name ,
1619 build_operation_name ,
@@ -104,13 +107,7 @@ async def start_and_wait(
104107 )
105108
106109 def merge_page_response (page_response : BatchFetchJobResponse ) -> None :
107- if page_response .data :
108- job_response .data .extend (page_response .data )
109- job_response .current_page_batch = page_response .current_page_batch
110- job_response .total_pages = page_response .total_pages
111- job_response .total_page_batches = page_response .total_page_batches
112- job_response .batch_size = page_response .batch_size
113- job_response .error = page_response .error
110+ merge_paginated_page_response (job_response , page_response )
114111
115112 await collect_paginated_results_async (
116113 operation_name = operation_name ,
Original file line number Diff line number Diff line change 1010)
1111from ...web_payload_utils import build_web_crawl_start_payload
1212from ...web_payload_utils import build_web_crawl_get_params
13- from ...web_pagination_utils import initialize_paginated_job_response
13+ from ...web_pagination_utils import (
14+ initialize_paginated_job_response ,
15+ merge_paginated_page_response ,
16+ )
1417from ....polling import (
1518 build_fetch_operation_name ,
1619 build_operation_name ,
@@ -102,13 +105,7 @@ async def start_and_wait(
102105 )
103106
104107 def merge_page_response (page_response : WebCrawlJobResponse ) -> None :
105- if page_response .data :
106- job_response .data .extend (page_response .data )
107- job_response .current_page_batch = page_response .current_page_batch
108- job_response .total_pages = page_response .total_pages
109- job_response .total_page_batches = page_response .total_page_batches
110- job_response .batch_size = page_response .batch_size
111- job_response .error = page_response .error
108+ merge_paginated_page_response (job_response , page_response )
112109
113110 await collect_paginated_results_async (
114111 operation_name = operation_name ,
Original file line number Diff line number Diff line change 1010)
1111from ...web_payload_utils import build_batch_fetch_start_payload
1212from ...web_payload_utils import build_batch_fetch_get_params
13- from ...web_pagination_utils import initialize_paginated_job_response
13+ from ...web_pagination_utils import (
14+ initialize_paginated_job_response ,
15+ merge_paginated_page_response ,
16+ )
1417from ....polling import (
1518 build_fetch_operation_name ,
1619 build_operation_name ,
@@ -102,13 +105,7 @@ def start_and_wait(
102105 )
103106
104107 def merge_page_response (page_response : BatchFetchJobResponse ) -> None :
105- if page_response .data :
106- job_response .data .extend (page_response .data )
107- job_response .current_page_batch = page_response .current_page_batch
108- job_response .total_pages = page_response .total_pages
109- job_response .total_page_batches = page_response .total_page_batches
110- job_response .batch_size = page_response .batch_size
111- job_response .error = page_response .error
108+ merge_paginated_page_response (job_response , page_response )
112109
113110 collect_paginated_results (
114111 operation_name = operation_name ,
Original file line number Diff line number Diff line change 1010)
1111from ...web_payload_utils import build_web_crawl_start_payload
1212from ...web_payload_utils import build_web_crawl_get_params
13- from ...web_pagination_utils import initialize_paginated_job_response
13+ from ...web_pagination_utils import (
14+ initialize_paginated_job_response ,
15+ merge_paginated_page_response ,
16+ )
1417from ....polling import (
1518 build_fetch_operation_name ,
1619 build_operation_name ,
@@ -102,13 +105,7 @@ def start_and_wait(
102105 )
103106
104107 def merge_page_response (page_response : WebCrawlJobResponse ) -> None :
105- if page_response .data :
106- job_response .data .extend (page_response .data )
107- job_response .current_page_batch = page_response .current_page_batch
108- job_response .total_pages = page_response .total_pages
109- job_response .total_page_batches = page_response .total_page_batches
110- job_response .batch_size = page_response .batch_size
111- job_response .error = page_response .error
108+ merge_paginated_page_response (job_response , page_response )
112109
113110 collect_paginated_results (
114111 operation_name = operation_name ,
Original file line number Diff line number Diff line change 1- from typing import Type , TypeVar
1+ from typing import Any , Type , TypeVar
22
33T = TypeVar ("T" )
44
@@ -19,3 +19,13 @@ def initialize_paginated_job_response(
1919 totalPages = 0 ,
2020 batchSize = batch_size ,
2121 )
22+
23+
24+ def merge_paginated_page_response (job_response : Any , page_response : Any ) -> None :
25+ if page_response .data :
26+ job_response .data .extend (page_response .data )
27+ job_response .current_page_batch = page_response .current_page_batch
28+ job_response .total_pages = page_response .total_pages
29+ job_response .total_page_batches = page_response .total_page_batches
30+ job_response .batch_size = page_response .batch_size
31+ job_response .error = page_response .error
Original file line number Diff line number Diff line change 11from hyperbrowser .client .managers .web_pagination_utils import (
22 initialize_paginated_job_response ,
3+ merge_paginated_page_response ,
34)
45from hyperbrowser .models import BatchFetchJobResponse , WebCrawlJobResponse
56
@@ -35,3 +36,29 @@ def test_initialize_paginated_job_response_for_web_crawl_with_custom_batch_size(
3536 assert response .total_page_batches == 0
3637 assert response .total_pages == 0
3738 assert response .batch_size == 25
39+
40+
41+ def test_merge_paginated_page_response_merges_page_data_and_metadata ():
42+ job_response = initialize_paginated_job_response (
43+ model = BatchFetchJobResponse ,
44+ job_id = "job-1" ,
45+ status = "running" ,
46+ )
47+ page_response = BatchFetchJobResponse (
48+ jobId = "job-1" ,
49+ status = "running" ,
50+ data = [],
51+ currentPageBatch = 2 ,
52+ totalPageBatches = 4 ,
53+ totalPages = 10 ,
54+ batchSize = 100 ,
55+ error = "partial error" ,
56+ )
57+
58+ merge_paginated_page_response (job_response , page_response )
59+
60+ assert job_response .current_page_batch == 2
61+ assert job_response .total_page_batches == 4
62+ assert job_response .total_pages == 10
63+ assert job_response .batch_size == 100
64+ assert job_response .error == "partial error"
Original file line number Diff line number Diff line change @@ -36,9 +36,11 @@ def test_batch_fetch_managers_use_shared_start_payload_helper():
3636 assert "build_batch_fetch_start_payload(" in module_text
3737 assert "build_batch_fetch_get_params(" in module_text
3838 assert "initialize_paginated_job_response(" in module_text
39+ assert "merge_paginated_page_response(" in module_text
3940 assert "inject_web_output_schemas(" not in module_text
4041 assert "serialize_model_dump_to_dict(" not in module_text
4142 assert "BatchFetchJobResponse(" not in module_text
43+ assert "current_page_batch = page_response.current_page_batch" not in module_text
4244
4345
4446def test_web_crawl_managers_use_shared_start_payload_helper ():
@@ -47,6 +49,8 @@ def test_web_crawl_managers_use_shared_start_payload_helper():
4749 assert "build_web_crawl_start_payload(" in module_text
4850 assert "build_web_crawl_get_params(" in module_text
4951 assert "initialize_paginated_job_response(" in module_text
52+ assert "merge_paginated_page_response(" in module_text
5053 assert "inject_web_output_schemas(" not in module_text
5154 assert "serialize_model_dump_to_dict(" not in module_text
5255 assert "WebCrawlJobResponse(" not in module_text
56+ assert "current_page_batch = page_response.current_page_batch" not in module_text
You can’t perform that action at this time.
0 commit comments