Ejemplo n.º 1
0
def test_update_job(mocker, SETTINGS):
    aget_job = mocker.patch(
        'jenkins_epo.jenkins.JENKINS.aget_job',
        CoroutineMock(),
    )
    rest = mocker.patch('jenkins_epo.jenkins.JENKINS.rest')

    url = rest.job()
    url.api.python.aget = CoroutineMock()
    url().aget = CoroutineMock()
    url().apost = CoroutineMock()

    from jenkins_epo.jenkins import Job

    SETTINGS.DRY_RUN = 1

    spec = Mock(config=dict())
    spec.name = 'job'

    job = Job(Mock(_data=dict()))
    new_job = yield from job.update(spec)
    assert new_job is job

    SETTINGS.DRY_RUN = 0
    new_job = yield from job.update(spec)
    assert new_job is not job
    assert aget_job.mock_calls
def test_update_job(mocker, SETTINGS):
    aget_job = mocker.patch(
        'jenkins_epo.jenkins.JENKINS.aget_job',
        CoroutineMock(),
    )
    rest = mocker.patch('jenkins_epo.jenkins.JENKINS.rest')

    url = rest.job()
    url.api.python.aget = CoroutineMock()
    url().aget = CoroutineMock()
    url().apost = CoroutineMock()

    from jenkins_epo.jenkins import Job

    SETTINGS.DRY_RUN = 1

    spec = Mock(config=dict())
    spec.name = 'job'

    job = Job(Mock(_data=dict()))
    new_job = yield from job.update(spec)
    assert new_job is job

    SETTINGS.DRY_RUN = 0
    new_job = yield from job.update(spec)
    assert new_job is not job
    assert aget_job.mock_calls
def test_job_managed(from_xml, SETTINGS):
    from jenkins_epo.jenkins import Job

    SETTINGS.JOBS_AUTO = 0

    job = Job(Mock(_data=dict()))
    job.jobs_filter = []
    job._instance.name = 'job'
    job._instance.get_scm_url.return_value = []

    assert job.managed
Ejemplo n.º 4
0
def test_job_managed(from_xml, SETTINGS):
    from jenkins_epo.jenkins import Job

    SETTINGS.JOBS_AUTO = 0

    job = Job(Mock(_data=dict()))
    job.jobs_filter = []
    job._instance.name = 'job'
    job._instance.get_scm_url.return_value = []

    assert job.managed
Ejemplo n.º 5
0
def test_fetch_builds(mocker):
    Client = mocker.patch('jenkins_epo.jenkins.rest.Client')
    Client().api.python.aget = aget = CoroutineMock(return_value=dict(
        builds=[]))
    from jenkins_epo.jenkins import Job

    api_instance = Mock(_data=dict())
    api_instance.name = 'freestyle'

    job = Job(api_instance)
    yield from job.fetch_builds()

    assert aget.mock_calls
def test_fetch_builds(mocker):
    Client = mocker.patch('jenkins_epo.jenkins.rest.Client')
    Client().api.python.aget = aget = CoroutineMock(
        return_value=dict(builds=[])
    )
    from jenkins_epo.jenkins import Job

    api_instance = Mock(_data=dict())
    api_instance.name = 'freestyle'

    job = Job(api_instance)
    yield from job.fetch_builds()

    assert aget.mock_calls
def test_process_builds():
    from jenkins_epo.jenkins import Job

    api_instance = Mock(_data=dict())
    api_instance.name = 'freestyle'

    job = Job(api_instance)

    builds = list(job.process_builds([
        {'number': 1, 'url': 'url://'},
        {'number': 2, 'url': 'url://'},
    ]))

    assert 2 == len(builds)
    assert 2 == builds[0].number
    assert 1 == builds[1].number
Ejemplo n.º 8
0
def test_matrix_list_context_node_axis_only():
    from jenkins_yml import Job
    from jenkins_epo.jenkins import MatrixJob

    api_instance = Mock(spec=['_get_config_element_tree', 'get_params'])
    api_instance.name = 'matrix'
    api_instance._data = dict(activeConfigurations=[
        {
            'name': 'NODE=slave,P=a'
        },
        {
            'name': 'NODE=slave,P=b'
        },
    ])

    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    job = MatrixJob(api_instance)
    job._node_axis = 'NODE'

    spec = Job('matrix', dict(
        axis={'P': ['a', 'b']},
        merged_nodes=['slave'],
    ))
    contexts = [c for c in job.list_contexts(spec)]

    assert 2 == len(contexts)
Ejemplo n.º 9
0
def test_job_updated_at(JobSpec):
    from jenkins_epo.jenkins import Job

    job = Job(
        Mock(_data=dict(description="""\
Bla bla.

<!--
epo:
  updated_at: 2016-10-10T15:27:00Z
-->
""")))
    assert job.updated_at
    assert 2016 == job.updated_at.year

    job = Job(Mock(_data=dict(description="""no yaml""")))
    assert not job.updated_at
Ejemplo n.º 10
0
def test_process_builds():
    from jenkins_epo.jenkins import Job

    api_instance = Mock(_data=dict())
    api_instance.name = 'freestyle'

    job = Job(api_instance)

    builds = list(
        job.process_builds([
            {
                'number': 1,
                'url': 'url://'
            },
            {
                'number': 2,
                'url': 'url://'
            },
        ]))

    assert 2 == len(builds)
    assert 2 == builds[0].number
    assert 1 == builds[1].number
Ejemplo n.º 11
0
def test_matrix_list_context_superset(JobSpec):
    from jenkins_yml import Job
    from jenkins_epo.jenkins import MatrixJob

    api_instance = Mock(spec=['_get_config_element_tree', 'get_params'])
    api_instance.name = 'matrix'
    api_instance._data = dict(activeConfigurations=[
        {
            'name': 'A=0,B=a'
        },
        {
            'name': 'A=1,B=a'
        },
        {
            'name': 'A=0,B=b'
        },
        {
            'name': 'A=1,B=b'
        },
        {
            'name': 'A=0,B=c'
        },
        {
            'name': 'A=1,B=c'
        },
    ])

    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    jenkins_spec = JobSpec.from_xml.return_value
    jenkins_spec.config = dict(axis={'A': [0, 1], 'B': 'abc'})

    job = MatrixJob(api_instance)
    spec = Job('matrix', dict(axis={'B': 'acd'}))

    contexts = [c for c in job.list_contexts(spec)]

    haystack = '\n'.join(contexts)
    assert 'A=0' in haystack
    assert 'A=1' not in haystack
    assert 'B=b' not in haystack
    assert 2 == len(contexts)
Ejemplo n.º 12
0
def test_enabled():
    from jenkins_epo.jenkins import Job

    assert not Job(Mock(_data=dict(color='disabled'))).enabled
    assert Job(Mock(_data=dict(color='blue'))).enabled