Exemplo n.º 1
0
def test_ref():
    from jenkins_epo.jenkins import Build

    build = Build(job=Mock(), payload={})

    with pytest.raises(Exception):
        build.ref

    build.job.revision_param = 'R'
    build.params['R'] = 'refs/heads/master'

    assert 'master' == build.ref

    build.actions['lastBuiltRevision'] = {
        'branch': [{
            'name': 'otherremote/master'
        }]
    }

    with pytest.raises(Exception):
        build.ref

    build.actions['lastBuiltRevision'] = {
        'branch': [{
            'name': 'refs/remote/origin/master'
        }]
    }

    assert 'master' == build.ref
Exemplo n.º 2
0
def test_ref():
    from jenkins_epo.jenkins import Build

    build = Build(job=Mock(), payload={})

    with pytest.raises(Exception):
        build.ref

    build.job.revision_param = 'R'
    build.params['R'] = 'refs/heads/master'

    assert 'master' == build.ref

    build.actions['lastBuiltRevision'] = {
        'branch': [{'name': 'otherremote/master'}]
    }

    with pytest.raises(Exception):
        build.ref

    build.actions['lastBuiltRevision'] = {
        'branch': [{'name': 'refs/remote/origin/master'}]
    }

    assert 'master' == build.ref
Exemplo n.º 3
0
def test_props():
    from jenkins_epo.jenkins import Build

    build = Build(job=Mock(),
                  payload={
                      'timestamp': 1000 * (time() - 3600 * 4),
                      'building': False,
                      'fullDisplayName': '#1'
                  })

    assert build.is_outdated
    assert not build.is_running
    assert str(build)
    assert repr(build)

    with pytest.raises(Exception):
        build.sha

    build = Build(job=Mock(),
                  payload=dict(build.payload,
                               actions=[{
                                   'lastBuiltRevision': {
                                       'branch': [{
                                           'SHA1': 'cafed0d0'
                                       }]
                                   }
                               }]))

    assert build.sha == 'cafed0d0'
Exemplo n.º 4
0
def test_params():
    from jenkins_epo.jenkins import Build

    assert 0 == len(Build.process_params({}))
    assert 0 == len(Build.process_params({'actions': [{'parameters': []}]}))
    assert 0 == len(Build.process_params({
        'actions': [{'parameters': [{'name': 'value'}]}]
    }))
Exemplo n.º 5
0
def test_stop(SETTINGS, mocker):
    Client = mocker.patch('jenkins_epo.jenkins.rest.Client')

    from jenkins_epo.jenkins import Build

    build = Build(Mock(), payload=dict(url='jenkins://'))
    Client().stop.apost = CoroutineMock()

    yield from build.stop()

    assert Client().stop.apost.mock_calls
Exemplo n.º 6
0
def test_stop(SETTINGS, mocker):
    Client = mocker.patch('jenkins_epo.jenkins.rest.Client')

    from jenkins_epo.jenkins import Build

    build = Build(Mock(), payload=dict(url='jenkins://'))
    Client().stop.apost = CoroutineMock()

    yield from build.stop()

    assert Client().stop.apost.mock_calls
Exemplo n.º 7
0
def test_params():
    from jenkins_epo.jenkins import Build

    assert 0 == len(Build.process_params({}))
    assert 0 == len(Build.process_params({'actions': [{'parameters': []}]}))
    assert 0 == len(
        Build.process_params(
            {'actions': [{
                'parameters': [{
                    'name': 'value'
                }]
            }]}))
Exemplo n.º 8
0
def test_from_url(SETTINGS, mocker):
    SETTINGS.JENKINS_URL = 'jenkins://'
    Client = mocker.patch('jenkins_epo.jenkins.rest.Client')

    from jenkins_epo.jenkins import Build, NotOnJenkins

    with pytest.raises(NotOnJenkins):
        yield from Build.from_url('circleci:///')

    Client().api.python.aget = CoroutineMock(return_value=dict(number=1))

    build = yield from Build.from_url('jenkins://job/1')

    assert 1 == build.number
Exemplo n.º 9
0
def test_from_url(SETTINGS, mocker):
    SETTINGS.JENKINS_URL = 'jenkins://'
    Client = mocker.patch('jenkins_epo.jenkins.rest.Client')

    from jenkins_epo.jenkins import Build, NotOnJenkins

    with pytest.raises(NotOnJenkins):
        yield from Build.from_url('circleci:///')

    Client().api.python.aget = CoroutineMock(return_value=dict(number=1))

    build = yield from Build.from_url('jenkins://job/1')

    assert 1 == build.number
Exemplo n.º 10
0
def test_commit_status():
    from jenkins_epo.jenkins import Build

    payload = dict(displayName='#3 on master', duration=0, url='url://job/1')
    build = Build(Mock(), payload=dict(payload, result=None))
    assert 'pending' == build.commit_status['state']

    build = Build(Mock(), payload=dict(payload, result='ABORTED'))
    assert 'error' == build.commit_status['state']

    build = Build(Mock(), payload=dict(payload, result='SUCCESS'))
    assert 'success' == build.commit_status['state']

    build = Build(Mock(), payload=dict(payload, result='FAILURE'))
    assert 'failure' == build.commit_status['state']
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
def test_future():
    from jenkins_epo.jenkins import Build

    build = Build(job=Mock(), payload={'timestamp': 1000 * (time() + 300)})

    assert not build.is_outdated