Skip to content

Commit 26b12af

Browse files
Centralize team manager request and metadata handling
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 02ac62a commit 26b12af

14 files changed

Lines changed: 238 additions & 14 deletions

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ This runs lint, format checks, compile checks, tests, and package build.
139139
- `tests/test_start_and_wait_default_constants_usage.py` (shared start-and-wait default-constant usage enforcement),
140140
- `tests/test_start_job_context_helper_usage.py` (shared started-job context helper usage enforcement),
141141
- `tests/test_started_job_helper_boundary.py` (centralization boundary enforcement for started-job helper primitives),
142+
- `tests/test_team_operation_metadata_usage.py` (team manager operation-metadata usage enforcement),
143+
- `tests/test_team_request_helper_usage.py` (team manager request-helper usage enforcement),
144+
- `tests/test_team_route_constants_usage.py` (team manager route-constant usage enforcement),
142145
- `tests/test_tool_mapping_reader_usage.py` (tools mapping-helper usage),
143146
- `tests/test_type_utils_usage.py` (type `__mro__` boundary centralization in `hyperbrowser/type_utils.py`),
144147
- `tests/test_web_operation_metadata_usage.py` (web manager operation-metadata usage enforcement),
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
from hyperbrowser.models import TeamCreditInfo
2-
from ..response_utils import parse_response_model
2+
from ..team_operation_metadata import TEAM_OPERATION_METADATA
3+
from ..team_request_utils import get_team_resource_async
4+
from ..team_route_constants import TEAM_CREDIT_INFO_ROUTE_PATH
35

46

57
class TeamManager:
8+
_OPERATION_METADATA = TEAM_OPERATION_METADATA
9+
_CREDIT_INFO_ROUTE_PATH = TEAM_CREDIT_INFO_ROUTE_PATH
10+
611
def __init__(self, client):
712
self._client = client
813

914
async def get_credit_info(self) -> TeamCreditInfo:
10-
response = await self._client.transport.get(
11-
self._client._build_url("/team/credit-info")
12-
)
13-
return parse_response_model(
14-
response.data,
15+
return await get_team_resource_async(
16+
client=self._client,
17+
route_path=self._CREDIT_INFO_ROUTE_PATH,
1518
model=TeamCreditInfo,
16-
operation_name="team credit info",
19+
operation_name=self._OPERATION_METADATA.get_credit_info_operation_name,
1720
)
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
from hyperbrowser.models import TeamCreditInfo
2-
from ..response_utils import parse_response_model
2+
from ..team_operation_metadata import TEAM_OPERATION_METADATA
3+
from ..team_request_utils import get_team_resource
4+
from ..team_route_constants import TEAM_CREDIT_INFO_ROUTE_PATH
35

46

57
class TeamManager:
8+
_OPERATION_METADATA = TEAM_OPERATION_METADATA
9+
_CREDIT_INFO_ROUTE_PATH = TEAM_CREDIT_INFO_ROUTE_PATH
10+
611
def __init__(self, client):
712
self._client = client
813

914
def get_credit_info(self) -> TeamCreditInfo:
10-
response = self._client.transport.get(
11-
self._client._build_url("/team/credit-info")
12-
)
13-
return parse_response_model(
14-
response.data,
15+
return get_team_resource(
16+
client=self._client,
17+
route_path=self._CREDIT_INFO_ROUTE_PATH,
1518
model=TeamCreditInfo,
16-
operation_name="team credit info",
19+
operation_name=self._OPERATION_METADATA.get_credit_info_operation_name,
1720
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass(frozen=True)
5+
class TeamOperationMetadata:
6+
get_credit_info_operation_name: str
7+
8+
9+
TEAM_OPERATION_METADATA = TeamOperationMetadata(
10+
get_credit_info_operation_name="team credit info",
11+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from typing import Any, Type, TypeVar
2+
3+
from .response_utils import parse_response_model
4+
5+
T = TypeVar("T")
6+
7+
8+
def get_team_resource(
9+
*,
10+
client: Any,
11+
route_path: str,
12+
model: Type[T],
13+
operation_name: str,
14+
) -> T:
15+
response = client.transport.get(
16+
client._build_url(route_path),
17+
)
18+
return parse_response_model(
19+
response.data,
20+
model=model,
21+
operation_name=operation_name,
22+
)
23+
24+
25+
async def get_team_resource_async(
26+
*,
27+
client: Any,
28+
route_path: str,
29+
model: Type[T],
30+
operation_name: str,
31+
) -> T:
32+
response = await client.transport.get(
33+
client._build_url(route_path),
34+
)
35+
return parse_response_model(
36+
response.data,
37+
model=model,
38+
operation_name=operation_name,
39+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEAM_CREDIT_INFO_ROUTE_PATH = "/team/credit-info"

tests/test_architecture_marker_usage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@
7171
"tests/test_start_and_wait_default_constants_usage.py",
7272
"tests/test_start_job_context_helper_usage.py",
7373
"tests/test_started_job_helper_boundary.py",
74+
"tests/test_team_operation_metadata_usage.py",
75+
"tests/test_team_request_helper_usage.py",
76+
"tests/test_team_route_constants_usage.py",
7477
"tests/test_web_operation_metadata_usage.py",
7578
"tests/test_web_pagination_internal_reuse.py",
7679
"tests/test_web_payload_helper_usage.py",

tests/test_core_type_helper_usage.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
"hyperbrowser/client/managers/session_operation_metadata.py",
5656
"hyperbrowser/client/managers/session_route_constants.py",
5757
"hyperbrowser/client/managers/session_upload_utils.py",
58+
"hyperbrowser/client/managers/team_operation_metadata.py",
59+
"hyperbrowser/client/managers/team_request_utils.py",
60+
"hyperbrowser/client/managers/team_route_constants.py",
5861
"hyperbrowser/client/managers/session_profile_update_utils.py",
5962
"hyperbrowser/client/managers/web_operation_metadata.py",
6063
"hyperbrowser/client/managers/web_request_utils.py",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from hyperbrowser.client.managers.team_operation_metadata import (
2+
TEAM_OPERATION_METADATA,
3+
)
4+
5+
6+
def test_team_operation_metadata_values():
7+
assert TEAM_OPERATION_METADATA.get_credit_info_operation_name == "team credit info"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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/team.py",
10+
"hyperbrowser/client/managers/async_manager/team.py",
11+
)
12+
13+
14+
def test_team_managers_use_shared_operation_metadata():
15+
for module_path in MODULES:
16+
module_text = Path(module_path).read_text(encoding="utf-8")
17+
assert "team_operation_metadata import" in module_text
18+
assert "_OPERATION_METADATA = " in module_text
19+
assert "operation_name=self._OPERATION_METADATA." in module_text
20+
assert 'operation_name="' not in module_text

0 commit comments

Comments
 (0)