Skip to content

Commit bd789e6

Browse files
Centralize session upload prefixes in operation metadata
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 781154a commit bd789e6

5 files changed

Lines changed: 32 additions & 3 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ This runs lint, format checks, compile checks, tests, and package build.
199199
- `tests/test_session_resource_wrapper_internal_reuse.py` (session resource-wrapper internal reuse of shared model raw request helpers),
200200
- `tests/test_session_route_constants_usage.py` (session manager route-constant usage enforcement),
201201
- `tests/test_session_upload_helper_usage.py` (session upload-input normalization helper usage enforcement),
202+
- `tests/test_session_upload_metadata_usage.py` (session upload-helper shared operation-metadata prefix usage enforcement),
202203
- `tests/test_start_and_wait_default_constants_usage.py` (shared start-and-wait default-constant usage enforcement),
203204
- `tests/test_start_job_context_helper_usage.py` (shared started-job context helper usage enforcement),
204205
- `tests/test_started_job_helper_boundary.py` (centralization boundary enforcement for started-job helper primitives),

hyperbrowser/client/managers/session_operation_metadata.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ class SessionOperationMetadata:
1111
video_recording_url_operation_name: str
1212
downloads_url_operation_name: str
1313
upload_file_operation_name: str
14+
upload_missing_file_message_prefix: str
15+
upload_not_file_message_prefix: str
16+
upload_open_file_error_prefix: str
1417
extend_operation_name: str
1518
update_profile_operation_name: str
1619

@@ -24,6 +27,9 @@ class SessionOperationMetadata:
2427
video_recording_url_operation_name="session video recording url",
2528
downloads_url_operation_name="session downloads url",
2629
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",
2733
extend_operation_name="session extend",
2834
update_profile_operation_name="session update profile",
2935
)

hyperbrowser/client/managers/session_upload_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ensure_existing_file_path,
1313
open_binary_file,
1414
)
15+
from .session_operation_metadata import SESSION_OPERATION_METADATA
1516

1617

1718
def normalize_upload_file_input(
@@ -31,11 +32,11 @@ def normalize_upload_file_input(
3132
raw_file_path,
3233
missing_file_message=build_file_path_error_message(
3334
raw_file_path,
34-
prefix="Upload file not found at path",
35+
prefix=SESSION_OPERATION_METADATA.upload_missing_file_message_prefix,
3536
),
3637
not_file_message=build_file_path_error_message(
3738
raw_file_path,
38-
prefix="Upload file path must point to a file",
39+
prefix=SESSION_OPERATION_METADATA.upload_not_file_message_prefix,
3940
),
4041
)
4142
return file_path, None
@@ -80,7 +81,7 @@ def open_upload_files_from_input(
8081
file_path,
8182
open_error_message=build_open_file_error_message(
8283
file_path,
83-
prefix="Failed to open upload file at path",
84+
prefix=SESSION_OPERATION_METADATA.upload_open_file_error_prefix,
8485
),
8586
) as opened_file:
8687
yield {"file": opened_file}

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"tests/test_session_resource_wrapper_internal_reuse.py",
132132
"tests/test_session_route_constants_usage.py",
133133
"tests/test_session_upload_helper_usage.py",
134+
"tests/test_session_upload_metadata_usage.py",
134135
"tests/test_start_and_wait_default_constants_usage.py",
135136
"tests/test_start_job_context_helper_usage.py",
136137
"tests/test_started_job_helper_boundary.py",
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+
MODULE_PATH = "hyperbrowser/client/managers/session_upload_utils.py"
9+
10+
11+
def test_session_upload_helper_uses_shared_operation_metadata_prefixes():
12+
module_text = Path(MODULE_PATH).read_text(encoding="utf-8")
13+
14+
assert "session_operation_metadata import" in module_text
15+
assert "SESSION_OPERATION_METADATA.upload_missing_file_message_prefix" in module_text
16+
assert "SESSION_OPERATION_METADATA.upload_not_file_message_prefix" in module_text
17+
assert "SESSION_OPERATION_METADATA.upload_open_file_error_prefix" in module_text
18+
assert 'prefix="Upload file not found at path"' not in module_text
19+
assert 'prefix="Upload file path must point to a file"' not in module_text
20+
assert 'prefix="Failed to open upload file at path"' not in module_text

0 commit comments

Comments
 (0)