|
5 | 5 | from hyperbrowser.models import ( |
6 | 6 | FetchOutputOptions, |
7 | 7 | FetchParams, |
| 8 | + GetBatchFetchJobParams, |
| 9 | + GetWebCrawlJobParams, |
8 | 10 | StartBatchFetchJobParams, |
9 | 11 | StartWebCrawlJobParams, |
10 | 12 | WebSearchParams, |
@@ -85,6 +87,34 @@ def test_build_web_crawl_start_payload_returns_serialized_payload(): |
85 | 87 | assert payload["url"] == "https://example.com" |
86 | 88 |
|
87 | 89 |
|
| 90 | +def test_build_batch_fetch_get_params_returns_serialized_payload(): |
| 91 | + payload = web_payload_utils.build_batch_fetch_get_params( |
| 92 | + GetBatchFetchJobParams(page=2, batch_size=50) |
| 93 | + ) |
| 94 | + |
| 95 | + assert payload == {"page": 2, "batchSize": 50} |
| 96 | + |
| 97 | + |
| 98 | +def test_build_batch_fetch_get_params_uses_default_params(): |
| 99 | + payload = web_payload_utils.build_batch_fetch_get_params() |
| 100 | + |
| 101 | + assert payload == {} |
| 102 | + |
| 103 | + |
| 104 | +def test_build_web_crawl_get_params_returns_serialized_payload(): |
| 105 | + payload = web_payload_utils.build_web_crawl_get_params( |
| 106 | + GetWebCrawlJobParams(page=3, batch_size=25) |
| 107 | + ) |
| 108 | + |
| 109 | + assert payload == {"page": 3, "batchSize": 25} |
| 110 | + |
| 111 | + |
| 112 | +def test_build_web_crawl_get_params_uses_default_params(): |
| 113 | + payload = web_payload_utils.build_web_crawl_get_params() |
| 114 | + |
| 115 | + assert payload == {} |
| 116 | + |
| 117 | + |
88 | 118 | def test_build_web_crawl_start_payload_invokes_schema_injection( |
89 | 119 | monkeypatch: pytest.MonkeyPatch, |
90 | 120 | ): |
@@ -155,3 +185,27 @@ def model_dump(self, **kwargs): # noqa: ARG002 |
155 | 185 | web_payload_utils.build_web_crawl_start_payload(_BrokenWebCrawlParams()) # type: ignore[arg-type] |
156 | 186 |
|
157 | 187 | assert exc_info.value.original_error is None |
| 188 | + |
| 189 | + |
| 190 | +def test_build_batch_fetch_get_params_wraps_runtime_model_dump_failures(): |
| 191 | + class _BrokenBatchFetchGetParams: |
| 192 | + def model_dump(self, **kwargs): # noqa: ARG002 |
| 193 | + raise RuntimeError("boom") |
| 194 | + |
| 195 | + with pytest.raises( |
| 196 | + HyperbrowserError, match="Failed to serialize batch fetch get params" |
| 197 | + ) as exc_info: |
| 198 | + web_payload_utils.build_batch_fetch_get_params(_BrokenBatchFetchGetParams()) # type: ignore[arg-type] |
| 199 | + |
| 200 | + assert isinstance(exc_info.value.original_error, RuntimeError) |
| 201 | + |
| 202 | + |
| 203 | +def test_build_web_crawl_get_params_preserves_hyperbrowser_model_dump_failures(): |
| 204 | + class _BrokenWebCrawlGetParams: |
| 205 | + def model_dump(self, **kwargs): # noqa: ARG002 |
| 206 | + raise HyperbrowserError("custom dump failure") |
| 207 | + |
| 208 | + with pytest.raises(HyperbrowserError, match="custom dump failure") as exc_info: |
| 209 | + web_payload_utils.build_web_crawl_get_params(_BrokenWebCrawlGetParams()) # type: ignore[arg-type] |
| 210 | + |
| 211 | + assert exc_info.value.original_error is None |
0 commit comments