Skip to content

Commit cbccec7

Browse files
Centralize shared web manager route constants
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 50ec856 commit cbccec7

File tree

10 files changed

+63
-13
lines changed

10 files changed

+63
-13
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ This runs lint, format checks, compile checks, tests, and package build.
134134
- `tests/test_tool_mapping_reader_usage.py` (tools mapping-helper usage),
135135
- `tests/test_type_utils_usage.py` (type `__mro__` boundary centralization in `hyperbrowser/type_utils.py`),
136136
- `tests/test_web_pagination_internal_reuse.py` (web pagination helper internal reuse of shared job pagination helpers),
137-
- `tests/test_web_payload_helper_usage.py` (web manager payload-helper usage enforcement).
137+
- `tests/test_web_payload_helper_usage.py` (web manager payload-helper usage enforcement),
138+
- `tests/test_web_route_constants_usage.py` (web manager route-constant usage enforcement).
138139

139140
## Code quality conventions
140141

hyperbrowser/client/managers/async_manager/web/batch_fetch.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_route_constants import BATCH_FETCH_JOB_ROUTE_PREFIX
1213
from ...web_payload_utils import build_batch_fetch_start_payload
1314
from ...web_payload_utils import build_batch_fetch_get_params
1415
from ...web_pagination_utils import (
@@ -34,6 +35,8 @@
3435

3536

3637
class BatchFetchManager:
38+
_ROUTE_PREFIX = BATCH_FETCH_JOB_ROUTE_PREFIX
39+
3740
def __init__(self, client):
3841
self._client = client
3942

@@ -43,7 +46,7 @@ async def start(
4346
payload = build_batch_fetch_start_payload(params)
4447

4548
response = await self._client.transport.post(
46-
self._client._build_url("/web/batch-fetch"),
49+
self._client._build_url(self._ROUTE_PREFIX),
4750
data=payload,
4851
)
4952
return parse_response_model(
@@ -54,7 +57,7 @@ async def start(
5457

5558
async def get_status(self, job_id: str) -> BatchFetchJobStatusResponse:
5659
response = await self._client.transport.get(
57-
self._client._build_url(f"/web/batch-fetch/{job_id}/status")
60+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}/status")
5861
)
5962
return parse_response_model(
6063
response.data,
@@ -67,7 +70,7 @@ async def get(
6770
) -> BatchFetchJobResponse:
6871
query_params = build_batch_fetch_get_params(params)
6972
response = await self._client.transport.get(
70-
self._client._build_url(f"/web/batch-fetch/{job_id}"),
73+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}"),
7174
params=query_params,
7275
)
7376
return parse_response_model(

hyperbrowser/client/managers/async_manager/web/crawl.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_route_constants import WEB_CRAWL_JOB_ROUTE_PREFIX
1213
from ...web_payload_utils import build_web_crawl_start_payload
1314
from ...web_payload_utils import build_web_crawl_get_params
1415
from ...web_pagination_utils import (
@@ -34,14 +35,16 @@
3435

3536

3637
class WebCrawlManager:
38+
_ROUTE_PREFIX = WEB_CRAWL_JOB_ROUTE_PREFIX
39+
3740
def __init__(self, client):
3841
self._client = client
3942

4043
async def start(self, params: StartWebCrawlJobParams) -> StartWebCrawlJobResponse:
4144
payload = build_web_crawl_start_payload(params)
4245

4346
response = await self._client.transport.post(
44-
self._client._build_url("/web/crawl"),
47+
self._client._build_url(self._ROUTE_PREFIX),
4548
data=payload,
4649
)
4750
return parse_response_model(
@@ -52,7 +55,7 @@ async def start(self, params: StartWebCrawlJobParams) -> StartWebCrawlJobRespons
5255

5356
async def get_status(self, job_id: str) -> WebCrawlJobStatusResponse:
5457
response = await self._client.transport.get(
55-
self._client._build_url(f"/web/crawl/{job_id}/status")
58+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}/status")
5659
)
5760
return parse_response_model(
5861
response.data,
@@ -65,7 +68,7 @@ async def get(
6568
) -> WebCrawlJobResponse:
6669
query_params = build_web_crawl_get_params(params)
6770
response = await self._client.transport.get(
68-
self._client._build_url(f"/web/crawl/{job_id}"),
71+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}"),
6972
params=query_params,
7073
)
7174
return parse_response_model(

hyperbrowser/client/managers/sync_manager/web/batch_fetch.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_route_constants import BATCH_FETCH_JOB_ROUTE_PREFIX
1213
from ...web_payload_utils import build_batch_fetch_start_payload
1314
from ...web_payload_utils import build_batch_fetch_get_params
1415
from ...web_pagination_utils import (
@@ -34,14 +35,16 @@
3435

3536

3637
class BatchFetchManager:
38+
_ROUTE_PREFIX = BATCH_FETCH_JOB_ROUTE_PREFIX
39+
3740
def __init__(self, client):
3841
self._client = client
3942

4043
def start(self, params: StartBatchFetchJobParams) -> StartBatchFetchJobResponse:
4144
payload = build_batch_fetch_start_payload(params)
4245

4346
response = self._client.transport.post(
44-
self._client._build_url("/web/batch-fetch"),
47+
self._client._build_url(self._ROUTE_PREFIX),
4548
data=payload,
4649
)
4750
return parse_response_model(
@@ -52,7 +55,7 @@ def start(self, params: StartBatchFetchJobParams) -> StartBatchFetchJobResponse:
5255

5356
def get_status(self, job_id: str) -> BatchFetchJobStatusResponse:
5457
response = self._client.transport.get(
55-
self._client._build_url(f"/web/batch-fetch/{job_id}/status")
58+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}/status")
5659
)
5760
return parse_response_model(
5861
response.data,
@@ -65,7 +68,7 @@ def get(
6568
) -> BatchFetchJobResponse:
6669
query_params = build_batch_fetch_get_params(params)
6770
response = self._client.transport.get(
68-
self._client._build_url(f"/web/batch-fetch/{job_id}"),
71+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}"),
6972
params=query_params,
7073
)
7174
return parse_response_model(

hyperbrowser/client/managers/sync_manager/web/crawl.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_route_constants import WEB_CRAWL_JOB_ROUTE_PREFIX
1213
from ...web_payload_utils import build_web_crawl_start_payload
1314
from ...web_payload_utils import build_web_crawl_get_params
1415
from ...web_pagination_utils import (
@@ -32,14 +33,16 @@
3233

3334

3435
class WebCrawlManager:
36+
_ROUTE_PREFIX = WEB_CRAWL_JOB_ROUTE_PREFIX
37+
3538
def __init__(self, client):
3639
self._client = client
3740

3841
def start(self, params: StartWebCrawlJobParams) -> StartWebCrawlJobResponse:
3942
payload = build_web_crawl_start_payload(params)
4043

4144
response = self._client.transport.post(
42-
self._client._build_url("/web/crawl"),
45+
self._client._build_url(self._ROUTE_PREFIX),
4346
data=payload,
4447
)
4548
return parse_response_model(
@@ -50,7 +53,7 @@ def start(self, params: StartWebCrawlJobParams) -> StartWebCrawlJobResponse:
5053

5154
def get_status(self, job_id: str) -> WebCrawlJobStatusResponse:
5255
response = self._client.transport.get(
53-
self._client._build_url(f"/web/crawl/{job_id}/status")
56+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}/status")
5457
)
5558
return parse_response_model(
5659
response.data,
@@ -63,7 +66,7 @@ def get(
6366
) -> WebCrawlJobResponse:
6467
query_params = build_web_crawl_get_params(params)
6568
response = self._client.transport.get(
66-
self._client._build_url(f"/web/crawl/{job_id}"),
69+
self._client._build_url(f"{self._ROUTE_PREFIX}/{job_id}"),
6770
params=query_params,
6871
)
6972
return parse_response_model(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BATCH_FETCH_JOB_ROUTE_PREFIX = "/web/batch-fetch"
2+
WEB_CRAWL_JOB_ROUTE_PREFIX = "/web/crawl"

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"tests/test_started_job_helper_boundary.py",
6666
"tests/test_web_pagination_internal_reuse.py",
6767
"tests/test_web_payload_helper_usage.py",
68+
"tests/test_web_route_constants_usage.py",
6869
)
6970

7071

tests/test_core_type_helper_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"hyperbrowser/client/managers/polling_defaults.py",
4949
"hyperbrowser/client/managers/session_upload_utils.py",
5050
"hyperbrowser/client/managers/session_profile_update_utils.py",
51+
"hyperbrowser/client/managers/web_route_constants.py",
5152
"hyperbrowser/client/managers/web_pagination_utils.py",
5253
"hyperbrowser/client/managers/web_payload_utils.py",
5354
"hyperbrowser/client/managers/start_job_utils.py",

tests/test_web_route_constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from hyperbrowser.client.managers.web_route_constants import (
2+
BATCH_FETCH_JOB_ROUTE_PREFIX,
3+
WEB_CRAWL_JOB_ROUTE_PREFIX,
4+
)
5+
6+
7+
def test_web_route_constants_match_expected_api_paths():
8+
assert BATCH_FETCH_JOB_ROUTE_PREFIX == "/web/batch-fetch"
9+
assert WEB_CRAWL_JOB_ROUTE_PREFIX == "/web/crawl"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
pytestmark = pytest.mark.architecture
6+
7+
8+
MODULES = (
9+
"hyperbrowser/client/managers/sync_manager/web/batch_fetch.py",
10+
"hyperbrowser/client/managers/async_manager/web/batch_fetch.py",
11+
"hyperbrowser/client/managers/sync_manager/web/crawl.py",
12+
"hyperbrowser/client/managers/async_manager/web/crawl.py",
13+
)
14+
15+
16+
def test_web_managers_use_shared_route_constants():
17+
for module_path in MODULES:
18+
module_text = Path(module_path).read_text(encoding="utf-8")
19+
assert "web_route_constants import" in module_text
20+
assert "_ROUTE_PREFIX = " in module_text
21+
assert '_ROUTE_PREFIX = "/web/' not in module_text
22+
assert "_build_url(self._ROUTE_PREFIX)" in module_text
23+
assert '_build_url("/web/' not in module_text
24+
assert '_build_url(f"/web/' not in module_text

0 commit comments

Comments
 (0)