Skip to content
This repository has been archived by the owner on Oct 3, 2018. It is now read-only.

Commit

Permalink
Fix URL for accessing the API of a build
Browse files Browse the repository at this point in the history
At some point between Jenkins 2.52 and 2.59, the URL returned at job
creation by jenkins changed from the url of the job to that url suffixed
with /display/redirect. When suffixing all that with /api/python, the
api part is ignored. This commit removes the /display/redirect just
before using it.
  • Loading branch information
Joachim Jablon committed May 10, 2017
1 parent e9972da commit 0f9d54e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions jenkins_epo/jenkins.py
Expand Up @@ -180,6 +180,9 @@ def from_url(cls, url):
if not url.startswith(SETTINGS.JENKINS_URL):
raise NotOnJenkins("%s is not on this Jenkins." % url)

if url.endswith("/display/redirect"):
url = url.replace("/display/redirect", "")

payload = yield from rest.Client(url).api.python.aget(
tree=cls.jenkins_tree,
)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_jenkins.py
Expand Up @@ -481,3 +481,23 @@ def test_job_updated_at(JobSpec):

job = Job(Mock(_data=dict(description="""no yaml""")))
assert not job.updated_at


@pytest.mark.asyncio
@asyncio.coroutine
def test_from_url_removes_suffix(mocker, SETTINGS):
from jenkins_epo.jenkins import Build
Client = mocker.patch('jenkins_epo.jenkins.rest.Client')
Client().api.python.aget = aget = CoroutineMock(
return_value={}
)
SETTINGS.JENKINS_URL = "http://jenkins.local"
url = SETTINGS.JENKINS_URL + "/job/rh2-build-doc/4910/display/redirect"
correct_url = SETTINGS.JENKINS_URL + "/job/rh2-build-doc/4910"

build = yield from Build.from_url(url)

assert isinstance(build, Build)
assert build.job is None
assert build.payload == {}
assert Client.mock_calls[1] == mocker.call(correct_url)

0 comments on commit 0f9d54e

Please sign in to comment.