Skip to content

Commit

Permalink
Issue #192 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Sep 15, 2022
1 parent 993ff17 commit 57fb0d5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

## [Unreleased]
### Changed
- `LogManager` class moved from `core` package to `logs` package
- `LogManager` class moved from `core` package to `logs` package, by @HardNorth
### Fixed
- Issue [#192](https://github.com/reportportal/client-Python/issues/192): launch URL generation, by @HardNorth

## [5.2.3]
### Added
Expand Down
31 changes: 25 additions & 6 deletions reportportal_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from requests.adapters import HTTPAdapter, Retry

from ._local import set_current
from .logs.log_manager import LogManager, MAX_LOG_BATCH_PAYLOAD_SIZE
from .core.rp_requests import (
HttpRequest,
ItemStartRequest,
Expand All @@ -29,6 +28,7 @@
LaunchFinishRequest
)
from .helpers import uri_join, verify_value_length
from .logs.log_manager import LogManager, MAX_LOG_BATCH_PAYLOAD_SIZE
from .static.defines import NOT_FOUND
from .steps import StepReporter

Expand Down Expand Up @@ -59,6 +59,7 @@ def __init__(self,
launch_id=None,
http_timeout=(10, 10),
log_batch_payload_size=MAX_LOG_BATCH_PAYLOAD_SIZE,
mode='DEFAULT',
**_):
"""Initialize required attributes.
Expand Down Expand Up @@ -100,6 +101,7 @@ def __init__(self,
self.session = requests.Session()
self.step_reporter = StepReporter(self)
self._item_stack = []
self.mode = mode
if retries:
retry_strategy = Retry(
total=retries,
Expand Down Expand Up @@ -244,10 +246,19 @@ def get_launch_ui_url(self):
:return: launch URL or all launches URL.
"""
ui_id = self.get_launch_ui_id()
launch_info = self.get_launch_info()
ui_id = launch_info.get('id') if launch_info else None
if not ui_id:
return
path = 'ui/#{0}/launches/all/{1}'.format(self.project, ui_id)
mode = launch_info.get('mode') if launch_info else None
if not mode:
mode = self.mode

launch_type = "launches" if mode.upper() == 'DEFAULT' else 'userdebug'

path = 'ui/#{project_name}/{launch_type}/all/{launch_id}'.format(
project_name=self.project.lower(), launch_type=launch_type,
launch_id=ui_id)
url = uri_join(self.endpoint, path)
logger.debug('get_launch_ui_url - ID: %s', self.launch_id)
return url
Expand Down Expand Up @@ -282,7 +293,6 @@ def start_launch(self,
start_time,
description=None,
attributes=None,
mode=None,
rerun=False,
rerun_of=None,
**kwargs):
Expand All @@ -292,12 +302,21 @@ def start_launch(self,
:param start_time: Launch start time
:param description: Launch description
:param attributes: Launch attributes
:param mode: Launch mode
:param rerun: Enables launch rerun mode
:param rerun_of: Rerun mode. Specifies launch to be re-runned.
Should be used with the 'rerun' option.
"""
url = uri_join(self.base_url_v2, 'launch')

# We are moving 'mode' param to the constructor, next code for the
# transition period only.
my_kwargs = dict(kwargs)
mode = my_kwargs.get('mode')
if not mode:
mode = self.mode
else:
del my_kwargs['mode']

request_payload = LaunchStartRequest(
name=name,
start_time=start_time,
Expand All @@ -306,7 +325,7 @@ def start_launch(self,
mode=mode,
rerun=rerun,
rerun_of=rerun_of or kwargs.get('rerunOf'),
**kwargs
**my_kwargs
).payload
response = HttpRequest(self.session.post,
url=url,
Expand Down
1 change: 1 addition & 0 deletions reportportal_client/client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class RPClient:
http_timeout: Union[float, Tuple[float, float]] = ...
session: Session = ...
step_reporter: StepReporter = ...
mode: str = ...

def __init__(
self,
Expand Down
33 changes: 33 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest
from requests import Response
from requests.exceptions import ReadTimeout
from six.moves import mock

from reportportal_client.helpers import timestamp
from reportportal_client.static.defines import NOT_FOUND
Expand Down Expand Up @@ -56,3 +57,35 @@ def test_connection_errors(rp_client, requests_method, client_method,
getattr(rp_client.session, requests_method).side_effect = response_error
result = getattr(rp_client, client_method)(*client_params)
assert result == expected_result


LAUNCH_ID = 333
EXPECTED_DEFAULT_URL = 'http://endpoint/ui/#project/launches/all/' + str(
LAUNCH_ID)
EXPECTED_DEBUG_URL = 'http://endpoint/ui/#project/userdebug/all/' + str(
LAUNCH_ID)


@pytest.mark.parametrize(
'launch_mode, project_name, expected_url',
[
('DEFAULT', "project", EXPECTED_DEFAULT_URL),
('DEBUG', "project", EXPECTED_DEBUG_URL),
('DEFAULT', "PROJECT", EXPECTED_DEFAULT_URL),
('debug', "PROJECT", EXPECTED_DEBUG_URL)
]
)
def test_launch_url_get(rp_client, launch_mode, project_name, expected_url):
rp_client.launch_id = 'test_launch_id'
rp_client.project = project_name

response = mock.Mock()
response.is_success = True
response.json.side_effect = lambda: {'mode': launch_mode, 'id': LAUNCH_ID}

def get_call(*args, **kwargs):
return response

rp_client.session.get.side_effect = get_call

assert rp_client.get_launch_ui_url() == expected_url

0 comments on commit 57fb0d5

Please sign in to comment.