Skip to content

Commit a7b63b4

Browse files
committed
Add binary characters replacement property
1 parent 9bfc6b7 commit a7b63b4

10 files changed

Lines changed: 478 additions & 172 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- Attribute key length and number truncation, by @HardNorth
6+
- Binary character replacement in basic text fields, by @HardNorth
47

58
## [5.7.0]
69
### Added

reportportal_client/__init__.py

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ class _ClientOptions(TypedDict, total=False):
6262
launch_uuid_print: bool
6363
print_output: OutputType
6464
truncate_attributes: bool
65+
truncate_fields: bool
66+
replace_binary_chars: bool
67+
launch_name_length_limit: int
68+
item_name_length_limit: int
69+
launch_description_length_limit: int
70+
item_description_length_limit: int
6571
log_batch_size: int
6672
log_batch_payload_limit: int
6773
# Async client specific parameters
@@ -80,42 +86,48 @@ def create_client(
8086
) -> Optional[RP]:
8187
"""Create and ReportPortal Client based on the type and arguments provided.
8288
83-
:param client_type: Type of the Client to create.
84-
:param endpoint: Endpoint of the ReportPortal service.
85-
:param project: Project name to report to.
86-
:param api_key: Authorization API key.
87-
:param oauth_uri: OAuth 2.0 token endpoint URI (for OAuth authentication).
88-
:param oauth_username: Username for OAuth 2.0 authentication.
89-
:param oauth_password: Password for OAuth 2.0 authentication.
90-
:param oauth_client_id: OAuth 2.0 client ID.
91-
:param oauth_client_secret: OAuth 2.0 client secret (optional).
92-
:param oauth_scope: OAuth 2.0 scope (optional).
93-
:param launch_uuid: A launch UUID to use instead of starting own one.
94-
:param is_skipped_an_issue: Option to mark skipped tests as not 'To Investigate' items on the server
95-
side.
96-
:param verify_ssl: Option to skip ssl verification.
97-
:param retries: Number of retry attempts to make in case of connection / server
98-
errors.
99-
:param max_pool_size: Option to set the maximum number of connections to save the pool.
100-
:param http_timeout : A float in seconds for connect and read timeout. Use a Tuple to
101-
specific connect and read separately.
102-
:param mode: Launch mode, all Launches started by the client will be in that mode.
103-
:param launch_uuid_print: Print Launch UUID into passed TextIO or by default to stdout.
104-
:param print_output: Set output stream for Launch UUID printing.
105-
:param truncate_attributes: Truncate test item attributes to default maximum length.
106-
:param log_batch_size: Option to set the maximum number of logs that can be processed in one
107-
batch.
108-
:param log_batch_payload_limit: Maximum size in bytes of logs that can be processed in one batch.
109-
:param keepalive_timeout: For Async Clients only. Maximum amount of idle time in seconds before
110-
force connection closing.
111-
:param task_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for a
112-
Task processing.
113-
:param shutdown_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for
114-
shutting down internal Tasks.
115-
:param trigger_num: For Async Batched Client only. Number of tasks which triggers Task batch
116-
execution.
117-
:param trigger_interval: For Async Batched Client only. Time limit which triggers Task batch
118-
execution.
89+
:param client_type: Type of the Client to create.
90+
:param endpoint: Endpoint of the ReportPortal service.
91+
:param project: Project name to report to.
92+
:param api_key: Authorization API key.
93+
:param oauth_uri: OAuth 2.0 token endpoint URI (for OAuth authentication).
94+
:param oauth_username: Username for OAuth 2.0 authentication.
95+
:param oauth_password: Password for OAuth 2.0 authentication.
96+
:param oauth_client_id: OAuth 2.0 client ID.
97+
:param oauth_client_secret: OAuth 2.0 client secret (optional).
98+
:param oauth_scope: OAuth 2.0 scope (optional).
99+
:param launch_uuid: A launch UUID to use instead of starting own one.
100+
:param is_skipped_an_issue: Option to mark skipped tests as not 'To Investigate' items on the server
101+
side.
102+
:param verify_ssl: Option to skip ssl verification.
103+
:param retries: Number of retry attempts to make in case of connection / server
104+
errors.
105+
:param max_pool_size: Option to set the maximum number of connections to save the pool.
106+
:param http_timeout: A float in seconds for connect and read timeout. Use a Tuple to
107+
specific connect and read separately.
108+
:param mode: Launch mode, all Launches started by the client will be in that mode.
109+
:param launch_uuid_print: Print Launch UUID into passed TextIO or by default to stdout.
110+
:param print_output: Set output stream for Launch UUID printing.
111+
:param truncate_attributes: Truncate test item attributes to default maximum length.
112+
:param truncate_fields: Truncate request fields to configured limits.
113+
:param replace_binary_chars: Toggle replacement of basic binary characters with \ufffd char.
114+
:param launch_name_length_limit: Maximum allowed launch name length.
115+
:param item_name_length_limit: Maximum allowed test item name length.
116+
:param launch_description_length_limit: Maximum allowed launch description length.
117+
:param item_description_length_limit: Maximum allowed test item description length.
118+
:param log_batch_size: Option to set the maximum number of logs that can be processed in one
119+
batch.
120+
:param log_batch_payload_limit: Maximum size in bytes of logs that can be processed in one batch.
121+
:param keepalive_timeout: For Async Clients only. Maximum amount of idle time in seconds before
122+
force connection closing.
123+
:param task_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for a
124+
Task processing.
125+
:param shutdown_timeout: For Async Threaded and Batched Clients only. Time limit in seconds for
126+
shutting down internal Tasks.
127+
:param trigger_num: For Async Batched Client only. Number of tasks which triggers Task batch
128+
execution.
129+
:param trigger_interval: For Async Batched Client only. Time limit which triggers Task batch
130+
execution.
119131
:return: ReportPortal Client instance.
120132
"""
121133
my_kwargs = kwargs.copy()

reportportal_client/aio/client.py

Lines changed: 89 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,21 @@
6666
AsyncRPLogBatch,
6767
AsyncRPRequestLog,
6868
ErrorPrintingAsyncHttpRequest,
69+
ItemUpdateRequest,
6970
LaunchFinishRequest,
7071
LaunchStartRequest,
7172
RPFile,
7273
)
7374
from reportportal_client.helpers import (
75+
ITEM_DESCRIPTION_LENGTH_LIMIT,
76+
ITEM_NAME_LENGTH_LIMIT,
77+
LAUNCH_DESCRIPTION_LENGTH_LIMIT,
78+
LAUNCH_NAME_LENGTH_LIMIT,
7479
LifoQueue,
7580
agent_name_version,
7681
await_if_necessary,
7782
root_uri_join,
7883
uri_join,
79-
verify_value_length,
8084
)
8185
from reportportal_client.logs import MAX_LOG_BATCH_PAYLOAD_SIZE
8286
from reportportal_client.steps import StepReporter
@@ -122,6 +126,12 @@ class Client:
122126
launch_uuid_print: bool
123127
print_output: OutputType
124128
truncate_attributes: bool
129+
truncate_fields: bool
130+
replace_binary_chars: bool
131+
launch_name_length_limit: int
132+
item_name_length_limit: int
133+
launch_description_length_limit: int
134+
item_description_length_limit: int
125135
_skip_analytics: Optional[str]
126136
_session: Optional[ClientSession]
127137
__stat_task: Optional[asyncio.Task]
@@ -142,6 +152,12 @@ def __init__(
142152
launch_uuid_print: bool = False,
143153
print_output: OutputType = OutputType.STDOUT,
144154
truncate_attributes: bool = True,
155+
truncate_fields: bool = True,
156+
replace_binary_chars: bool = True,
157+
launch_name_length_limit: int = LAUNCH_NAME_LENGTH_LIMIT,
158+
item_name_length_limit: int = ITEM_NAME_LENGTH_LIMIT,
159+
launch_description_length_limit: int = LAUNCH_DESCRIPTION_LENGTH_LIMIT,
160+
item_description_length_limit: int = ITEM_DESCRIPTION_LENGTH_LIMIT,
145161
# OAuth 2.0 Password Grant parameters
146162
oauth_uri: Optional[str] = None,
147163
oauth_username: Optional[str] = None,
@@ -153,27 +169,35 @@ def __init__(
153169
) -> None:
154170
"""Initialize the class instance with arguments.
155171
156-
:param endpoint: Endpoint of the ReportPortal service.
157-
:param project: Project name to report to.
158-
:param api_key: Authorization API key.
159-
:param oauth_uri: OAuth 2.0 token endpoint URI (for OAuth authentication).
160-
:param oauth_username: Username for OAuth 2.0 authentication.
161-
:param oauth_password: Password for OAuth 2.0 authentication.
162-
:param oauth_client_id: OAuth 2.0 client ID.
163-
:param oauth_client_secret: OAuth 2.0 client secret (optional).
164-
:param oauth_scope: OAuth 2.0 scope (optional).
165-
:param is_skipped_an_issue: Option to mark skipped tests as not 'To Investigate' items on the
166-
server side.
167-
:param verify_ssl: Option to skip ssl verification.
168-
:param retries: Number of retry attempts to make in case of connection / server errors.
169-
:param max_pool_size: Option to set the maximum number of connections to save the pool.
170-
:param http_timeout: A float in seconds for connect and read timeout. Use a Tuple to
171-
specific connect and read separately.
172-
:param keepalive_timeout: Maximum amount of idle time in seconds before force connection closing.
173-
:param mode: Launch mode, all Launches started by the client will be in that mode.
174-
:param launch_uuid_print: Print Launch UUID into passed TextIO or by default to stdout.
175-
:param print_output: Set output stream for Launch UUID printing.
176-
:param truncate_attributes: Truncate test item attributes to default maximum length.
172+
:param endpoint: Endpoint of the ReportPortal service.
173+
:param project: Project name to report to.
174+
:param api_key: Authorization API key.
175+
:param oauth_uri: OAuth 2.0 token endpoint URI (for OAuth authentication).
176+
:param oauth_username: Username for OAuth 2.0 authentication.
177+
:param oauth_password: Password for OAuth 2.0 authentication.
178+
:param oauth_client_id: OAuth 2.0 client ID.
179+
:param oauth_client_secret: OAuth 2.0 client secret (optional).
180+
:param oauth_scope: OAuth 2.0 scope (optional).
181+
:param is_skipped_an_issue: Option to mark skipped tests as not 'To Investigate' items on the
182+
server side.
183+
:param verify_ssl: Option to skip ssl verification.
184+
:param retries: Number of retry attempts to make in case of connection / server
185+
errors.
186+
:param max_pool_size: Option to set the maximum number of connections to save the pool.
187+
:param http_timeout: A float in seconds for connect and read timeout. Use a Tuple to
188+
specific connect and read separately.
189+
:param keepalive_timeout: Maximum amount of idle time in seconds before force connection
190+
closing.
191+
:param mode: Launch mode, all Launches started by the client will be in that mode.
192+
:param launch_uuid_print: Print Launch UUID into passed TextIO or by default to stdout.
193+
:param print_output: Set output stream for Launch UUID printing.
194+
:param truncate_attributes: Truncate test item attributes to default maximum length.
195+
:param truncate_fields: Truncate request fields to configured limits.
196+
:param replace_binary_chars: Toggle replacement of basic binary characters with \ufffd char.
197+
:param launch_name_length_limit: Maximum allowed launch name length.
198+
:param item_name_length_limit: Maximum allowed test item name length.
199+
:param launch_description_length_limit: Maximum allowed launch description length.
200+
:param item_description_length_limit: Maximum allowed test item description length.
177201
"""
178202
self.api_v1, self.api_v2 = "v1", "v2"
179203
self.endpoint = endpoint
@@ -193,6 +217,12 @@ def __init__(
193217
self._session = None
194218
self.__stat_task = None
195219
self.truncate_attributes = truncate_attributes
220+
self.truncate_fields = truncate_fields
221+
self.replace_binary_chars = replace_binary_chars
222+
self.launch_name_length_limit = launch_name_length_limit
223+
self.item_name_length_limit = item_name_length_limit
224+
self.launch_description_length_limit = launch_description_length_limit
225+
self.item_description_length_limit = item_description_length_limit
196226

197227
self.api_key = api_key
198228
# Handle deprecated token argument
@@ -341,7 +371,12 @@ async def start_launch(
341371
request_payload = LaunchStartRequest(
342372
name=name,
343373
start_time=start_time,
344-
attributes=verify_value_length(attributes) if self.truncate_attributes else attributes,
374+
attributes=attributes,
375+
truncate_attributes_enabled=self.truncate_attributes,
376+
truncate_fields_enabled=self.truncate_fields,
377+
replace_binary_characters=self.replace_binary_chars,
378+
launch_name_length_limit=self.launch_name_length_limit,
379+
launch_description_length_limit=self.launch_description_length_limit,
345380
description=description,
346381
mode=self.mode,
347382
rerun=rerun,
@@ -414,7 +449,12 @@ async def start_test_item(
414449
start_time,
415450
item_type,
416451
launch_uuid,
417-
attributes=verify_value_length(attributes) if self.truncate_attributes else attributes,
452+
attributes=attributes,
453+
truncate_attributes_enabled=self.truncate_attributes,
454+
truncate_fields_enabled=self.truncate_fields,
455+
replace_binary_characters=self.replace_binary_chars,
456+
item_name_length_limit=self.item_name_length_limit,
457+
item_description_length_limit=self.item_description_length_limit,
418458
code_ref=code_ref,
419459
description=description,
420460
has_stats=has_stats,
@@ -474,7 +514,11 @@ async def finish_test_item(
474514
end_time,
475515
launch_uuid,
476516
status,
477-
attributes=verify_value_length(attributes) if self.truncate_attributes else attributes,
517+
attributes=attributes,
518+
truncate_attributes_enabled=self.truncate_attributes,
519+
truncate_fields_enabled=self.truncate_fields,
520+
replace_binary_characters=self.replace_binary_chars,
521+
item_description_length_limit=self.item_description_length_limit,
478522
description=description,
479523
test_case_id=test_case_id,
480524
is_skipped_an_issue=self.is_skipped_an_issue,
@@ -514,7 +558,11 @@ async def finish_launch(
514558
request_payload = LaunchFinishRequest(
515559
end_time,
516560
status=status,
517-
attributes=verify_value_length(attributes) if self.truncate_attributes else attributes,
561+
attributes=attributes,
562+
truncate_attributes_enabled=self.truncate_attributes,
563+
truncate_fields_enabled=self.truncate_fields,
564+
replace_binary_characters=self.replace_binary_chars,
565+
launch_description_length_limit=self.launch_description_length_limit,
518566
description=kwargs.get("description"),
519567
).payload
520568
response = await AsyncHttpRequest(
@@ -539,10 +587,14 @@ async def update_test_item(
539587
:param description: Test Item description.
540588
:return: Response message or None.
541589
"""
542-
data = {
543-
"description": description,
544-
"attributes": verify_value_length(attributes) if self.truncate_attributes else attributes,
545-
}
590+
data = ItemUpdateRequest(
591+
description=description,
592+
attributes=attributes,
593+
truncate_attributes_enabled=self.truncate_attributes,
594+
truncate_fields_enabled=self.truncate_fields,
595+
replace_binary_characters=self.replace_binary_chars,
596+
item_description_length_limit=self.item_description_length_limit,
597+
).payload
546598
item_id = await self.get_item_id_by_uuid(item_uuid)
547599
url = root_uri_join(self.base_url_v1, "item", item_id, "update")
548600
response = await AsyncHttpRequest(
@@ -670,6 +722,13 @@ def clone(self) -> "Client":
670722
mode=self.mode,
671723
launch_uuid_print=self.launch_uuid_print,
672724
print_output=self.print_output,
725+
truncate_fields=self.truncate_fields,
726+
truncate_attributes=self.truncate_attributes,
727+
replace_binary_chars=self.replace_binary_chars,
728+
launch_name_length_limit=self.launch_name_length_limit,
729+
item_name_length_limit=self.item_name_length_limit,
730+
launch_description_length_limit=self.launch_description_length_limit,
731+
item_description_length_limit=self.item_description_length_limit,
673732
oauth_uri=self.oauth_uri,
674733
oauth_username=self.oauth_username,
675734
oauth_password=self.oauth_password,

0 commit comments

Comments
 (0)