Skip to content

Commit 510119c

Browse files
Method of ReportPortalService to get launch UI URL
1 parent fa091f7 commit 510119c

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

reportportal_client/service.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,36 @@ def finish_launch(self, end_time, status=None, **kwargs):
249249
logger.debug("finish_launch - ID: %s", self.launch_id)
250250
return _get_msg(r)
251251

252+
def get_launch_info(self):
253+
"""Get the current launch information.
254+
255+
:return dict: launch information
256+
"""
257+
url = uri_join(self.base_url_v1, "launch/uuid", self.launch_id)
258+
launch_info = _get_json(self.session.get(
259+
url=url, verify=self.verify_ssl))
260+
logger.debug("get_launch_info - ID: %s", self.launch_id)
261+
logger.debug("get_launch_info - Launch info: %s", launch_info)
262+
return launch_info
263+
264+
def get_launch_ui_id(self):
265+
"""Get UI ID of the current launch.
266+
267+
:return str: UI ID of the given launch.
268+
"""
269+
return self.get_launch_info()["id"]
270+
271+
def get_launch_ui_url(self):
272+
"""Get UI URL of the current launch.
273+
274+
:return str: launch URL.
275+
"""
276+
ui_id = self.get_launch_ui_id()
277+
path = "ui/#{0}/launches/all/{1}".format(self.project, ui_id)
278+
url = uri_join(self.endpoint, path)
279+
logger.debug("get_launch_ui_url - ID: %s", self.launch_id)
280+
return url
281+
252282
def start_test_item(self,
253283
name,
254284
start_time,

tests/test_service.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,53 @@ def test_finish_launch(self, mock_get, rp_service):
8787
'name', datetime.now().isoformat())
8888
assert _get_msg == {'id': 111}
8989

90+
@mock.patch('reportportal_client.service._get_json',
91+
mock.Mock(return_value={'id': 112}))
92+
def test_get_launch_info(self, rp_service, monkeypatch):
93+
"""Test get current launch information.
94+
95+
:param rp_service: Pytest fixture that represents ReportPortalService
96+
object with mocked session.
97+
:param monkeypatch: Pytest fixture to safely set/delete an attribute
98+
"""
99+
mock_get = mock.Mock(return_value={'id': 112})
100+
monkeypatch.setattr(rp_service.session, 'get', mock_get)
101+
102+
launch_id = rp_service.get_launch_info()
103+
mock_get.assert_called_once_with(
104+
url='{0}/launch/uuid/{1}'.format(rp_service.base_url_v1,
105+
rp_service.launch_id),
106+
verify=rp_service.verify_ssl)
107+
assert launch_id == {'id': 112}
108+
109+
def test_get_launch_ui_id(self, rp_service, monkeypatch):
110+
"""Test get launch UI ID.
111+
112+
:param rp_service: Pytest fixture that represents ReportPortalService
113+
object with mocked session.
114+
:param monkeypatch: Pytest fixture to safely set/delete an attribute
115+
"""
116+
mock_get_launch_info = mock.Mock(return_value={'id': 113})
117+
monkeypatch.setattr(rp_service,
118+
'get_launch_info',
119+
mock_get_launch_info)
120+
assert rp_service.get_launch_ui_id() == 113
121+
122+
def test_get_launch_ui_url(self, rp_service, monkeypatch):
123+
"""Test get launch UI URL.
124+
125+
:param rp_service: Pytest fixture that represents ReportPortalService
126+
object with mocked session.
127+
:param monkeypatch: Pytest fixture to safely set/delete an attribute
128+
"""
129+
mock_get_launch_ui_id = mock.Mock(return_value=1)
130+
monkeypatch.setattr(rp_service,
131+
'get_launch_ui_id',
132+
mock_get_launch_ui_id)
133+
url = rp_service.get_launch_ui_url()
134+
assert url == '{0}/ui/#{1}/launches/all/1'.format(rp_service.endpoint,
135+
rp_service.project)
136+
90137
@mock.patch('platform.system', mock.Mock(return_value='linux'))
91138
@mock.patch('platform.machine', mock.Mock(return_value='Windows-PC'))
92139
@mock.patch('platform.processor', mock.Mock(return_value='amd'))

0 commit comments

Comments
 (0)