1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
import pytest
from . import configs
from jenkinsapi.build import Build
from jenkinsapi.job import Job
@pytest.fixture(scope="function")
def jenkins(mocker):
return mocker.MagicMock()
@pytest.fixture(scope="function")
def job(monkeypatch, jenkins):
def fake_poll(cls, tree=None): # pylint: disable=unused-argument
return configs.JOB_DATA
monkeypatch.setattr(Job, "_poll", fake_poll)
fake_job = Job("http://", "Fake_Job", jenkins)
return fake_job
@pytest.fixture(scope="function")
def build(job, monkeypatch):
def fake_poll(cls, tree=None): # pylint: disable=unused-argument
return configs.BUILD_SCM_DATA
monkeypatch.setattr(Build, "_poll", fake_poll)
return Build("http://", 97, job)
def test_git_scm(build):
"""
Can we extract git build revision data from a build object?
"""
assert isinstance(build.get_revision(), str)
assert build.get_revision() == "7def9ed6e92580f37d00e4980c36c4d36e68f702"
def test_git_revision_branch(build):
"""
Can we extract git build branch from a build object?
"""
assert isinstance(build.get_revision_branch(), list)
assert len(build.get_revision_branch()) == 1
assert isinstance(build.get_revision_branch()[0], dict)
assert (
build.get_revision_branch()[0]["SHA1"]
== "7def9ed6e92580f37d00e4980c36c4d36e68f702"
)
assert build.get_revision_branch()[0]["name"] == "origin/unstable"
def test_git_repo_url(build):
"""
Can we Extract git repo url for a given build
"""
assert isinstance(build.get_repo_url(), str)
assert (
build.get_repo_url()
== "https://github.com/salimfadhley/jenkinsapi.git"
)
|