Skip to content

Commit 57fb0d5

Browse files
committed
Issue #192 fix
1 parent 993ff17 commit 57fb0d5

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

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

79
## [5.2.3]
810
### Added

reportportal_client/client.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from requests.adapters import HTTPAdapter, Retry
2121

2222
from ._local import set_current
23-
from .logs.log_manager import LogManager, MAX_LOG_BATCH_PAYLOAD_SIZE
2423
from .core.rp_requests import (
2524
HttpRequest,
2625
ItemStartRequest,
@@ -29,6 +28,7 @@
2928
LaunchFinishRequest
3029
)
3130
from .helpers import uri_join, verify_value_length
31+
from .logs.log_manager import LogManager, MAX_LOG_BATCH_PAYLOAD_SIZE
3232
from .static.defines import NOT_FOUND
3333
from .steps import StepReporter
3434

@@ -59,6 +59,7 @@ def __init__(self,
5959
launch_id=None,
6060
http_timeout=(10, 10),
6161
log_batch_payload_size=MAX_LOG_BATCH_PAYLOAD_SIZE,
62+
mode='DEFAULT',
6263
**_):
6364
"""Initialize required attributes.
6465
@@ -100,6 +101,7 @@ def __init__(self,
100101
self.session = requests.Session()
101102
self.step_reporter = StepReporter(self)
102103
self._item_stack = []
104+
self.mode = mode
103105
if retries:
104106
retry_strategy = Retry(
105107
total=retries,
@@ -244,10 +246,19 @@ def get_launch_ui_url(self):
244246
245247
:return: launch URL or all launches URL.
246248
"""
247-
ui_id = self.get_launch_ui_id()
249+
launch_info = self.get_launch_info()
250+
ui_id = launch_info.get('id') if launch_info else None
248251
if not ui_id:
249252
return
250-
path = 'ui/#{0}/launches/all/{1}'.format(self.project, ui_id)
253+
mode = launch_info.get('mode') if launch_info else None
254+
if not mode:
255+
mode = self.mode
256+
257+
launch_type = "launches" if mode.upper() == 'DEFAULT' else 'userdebug'
258+
259+
path = 'ui/#{project_name}/{launch_type}/all/{launch_id}'.format(
260+
project_name=self.project.lower(), launch_type=launch_type,
261+
launch_id=ui_id)
251262
url = uri_join(self.endpoint, path)
252263
logger.debug('get_launch_ui_url - ID: %s', self.launch_id)
253264
return url
@@ -282,7 +293,6 @@ def start_launch(self,
282293
start_time,
283294
description=None,
284295
attributes=None,
285-
mode=None,
286296
rerun=False,
287297
rerun_of=None,
288298
**kwargs):
@@ -292,12 +302,21 @@ def start_launch(self,
292302
:param start_time: Launch start time
293303
:param description: Launch description
294304
:param attributes: Launch attributes
295-
:param mode: Launch mode
296305
:param rerun: Enables launch rerun mode
297306
:param rerun_of: Rerun mode. Specifies launch to be re-runned.
298307
Should be used with the 'rerun' option.
299308
"""
300309
url = uri_join(self.base_url_v2, 'launch')
310+
311+
# We are moving 'mode' param to the constructor, next code for the
312+
# transition period only.
313+
my_kwargs = dict(kwargs)
314+
mode = my_kwargs.get('mode')
315+
if not mode:
316+
mode = self.mode
317+
else:
318+
del my_kwargs['mode']
319+
301320
request_payload = LaunchStartRequest(
302321
name=name,
303322
start_time=start_time,
@@ -306,7 +325,7 @@ def start_launch(self,
306325
mode=mode,
307326
rerun=rerun,
308327
rerun_of=rerun_of or kwargs.get('rerunOf'),
309-
**kwargs
328+
**my_kwargs
310329
).payload
311330
response = HttpRequest(self.session.post,
312331
url=url,

reportportal_client/client.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class RPClient:
2727
http_timeout: Union[float, Tuple[float, float]] = ...
2828
session: Session = ...
2929
step_reporter: StepReporter = ...
30+
mode: str = ...
3031

3132
def __init__(
3233
self,

tests/test_client.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import pytest
1515
from requests import Response
1616
from requests.exceptions import ReadTimeout
17+
from six.moves import mock
1718

1819
from reportportal_client.helpers import timestamp
1920
from reportportal_client.static.defines import NOT_FOUND
@@ -56,3 +57,35 @@ def test_connection_errors(rp_client, requests_method, client_method,
5657
getattr(rp_client.session, requests_method).side_effect = response_error
5758
result = getattr(rp_client, client_method)(*client_params)
5859
assert result == expected_result
60+
61+
62+
LAUNCH_ID = 333
63+
EXPECTED_DEFAULT_URL = 'http://endpoint/ui/#project/launches/all/' + str(
64+
LAUNCH_ID)
65+
EXPECTED_DEBUG_URL = 'http://endpoint/ui/#project/userdebug/all/' + str(
66+
LAUNCH_ID)
67+
68+
69+
@pytest.mark.parametrize(
70+
'launch_mode, project_name, expected_url',
71+
[
72+
('DEFAULT', "project", EXPECTED_DEFAULT_URL),
73+
('DEBUG', "project", EXPECTED_DEBUG_URL),
74+
('DEFAULT', "PROJECT", EXPECTED_DEFAULT_URL),
75+
('debug', "PROJECT", EXPECTED_DEBUG_URL)
76+
]
77+
)
78+
def test_launch_url_get(rp_client, launch_mode, project_name, expected_url):
79+
rp_client.launch_id = 'test_launch_id'
80+
rp_client.project = project_name
81+
82+
response = mock.Mock()
83+
response.is_success = True
84+
response.json.side_effect = lambda: {'mode': launch_mode, 'id': LAUNCH_ID}
85+
86+
def get_call(*args, **kwargs):
87+
return response
88+
89+
rp_client.session.get.side_effect = get_call
90+
91+
assert rp_client.get_launch_ui_url() == expected_url

0 commit comments

Comments
 (0)