Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Commit

Permalink
Merge e205dce into 30fc616
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Hoang Dang committed Jul 4, 2018
2 parents 30fc616 + e205dce commit 15e1ac4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
5 changes: 5 additions & 0 deletions sktm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import sktm.jenkins
import sktm.patchwork

def join_with_slash(base, suffix):
base = base.rstrip('/')
suffix = suffix.lstrip('/')
return "{}/{}".format(base, suffix)


class tresult(enum.IntEnum):
"""Test result"""
Expand Down
31 changes: 18 additions & 13 deletions sktm/patchwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,10 @@ def get_project_id(self, project_name):
Returns:
Integer representing project's ID.
"""
response = requests.get("%s/%s" % (self.apiurls.get("projects"),
project_name))
response = requests.get(
sktm.join_with_slash(self.apiurls.get("projects"),
project_name)
)
if response.status_code != requests.codes.ok:
raise Exception("Can't get project data: %s %d" %
(project_name, response.status_code))
Expand All @@ -475,7 +477,7 @@ def get_apiurls(self, baseurl):
Returns:
The JSON representation of the API URLs.
"""
response = requests.get("%s/api" % baseurl)
response = requests.get(sktm.join_with_slash(baseurl, "api"))
if response.status_code != 200:
raise Exception("Can't get apiurls: %d" % response.status_code)

Expand Down Expand Up @@ -700,7 +702,10 @@ def get_patch_by_id(self, pid):
set of supported attributes depends on which API versions are
supported by a specific Patchwork instance.
"""
response = requests.get("%s/%d" % (self.apiurls.get("patches"), pid))
response = requests.get(
sktm.join_with_slash(self.apiurls.get("patches"),
str(pid))
)

if response.status_code != 200:
raise Exception("Can't get patch by id %d (%d)" %
Expand Down Expand Up @@ -745,10 +750,10 @@ def get_patchsets_by_patch(self, url, seen=set()):
if sid in seen:
continue
else:
series_list += self.get_series_from_url("%s/%d" % (
self.apiurls.get("series"),
sid
))
series_list += self.get_series_from_url(
sktm.join_with_slash(self.apiurls.get("series"),
str(sid))
)
seen.add(sid)

link = response.headers.get("Link")
Expand Down Expand Up @@ -811,10 +816,10 @@ def get_patchsets(self, patchlist):
for series in patch.get("series"):
sid = series.get("id")
if sid not in seen:
series_list += self.get_series_from_url("%s/%d" % (
self.apiurls.get("series"),
sid
))
series_list += self.get_series_from_url(
sktm.join_with_slash(self.apiurls.get("series"),
str(sid))
)
seen.add(sid)

return series_list
Expand Down Expand Up @@ -871,7 +876,7 @@ def get_rpc(self, baseurl):
Returns:
The XML RPC interface for the Patchwork
"""
rpc = xmlrpclib.ServerProxy("%s/xmlrpc/" % baseurl)
rpc = xmlrpclib.ServerProxy(sktm.join_with_slash(baseurl, "xmlrpc/"))
try:
ver = rpc.pw_rpc_version()
# check for normal patchwork1 xmlrpc version numbers
Expand Down
22 changes: 22 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@
import sktm


class TestIndependent(unittest.TestCase):
"""Test cases for independent functions in __init__.py."""
def test_join_with_slash(self):
"""Ensure join_with_slash return a good url, path string."""
base = "path/to/dir"
suffix = "file"
self.assertEqual("path/to/dir/file",
sktm.join_with_slash(base, suffix))
base = "path/to/dir/"
suffix = "file"
self.assertEqual("path/to/dir/file",
sktm.join_with_slash(base, suffix))
base = "http://url.com/"
suffix = "part"
self.assertEqual("http://url.com/part",
sktm.join_with_slash(base, suffix))
base = "http://url.com"
suffix = "part"
self.assertEqual("http://url.com/part",
sktm.join_with_slash(base, suffix))


class TestInit(unittest.TestCase):
"""Test cases for the __init__ module."""

Expand Down

0 comments on commit 15e1ac4

Please sign in to comment.