def test_matrix_build(mocker, SETTINGS): JENKINS = mocker.patch('jenkins_epo.jenkins.JENKINS') from jenkins_epo.jenkins import MatrixJob, JobSpec SETTINGS.DRY_RUN = 0 api_instance = Mock() api_instance.name = 'matrix' api_instance._data = {'url': 'https://jenkins/job'} xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None spec = JobSpec(api_instance.name) spec.config['parameters'] = {'PARAM': 1} job = MatrixJob(api_instance) job._node_axis = job._revision_param = None job._combination_param = 'C' job._revision_param = 'R' yield from job.build( Mock(url='url://', fullref='refs/heads/master'), spec, 'matrix', ) assert JENKINS.rest.job().buildWithParameters.mock_calls
def test_matrix_list_context_node(): 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-legacy,P=a'}, {'name': 'NODE=slave-ng,P=a'}, {'name': 'NODE=slave-legacy,P=b'}, {'name': 'NODE=slave-ng,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( node='slave-ng', axis={'P': ['a', 'b', 4.3]}, )) contexts = [c for c in job.list_contexts(spec)] assert 2 == len(contexts) assert 'NODE=slave-legacy' not in ''.join(contexts) assert 'NODE=slave-ng' in ''.join(contexts)
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)
def test_matrix_build(mocker, SETTINGS): JENKINS = mocker.patch('jenkins_epo.jenkins.JENKINS') from jenkins_epo.jenkins import MatrixJob, JobSpec SETTINGS.DRY_RUN = 0 api_instance = Mock() api_instance.name = 'matrix' api_instance._data = {'url': 'https://jenkins/job'} xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None spec = JobSpec(api_instance.name) spec.config['parameters'] = {'PARAM': 1} job = MatrixJob(api_instance) job._node_axis = job._revision_param = None job._combination_param = 'C' job._revision_param = 'R' yield from job.build( Mock(url='url://', fullref='refs/heads/master'), spec, 'matrix', ) assert JENKINS.rest.job().buildWithParameters.mock_calls
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)
def test_freestyle_node_param(): from jenkins_epo.jenkins import FreestyleJob api_instance = Mock(spec=['_get_config_element_tree', 'get_params']) api_instance._data = dict() api_instance.name = 'freestyle' api_instance.get_params.return_value = [ {'name': 'P', 'type': 'StringParameter'}, {'name': 'N', 'type': 'LabelParameterDefinition'}, ] xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None job = FreestyleJob(api_instance) assert 'N' == job.node_param
def test_matrix_combination_param(): from jenkins_epo.jenkins import MatrixJob api_instance = Mock(spec=['_get_config_element_tree', 'get_params']) api_instance.name = 'matrix' api_instance._data = dict() api_instance.get_params.return_value = [ {'name': 'P', 'type': 'StringParameter'}, {'name': 'C', 'type': 'MatrixCombinationsParameterDefinition'}, ] xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None job = MatrixJob(api_instance) assert 'C' == job.combination_param
def test_matrix_node_axis(): from jenkins_epo.jenkins import MatrixJob api_instance = Mock(spec=['_get_config_element_tree', 'get_params']) api_instance.name = 'matrix' api_instance._data = dict() xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None job = MatrixJob(api_instance) name_element = Mock() name_element.text = 'NODE' xml.findall.return_value = [name_element] assert 'NODE' == job.node_axis
def test_matrix_node_axis(): from jenkins_epo.jenkins import MatrixJob api_instance = Mock(spec=['_get_config_element_tree', 'get_params']) api_instance.name = 'matrix' api_instance._data = dict() xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None job = MatrixJob(api_instance) name_element = Mock() name_element.text = 'NODE' xml.findall.return_value = [name_element] assert 'NODE' == job.node_axis
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)
def test_freestyle_node_param(): from jenkins_epo.jenkins import FreestyleJob api_instance = Mock(spec=['_get_config_element_tree', 'get_params']) api_instance._data = dict() api_instance.name = 'freestyle' api_instance.get_params.return_value = [ { 'name': 'P', 'type': 'StringParameter' }, { 'name': 'N', 'type': 'LabelParameterDefinition' }, ] xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None job = FreestyleJob(api_instance) assert 'N' == job.node_param
def test_matrix_combination_param(): from jenkins_epo.jenkins import MatrixJob api_instance = Mock(spec=['_get_config_element_tree', 'get_params']) api_instance.name = 'matrix' api_instance._data = dict() api_instance.get_params.return_value = [ { 'name': 'P', 'type': 'StringParameter' }, { 'name': 'C', 'type': 'MatrixCombinationsParameterDefinition' }, ] xml = api_instance._get_config_element_tree.return_value xml.findall.return_value = [] xml.find.return_value = None job = MatrixJob(api_instance) assert 'C' == job.combination_param