Skip to content

Commit 6819161

Browse files
committed
Add reportportal_client.helpers.markdown_helpers and helpers refactoring
1 parent 6ac645d commit 6819161

File tree

7 files changed

+377
-24
lines changed

7 files changed

+377
-24
lines changed

CHANGELOG.md

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

33
## [Unreleased]
4+
### Added
5+
- `markdown_helpers` module in `reportportal_client.helpers` package, by @HardNorth
46
### Changed
57
- `helpers.is_binary` function to improve binary content detection, by @HardNorth
8+
- `helpers` module moved to `reportportal_client.helpers` package, by @HardNorth
69

710
## [5.6.0]
811
### Added

reportportal_client/aio/client.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ async def __get_item_url(self, item_id_future: Union[Optional[str], Task[Optiona
227227
item_id = await await_if_necessary(item_id_future)
228228
if item_id is NOT_FOUND or item_id is None:
229229
logger.warning("Attempt to make request for non-existent id.")
230-
return
230+
return None
231231
return root_uri_join(self.base_url_v2, "item", item_id)
232232

233233
async def __get_launch_url(self, launch_uuid_future: Union[Optional[str], Task[Optional[str]]]) -> Optional[str]:
234234
launch_uuid = await await_if_necessary(launch_uuid_future)
235235
if launch_uuid is NOT_FOUND or launch_uuid is None:
236236
logger.warning("Attempt to make request for non-existent launch.")
237-
return
237+
return None
238238
return root_uri_join(self.base_url_v2, "launch", launch_uuid, "finish")
239239

240240
async def start_launch(
@@ -272,7 +272,7 @@ async def start_launch(
272272

273273
response = await AsyncHttpRequest((await self.session()).post, url=url, json=request_payload).make()
274274
if not response:
275-
return
275+
return None
276276

277277
if not self._skip_analytics:
278278
stat_coro = async_send_event("start_launch", *agent_name_version(attributes))
@@ -347,7 +347,7 @@ async def start_test_item(
347347

348348
response = await AsyncHttpRequest((await self.session()).post, url=url, json=request_payload).make()
349349
if not response:
350-
return
350+
return None
351351
item_id = await response.id
352352
if item_id is NOT_FOUND or item_id is None:
353353
logger.warning("start_test_item - invalid response: %s", str(await response.json))
@@ -402,7 +402,7 @@ async def finish_test_item(
402402
).payload
403403
response = await AsyncHttpRequest((await self.session()).put, url=url, json=request_payload).make()
404404
if not response:
405-
return
405+
return None
406406
message = await response.message
407407
logger.debug("finish_test_item - ID: %s", await await_if_necessary(item_id))
408408
logger.debug("response message: %s", message)
@@ -437,7 +437,7 @@ async def finish_launch(
437437
(await self.session()).put, url=url, json=request_payload, name="Finish Launch"
438438
).make()
439439
if not response:
440-
return
440+
return None
441441
message = await response.message
442442
logger.debug("finish_launch - ID: %s", await await_if_necessary(launch_uuid))
443443
logger.debug("response message: %s", message)
@@ -465,15 +465,15 @@ async def update_test_item(
465465
url = root_uri_join(self.base_url_v1, "item", item_id, "update")
466466
response = await AsyncHttpRequest((await self.session()).put, url=url, json=data).make()
467467
if not response:
468-
return
468+
return None
469469
logger.debug("update_test_item - Item: %s", item_id)
470470
return await response.message
471471

472472
async def __get_launch_uuid_url(self, launch_uuid_future: Union[str, Task[str]]) -> Optional[str]:
473473
launch_uuid = await await_if_necessary(launch_uuid_future)
474474
if launch_uuid is NOT_FOUND or launch_uuid is None:
475475
logger.warning("Attempt to make request for non-existent Launch UUID.")
476-
return
476+
return None
477477
logger.debug("get_launch_info - ID: %s", launch_uuid)
478478
return root_uri_join(self.base_url_v1, "launch", "uuid", launch_uuid)
479479

@@ -486,7 +486,7 @@ async def get_launch_info(self, launch_uuid_future: Union[str, Task[str]]) -> Op
486486
url = self.__get_launch_uuid_url(launch_uuid_future)
487487
response = await AsyncHttpRequest((await self.session()).get, url=url).make()
488488
if not response:
489-
return
489+
return None
490490
launch_info = None
491491
if response.is_success:
492492
launch_info = await response.json
@@ -499,7 +499,7 @@ async def __get_item_uuid_url(self, item_uuid_future: Union[Optional[str], Task[
499499
item_uuid = await await_if_necessary(item_uuid_future)
500500
if item_uuid is NOT_FOUND or item_uuid is None:
501501
logger.warning("Attempt to make request for non-existent UUID.")
502-
return
502+
return None
503503
return root_uri_join(self.base_url_v1, "item", "uuid", item_uuid)
504504

505505
async def get_item_id_by_uuid(self, item_uuid_future: Union[str, Task[str]]) -> Optional[str]:
@@ -531,7 +531,7 @@ async def get_launch_ui_url(self, launch_uuid_future: Union[str, Task[str]]) ->
531531
launch_info = await self.get_launch_info(launch_uuid)
532532
launch_id = launch_info.get("id") if launch_info else None
533533
if not launch_id:
534-
return
534+
return None
535535
mode = launch_info.get("mode") if launch_info else None
536536
if not mode:
537537
mode = self.mode
@@ -564,7 +564,7 @@ async def log_batch(self, log_batch: Optional[List[AsyncRPRequestLog]]) -> Optio
564564
(await self.session()).post, url=url, data=AsyncRPLogBatch(log_batch).payload
565565
).make()
566566
if not response:
567-
return
567+
return None
568568
return await response.messages
569569

570570
def clone(self) -> "Client":
@@ -931,7 +931,7 @@ async def get_launch_ui_id(self) -> Optional[int]:
931931
:return: Launch ID of the Launch. None if not found.
932932
"""
933933
if not self.launch_uuid:
934-
return
934+
return None
935935
return await self.__client.get_launch_ui_id(self.launch_uuid)
936936

937937
async def get_launch_ui_url(self) -> Optional[str]:
@@ -940,7 +940,7 @@ async def get_launch_ui_url(self) -> Optional[str]:
940940
:return: Launch URL string.
941941
"""
942942
if not self.launch_uuid:
943-
return
943+
return None
944944
return await self.__client.get_launch_ui_url(self.launch_uuid)
945945

946946
async def get_project_settings(self) -> Optional[dict]:
@@ -972,7 +972,7 @@ async def log(
972972
"""
973973
if item_id is NOT_FOUND:
974974
logger.warning("Attempt to log to non-existent item")
975-
return
975+
return None
976976
rp_file = RPFile(**attachment) if attachment else None
977977
rp_log = AsyncRPRequestLog(self.launch_uuid, time, rp_file, item_id, level, message)
978978
return await self.__client.log_batch(await self._log_batcher.append_async(rp_log))
@@ -1555,7 +1555,7 @@ def create_task(self, coro: Coroutine[Any, Any, _T]) -> Optional[Task[_T]]:
15551555
:return: Task instance.
15561556
"""
15571557
if not getattr(self, "_loop", None):
1558-
return
1558+
return None
15591559
result = self._loop.create_task(coro)
15601560
with self._task_mutex:
15611561
self._task_list.append(result)
@@ -1742,7 +1742,7 @@ def create_task(self, coro: Coroutine[Any, Any, _T]) -> Optional[Task[_T]]:
17421742
:return: Task instance.
17431743
"""
17441744
if not getattr(self, "_loop", None):
1745-
return
1745+
return None
17461746
result = self._loop.create_task(coro)
17471747
with self._task_mutex:
17481748
tasks = self._task_list.append(result)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""This package contains helper functions."""
2+
3+
from reportportal_client.helpers import markdown_helpers
4+
from reportportal_client.helpers.common_helpers import (
5+
ATTRIBUTE_LENGTH_LIMIT,
6+
TRUNCATE_REPLACEMENT,
7+
CONTENT_TYPE_TO_EXTENSIONS,
8+
TYPICAL_MULTIPART_FOOTER_LENGTH,
9+
LifoQueue,
10+
agent_name_version,
11+
await_if_necessary,
12+
calculate_file_part_size,
13+
calculate_json_part_size,
14+
caseless_equal,
15+
dict_to_payload,
16+
gen_attributes,
17+
generate_uuid,
18+
get_function_params,
19+
get_launch_sys_attrs,
20+
get_package_parameters,
21+
get_package_version,
22+
guess_content_type_from_bytes,
23+
is_binary,
24+
match_pattern,
25+
normalize_caseless,
26+
root_uri_join,
27+
timestamp,
28+
to_bool,
29+
translate_glob_to_regex,
30+
truncate_attribute_string,
31+
uri_join,
32+
verify_value_length,
33+
)
34+
35+
__all__ = [
36+
"markdown_helpers",
37+
"ATTRIBUTE_LENGTH_LIMIT",
38+
"TRUNCATE_REPLACEMENT",
39+
"CONTENT_TYPE_TO_EXTENSIONS",
40+
"TYPICAL_MULTIPART_FOOTER_LENGTH",
41+
"LifoQueue",
42+
"agent_name_version",
43+
"await_if_necessary",
44+
"calculate_file_part_size",
45+
"calculate_json_part_size",
46+
"caseless_equal",
47+
"dict_to_payload",
48+
"gen_attributes",
49+
"generate_uuid",
50+
"get_function_params",
51+
"get_launch_sys_attrs",
52+
"get_package_parameters",
53+
"get_package_version",
54+
"guess_content_type_from_bytes",
55+
"is_binary",
56+
"match_pattern",
57+
"normalize_caseless",
58+
"root_uri_join",
59+
"timestamp",
60+
"to_bool",
61+
"translate_glob_to_regex",
62+
"truncate_attribute_string",
63+
"uri_join",
64+
"verify_value_length",
65+
]

reportportal_client/helpers.py renamed to reportportal_client/helpers/common_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def verify_value_length(attributes: Optional[Union[List[dict], dict]]) -> Option
253253
:return: List of attributes with corrected value length
254254
"""
255255
if attributes is None:
256-
return
256+
return attributes
257257

258258
my_attributes = attributes
259259
if isinstance(my_attributes, dict):

0 commit comments

Comments
 (0)