Пример #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
Пример #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
Пример #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'
Пример #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'}]}]
    }))
Пример #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
Пример #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
Пример #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'
                }]
            }]}))
Пример #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
Пример #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
Пример #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']
Пример #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)
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)
Пример #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