Skip to content

Commit 1abe699

Browse files
author
Dzmitry Humianiuk
authored
Merge pull request #1 from PositiveAlex/master
Fixed bugs of using report portal client on windows
2 parents 7dd2f9c + 5e58e84 commit 1abe699

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

reportportal_client/service.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,75 @@
66

77

88
class ReportPortalService(object):
9+
"""Service class with report portal event callbacks."""
10+
911
def __init__(self, endpoint, project, token, api_base=None):
12+
"""Init the service class.
13+
14+
Args:
15+
endpoint: endpoint of report portal service.
16+
project: project name to use for launch names.
17+
token: authorization token.
18+
api_base: defaults to api/v1, can be customized to use another version.
19+
"""
1020
super(ReportPortalService, self).__init__()
1121
self.endpoint = endpoint
1222
if api_base is None:
1323
self.api_base = "api/v1"
1424
self.project = project
1525
self.token = token
16-
self.base_url = os.path.join(self.endpoint,
17-
self.api_base,
18-
self.project)
26+
self.base_url = self.uri_join(self.endpoint,
27+
self.api_base,
28+
self.project)
1929
self.headers = {"Content-Type": "application/json",
2030
"Authorization": "{0} {1}".format("bearer",
2131
self.token)}
2232
self.session = requests.Session()
2333

34+
@staticmethod
35+
def uri_join(*uri_parts):
36+
"""Join uri parts.
37+
38+
Avoiding usage of urlparse.urljoin and os.path.join as it does not clearly join parts.
39+
40+
Args:
41+
*uri_parts: tuple of values for join, can contain back and forward slashes (will be stripped up).
42+
43+
Returns:
44+
An uri string.
45+
"""
46+
stripped = [str(i).strip('/').strip('\\') for i in uri_parts]
47+
return '/'.join(stripped)
48+
2449
def start_launch(self, start_launch_rq):
25-
url = os.path.join(self.base_url, "launch")
50+
url = self.uri_join(self.base_url, "launch")
2651
r = self.session.post(url=url, headers=self.headers,
27-
data=start_launch_rq.data)
52+
data=start_launch_rq.data)
2853
return EntryCreatedRS(raw=r.text)
2954

3055
def finish_launch(self, launch_id, finish_execution_rq):
31-
url = os.path.join(self.base_url, "launch", launch_id, "finish")
56+
url = self.uri_join(self.base_url, "launch", launch_id, "finish")
3257
r = self.session.put(url=url, headers=self.headers,
33-
data=finish_execution_rq.data)
58+
data=finish_execution_rq.data)
3459
return OperationCompletionRS(raw=r.text)
3560

3661
def start_test_item(self, parent_item_id, start_test_item_rq):
3762
if parent_item_id is not None:
38-
url = os.path.join(self.base_url, "item", parent_item_id)
63+
url = self.uri_join(self.base_url, "item", parent_item_id)
3964
else:
40-
url = os.path.join(self.base_url, "item")
65+
url = self.uri_join(self.base_url, "item")
4166
r = self.session.post(url=url, headers=self.headers,
42-
data=start_test_item_rq.data)
67+
data=start_test_item_rq.data)
4368
return EntryCreatedRS(raw=r.text)
4469

4570
def finish_test_item(self, item_id, finish_test_item_rq):
46-
url = os.path.join(self.base_url, "item", item_id)
71+
url = self.uri_join(self.base_url, "item", item_id)
4772
r = self.session.put(url=url, headers=self.headers,
48-
data=finish_test_item_rq.data)
73+
data=finish_test_item_rq.data)
4974
return OperationCompletionRS(raw=r.text)
5075

5176
def log(self, save_log_rq):
52-
url = os.path.join(self.base_url, "log")
77+
url = self.uri_join(self.base_url, "log")
5378
r = self.session.post(url=url, headers=self.headers,
54-
data=save_log_rq.data)
79+
data=save_log_rq.data)
5580
return EntryCreatedRS(raw=r.text)

0 commit comments

Comments
 (0)