Skip to content

Commit 89bbfd0

Browse files
Centralize profile route builder usage
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 72bc74b commit 89bbfd0

File tree

9 files changed

+30
-16
lines changed

9 files changed

+30
-16
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ This runs lint, format checks, compile checks, tests, and package build.
136136
- `tests/test_polling_loop_usage.py` (`while True` polling-loop centralization in `hyperbrowser/client/polling.py`),
137137
- `tests/test_profile_operation_metadata_usage.py` (profile manager operation-metadata usage enforcement),
138138
- `tests/test_profile_request_helper_usage.py` (profile manager request-helper usage enforcement),
139+
- `tests/test_profile_route_builder_usage.py` (profile request-helper route-builder usage enforcement),
139140
- `tests/test_profile_route_constants_usage.py` (profile manager route-constant usage enforcement),
140141
- `tests/test_pyproject_architecture_marker.py` (pytest marker registration enforcement),
141142
- `tests/test_readme_examples_listing.py` (README example-listing consistency enforcement),

hyperbrowser/client/managers/async_manager/profile.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ async def create(
4848
async def get(self, id: str) -> ProfileResponse:
4949
return await get_profile_resource_async(
5050
client=self._client,
51-
route_prefix=self._ROUTE_PREFIX,
5251
profile_id=id,
5352
model=ProfileResponse,
5453
operation_name=self._OPERATION_METADATA.get_operation_name,
@@ -57,7 +56,6 @@ async def get(self, id: str) -> ProfileResponse:
5756
async def delete(self, id: str) -> BasicResponse:
5857
return await delete_profile_resource_async(
5958
client=self._client,
60-
route_prefix=self._ROUTE_PREFIX,
6159
profile_id=id,
6260
model=BasicResponse,
6361
operation_name=self._OPERATION_METADATA.delete_operation_name,

hyperbrowser/client/managers/profile_request_utils.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any, Dict, Optional, Type, TypeVar
22

3+
from .profile_route_constants import build_profile_route
34
from .response_utils import parse_response_model
45

56
T = TypeVar("T")
@@ -27,13 +28,12 @@ def create_profile_resource(
2728
def get_profile_resource(
2829
*,
2930
client: Any,
30-
route_prefix: str,
3131
profile_id: str,
3232
model: Type[T],
3333
operation_name: str,
3434
) -> T:
3535
response = client.transport.get(
36-
client._build_url(f"{route_prefix}/{profile_id}"),
36+
client._build_url(build_profile_route(profile_id)),
3737
)
3838
return parse_response_model(
3939
response.data,
@@ -45,13 +45,12 @@ def get_profile_resource(
4545
def delete_profile_resource(
4646
*,
4747
client: Any,
48-
route_prefix: str,
4948
profile_id: str,
5049
model: Type[T],
5150
operation_name: str,
5251
) -> T:
5352
response = client.transport.delete(
54-
client._build_url(f"{route_prefix}/{profile_id}"),
53+
client._build_url(build_profile_route(profile_id)),
5554
)
5655
return parse_response_model(
5756
response.data,
@@ -101,13 +100,12 @@ async def create_profile_resource_async(
101100
async def get_profile_resource_async(
102101
*,
103102
client: Any,
104-
route_prefix: str,
105103
profile_id: str,
106104
model: Type[T],
107105
operation_name: str,
108106
) -> T:
109107
response = await client.transport.get(
110-
client._build_url(f"{route_prefix}/{profile_id}"),
108+
client._build_url(build_profile_route(profile_id)),
111109
)
112110
return parse_response_model(
113111
response.data,
@@ -119,13 +117,12 @@ async def get_profile_resource_async(
119117
async def delete_profile_resource_async(
120118
*,
121119
client: Any,
122-
route_prefix: str,
123120
profile_id: str,
124121
model: Type[T],
125122
operation_name: str,
126123
) -> T:
127124
response = await client.transport.delete(
128-
client._build_url(f"{route_prefix}/{profile_id}"),
125+
client._build_url(build_profile_route(profile_id)),
129126
)
130127
return parse_response_model(
131128
response.data,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
PROFILE_ROUTE_PREFIX = "/profile"
22
PROFILES_ROUTE_PATH = "/profiles"
3+
4+
5+
def build_profile_route(profile_id: str) -> str:
6+
return f"{PROFILE_ROUTE_PREFIX}/{profile_id}"

hyperbrowser/client/managers/sync_manager/profile.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ def create(
4848
def get(self, id: str) -> ProfileResponse:
4949
return get_profile_resource(
5050
client=self._client,
51-
route_prefix=self._ROUTE_PREFIX,
5251
profile_id=id,
5352
model=ProfileResponse,
5453
operation_name=self._OPERATION_METADATA.get_operation_name,
@@ -57,7 +56,6 @@ def get(self, id: str) -> ProfileResponse:
5756
def delete(self, id: str) -> BasicResponse:
5857
return delete_profile_resource(
5958
client=self._client,
60-
route_prefix=self._ROUTE_PREFIX,
6159
profile_id=id,
6260
model=BasicResponse,
6361
operation_name=self._OPERATION_METADATA.delete_operation_name,

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"tests/test_optional_serialization_helper_usage.py",
4040
"tests/test_profile_operation_metadata_usage.py",
4141
"tests/test_profile_request_helper_usage.py",
42+
"tests/test_profile_route_builder_usage.py",
4243
"tests/test_profile_route_constants_usage.py",
4344
"tests/test_type_utils_usage.py",
4445
"tests/test_polling_loop_usage.py",

tests/test_profile_request_utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def _fake_parse_response_model(data, **kwargs):
7171
try:
7272
result = profile_request_utils.get_profile_resource(
7373
client=_Client(),
74-
route_prefix="/profile",
7574
profile_id="profile-2",
7675
model=object,
7776
operation_name="get profile",
@@ -111,7 +110,6 @@ def _fake_parse_response_model(data, **kwargs):
111110
try:
112111
result = profile_request_utils.delete_profile_resource(
113112
client=_Client(),
114-
route_prefix="/profile",
115113
profile_id="profile-3",
116114
model=object,
117115
operation_name="delete profile",
@@ -236,7 +234,6 @@ def _fake_parse_response_model(data, **kwargs):
236234
result = asyncio.run(
237235
profile_request_utils.get_profile_resource_async(
238236
client=_Client(),
239-
route_prefix="/profile",
240237
profile_id="profile-5",
241238
model=object,
242239
operation_name="get profile",
@@ -278,7 +275,6 @@ def _fake_parse_response_model(data, **kwargs):
278275
result = asyncio.run(
279276
profile_request_utils.delete_profile_resource_async(
280277
client=_Client(),
281-
route_prefix="/profile",
282278
profile_id="profile-6",
283279
model=object,
284280
operation_name="delete profile",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
pytestmark = pytest.mark.architecture
6+
7+
8+
def test_profile_request_utils_use_profile_route_builder():
9+
module_text = Path(
10+
"hyperbrowser/client/managers/profile_request_utils.py"
11+
).read_text(encoding="utf-8")
12+
assert "profile_route_constants import build_profile_route" in module_text
13+
assert "build_profile_route(profile_id)" in module_text
14+
assert 'f"{route_prefix}/{profile_id}"' not in module_text

tests/test_profile_route_constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from hyperbrowser.client.managers.profile_route_constants import (
2+
build_profile_route,
23
PROFILE_ROUTE_PREFIX,
34
PROFILES_ROUTE_PATH,
45
)
@@ -7,3 +8,7 @@
78
def test_profile_route_constants_match_expected_api_paths():
89
assert PROFILE_ROUTE_PREFIX == "/profile"
910
assert PROFILES_ROUTE_PATH == "/profiles"
11+
12+
13+
def test_build_profile_route_composes_profile_path():
14+
assert build_profile_route("profile_123") == "/profile/profile_123"

0 commit comments

Comments
 (0)