Skip to content

Commit 2f7043b

Browse files
Centralize metadata default prefix constants
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 2e81165 commit 2f7043b

11 files changed

+76
-17
lines changed

hyperbrowser/client/managers/async_manager/extension.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
from ...file_utils import build_open_file_error_message, open_binary_file
44
from ..extension_create_utils import normalize_extension_create_input
5-
from ..extension_operation_metadata import EXTENSION_OPERATION_METADATA
5+
from ..extension_operation_metadata import (
6+
EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX,
7+
EXTENSION_OPERATION_METADATA,
8+
)
69
from ..extension_request_utils import (
710
create_extension_resource_async,
811
list_extension_resources_async,
@@ -30,7 +33,7 @@ async def create(self, params: CreateExtensionParams) -> ExtensionResponse:
3033
open_error_message=build_open_file_error_message(
3134
file_path,
3235
prefix=self._OPERATION_METADATA.open_file_error_prefix,
33-
default_prefix="Failed to open extension file at path",
36+
default_prefix=EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX,
3437
),
3538
) as extension_file:
3639
return await create_extension_resource_async(

hyperbrowser/client/managers/extension_create_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from hyperbrowser.models.extension import CreateExtensionParams
55

66
from ..file_utils import build_file_path_error_message, ensure_existing_file_path
7-
from .extension_operation_metadata import EXTENSION_OPERATION_METADATA
7+
from .extension_operation_metadata import (
8+
EXTENSION_DEFAULT_MISSING_FILE_MESSAGE_PREFIX,
9+
EXTENSION_DEFAULT_NOT_FILE_MESSAGE_PREFIX,
10+
EXTENSION_OPERATION_METADATA,
11+
)
812
from .serialization_utils import serialize_model_dump_to_dict
913

1014

@@ -32,12 +36,12 @@ def normalize_extension_create_input(params: Any) -> Tuple[str, Dict[str, Any]]:
3236
missing_file_message=build_file_path_error_message(
3337
raw_file_path,
3438
prefix=EXTENSION_OPERATION_METADATA.missing_file_message_prefix,
35-
default_prefix="Extension file not found at path",
39+
default_prefix=EXTENSION_DEFAULT_MISSING_FILE_MESSAGE_PREFIX,
3640
),
3741
not_file_message=build_file_path_error_message(
3842
raw_file_path,
3943
prefix=EXTENSION_OPERATION_METADATA.not_file_message_prefix,
40-
default_prefix="Extension file path must point to a file",
44+
default_prefix=EXTENSION_DEFAULT_NOT_FILE_MESSAGE_PREFIX,
4145
),
4246
)
4347
return file_path, payload

hyperbrowser/client/managers/extension_operation_metadata.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from dataclasses import dataclass
22

3+
EXTENSION_DEFAULT_MISSING_FILE_MESSAGE_PREFIX = "Extension file not found at path"
4+
EXTENSION_DEFAULT_NOT_FILE_MESSAGE_PREFIX = "Extension file path must point to a file"
5+
EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX = "Failed to open extension file at path"
6+
37

48
@dataclass(frozen=True)
59
class ExtensionOperationMetadata:
@@ -11,7 +15,7 @@ class ExtensionOperationMetadata:
1115

1216
EXTENSION_OPERATION_METADATA = ExtensionOperationMetadata(
1317
create_operation_name="create extension",
14-
missing_file_message_prefix="Extension file not found at path",
15-
not_file_message_prefix="Extension file path must point to a file",
16-
open_file_error_prefix="Failed to open extension file at path",
18+
missing_file_message_prefix=EXTENSION_DEFAULT_MISSING_FILE_MESSAGE_PREFIX,
19+
not_file_message_prefix=EXTENSION_DEFAULT_NOT_FILE_MESSAGE_PREFIX,
20+
open_file_error_prefix=EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX,
1721
)

hyperbrowser/client/managers/session_operation_metadata.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
from dataclasses import dataclass
22

3+
SESSION_DEFAULT_UPLOAD_MISSING_FILE_MESSAGE_PREFIX = "Upload file not found at path"
4+
SESSION_DEFAULT_UPLOAD_NOT_FILE_MESSAGE_PREFIX = "Upload file path must point to a file"
5+
SESSION_DEFAULT_UPLOAD_OPEN_FILE_ERROR_PREFIX = "Failed to open upload file at path"
6+
37

48
@dataclass(frozen=True)
59
class SessionOperationMetadata:
@@ -27,9 +31,9 @@ class SessionOperationMetadata:
2731
video_recording_url_operation_name="session video recording url",
2832
downloads_url_operation_name="session downloads url",
2933
upload_file_operation_name="session upload file",
30-
upload_missing_file_message_prefix="Upload file not found at path",
31-
upload_not_file_message_prefix="Upload file path must point to a file",
32-
upload_open_file_error_prefix="Failed to open upload file at path",
34+
upload_missing_file_message_prefix=SESSION_DEFAULT_UPLOAD_MISSING_FILE_MESSAGE_PREFIX,
35+
upload_not_file_message_prefix=SESSION_DEFAULT_UPLOAD_NOT_FILE_MESSAGE_PREFIX,
36+
upload_open_file_error_prefix=SESSION_DEFAULT_UPLOAD_OPEN_FILE_ERROR_PREFIX,
3337
extend_operation_name="session extend",
3438
update_profile_operation_name="session update profile",
3539
)

hyperbrowser/client/managers/session_upload_utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
ensure_existing_file_path,
1313
open_binary_file,
1414
)
15-
from .session_operation_metadata import SESSION_OPERATION_METADATA
15+
from .session_operation_metadata import (
16+
SESSION_DEFAULT_UPLOAD_MISSING_FILE_MESSAGE_PREFIX,
17+
SESSION_DEFAULT_UPLOAD_NOT_FILE_MESSAGE_PREFIX,
18+
SESSION_DEFAULT_UPLOAD_OPEN_FILE_ERROR_PREFIX,
19+
SESSION_OPERATION_METADATA,
20+
)
1621

1722

1823
def normalize_upload_file_input(
@@ -33,12 +38,12 @@ def normalize_upload_file_input(
3338
missing_file_message=build_file_path_error_message(
3439
raw_file_path,
3540
prefix=SESSION_OPERATION_METADATA.upload_missing_file_message_prefix,
36-
default_prefix="Upload file not found at path",
41+
default_prefix=SESSION_DEFAULT_UPLOAD_MISSING_FILE_MESSAGE_PREFIX,
3742
),
3843
not_file_message=build_file_path_error_message(
3944
raw_file_path,
4045
prefix=SESSION_OPERATION_METADATA.upload_not_file_message_prefix,
41-
default_prefix="Upload file path must point to a file",
46+
default_prefix=SESSION_DEFAULT_UPLOAD_NOT_FILE_MESSAGE_PREFIX,
4247
),
4348
)
4449
return file_path, None
@@ -84,7 +89,7 @@ def open_upload_files_from_input(
8489
open_error_message=build_open_file_error_message(
8590
file_path,
8691
prefix=SESSION_OPERATION_METADATA.upload_open_file_error_prefix,
87-
default_prefix="Failed to open upload file at path",
92+
default_prefix=SESSION_DEFAULT_UPLOAD_OPEN_FILE_ERROR_PREFIX,
8893
),
8994
) as opened_file:
9095
yield {"file": opened_file}

hyperbrowser/client/managers/sync_manager/extension.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
from ...file_utils import build_open_file_error_message, open_binary_file
44
from ..extension_create_utils import normalize_extension_create_input
5-
from ..extension_operation_metadata import EXTENSION_OPERATION_METADATA
5+
from ..extension_operation_metadata import (
6+
EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX,
7+
EXTENSION_OPERATION_METADATA,
8+
)
69
from ..extension_request_utils import (
710
create_extension_resource,
811
list_extension_resources,
@@ -30,7 +33,7 @@ def create(self, params: CreateExtensionParams) -> ExtensionResponse:
3033
open_error_message=build_open_file_error_message(
3134
file_path,
3235
prefix=self._OPERATION_METADATA.open_file_error_prefix,
33-
default_prefix="Failed to open extension file at path",
36+
default_prefix=EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX,
3437
),
3538
) as extension_file:
3639
return create_extension_resource(

tests/test_extension_create_metadata_usage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def test_extension_create_helper_uses_shared_operation_metadata_prefixes():
1515
assert "extension_operation_metadata import" in module_text
1616
assert "EXTENSION_OPERATION_METADATA.missing_file_message_prefix" in module_text
1717
assert "EXTENSION_OPERATION_METADATA.not_file_message_prefix" in module_text
18+
assert "EXTENSION_DEFAULT_MISSING_FILE_MESSAGE_PREFIX" in module_text
19+
assert "EXTENSION_DEFAULT_NOT_FILE_MESSAGE_PREFIX" in module_text
1820
assert (
1921
re.search(
2022
r'(?<!default_)prefix="Extension file not found at path"',
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
from hyperbrowser.client.managers.extension_operation_metadata import (
2+
EXTENSION_DEFAULT_MISSING_FILE_MESSAGE_PREFIX,
3+
EXTENSION_DEFAULT_NOT_FILE_MESSAGE_PREFIX,
4+
EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX,
25
EXTENSION_OPERATION_METADATA,
36
)
47

58

69
def test_extension_operation_metadata_values():
710
assert EXTENSION_OPERATION_METADATA.create_operation_name == "create extension"
11+
assert (
12+
EXTENSION_OPERATION_METADATA.missing_file_message_prefix
13+
== EXTENSION_DEFAULT_MISSING_FILE_MESSAGE_PREFIX
14+
)
15+
assert (
16+
EXTENSION_OPERATION_METADATA.not_file_message_prefix
17+
== EXTENSION_DEFAULT_NOT_FILE_MESSAGE_PREFIX
18+
)
19+
assert (
20+
EXTENSION_OPERATION_METADATA.open_file_error_prefix
21+
== EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX
22+
)

tests/test_extension_operation_metadata_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def test_extension_managers_use_shared_operation_metadata():
1919
assert "_OPERATION_METADATA = " in module_text
2020
assert "operation_name=self._OPERATION_METADATA." in module_text
2121
assert "prefix=self._OPERATION_METADATA.open_file_error_prefix" in module_text
22+
assert "default_prefix=EXTENSION_DEFAULT_OPEN_FILE_ERROR_PREFIX" in module_text
2223
assert 'operation_name="' not in module_text
2324
assert (
2425
re.search(

tests/test_session_operation_metadata.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from hyperbrowser.client.managers.session_operation_metadata import (
2+
SESSION_DEFAULT_UPLOAD_MISSING_FILE_MESSAGE_PREFIX,
3+
SESSION_DEFAULT_UPLOAD_NOT_FILE_MESSAGE_PREFIX,
4+
SESSION_DEFAULT_UPLOAD_OPEN_FILE_ERROR_PREFIX,
25
SESSION_OPERATION_METADATA,
36
)
47

@@ -18,6 +21,18 @@ def test_session_operation_metadata_values():
1821
== "session downloads url"
1922
)
2023
assert SESSION_OPERATION_METADATA.upload_file_operation_name == "session upload file"
24+
assert (
25+
SESSION_OPERATION_METADATA.upload_missing_file_message_prefix
26+
== SESSION_DEFAULT_UPLOAD_MISSING_FILE_MESSAGE_PREFIX
27+
)
28+
assert (
29+
SESSION_OPERATION_METADATA.upload_not_file_message_prefix
30+
== SESSION_DEFAULT_UPLOAD_NOT_FILE_MESSAGE_PREFIX
31+
)
32+
assert (
33+
SESSION_OPERATION_METADATA.upload_open_file_error_prefix
34+
== SESSION_DEFAULT_UPLOAD_OPEN_FILE_ERROR_PREFIX
35+
)
2136
assert SESSION_OPERATION_METADATA.extend_operation_name == "session extend"
2237
assert (
2338
SESSION_OPERATION_METADATA.update_profile_operation_name

0 commit comments

Comments
 (0)