def test_basic(self): filename = os.path.join(fixtures_path, 'child-custom-workspace.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] childcustomworkspace(root, parent) assert len(parent) == 1 assert parent[0][0] == "child-workspace" assert parent[0][1] == "lorem"
def test_basic(self): filename = os.path.join(fixtures_path, 'combination-filter.xml') root = get_xml_root(filename=filename) jobname = "test" yml = root_to_yaml(root, jobname) dct = yaml.safe_load(yml) assert len(dct) == 1 assert dct[0]['job']['execution-strategy'][ 'combination-filter'] == "(lorem == ipsum)"
def compare_jjb_output(self, name, job_name): test_filename = os.path.join(fixtures_path, name + '.xml') expected_yml_filename = os.path.join(fixtures_path, name + '.yml') root = get_xml_root(filename=test_filename) actual_yml = root_to_yaml(root, job_name) with open(expected_yml_filename) as f: expected_yml = f.read() assert actual_yml is not None assert actual_yml == expected_yml
def run_jjw(self, name): xml_filename = os.path.join(fixtures_path, name + '.xml') root = get_xml_root(filename=xml_filename) yaml = root_to_yaml(root, name) actual_yaml_filename = os.path.join(fixtures_path, name + '.yaml.actual') with open(actual_yaml_filename, "w") as f: f.write(yaml) expected_yaml_filename = os.path.join(fixtures_path, name + '.yaml') with open(expected_yaml_filename) as f: expected_yaml = f.read() assert expected_yaml == yaml
def test_gerrit_trigger_comparison(self): test_filename = os.path.join(fixtures_path, 'gerrit_trigger.xml') expected_yml_filename = os.path.join(fixtures_path, 'gerrit_trigger.yml') root = get_xml_root(filename=test_filename) actual_yml = root_to_yaml(root, "gerrit-trigger") with open(expected_yml_filename) as f: expected_yml = f.read() assert actual_yml is not None assert actual_yml == expected_yml
def run_jjb(self, name): filename = os.path.join(fixtures_path, name + '.xml') root = get_xml_root(filename=filename) yaml = root_to_yaml(root, name) # Run this wrecker YAML thru JJB. # XXX: shelling out with call() sucks; use JJB's API instead temp = tempfile.NamedTemporaryFile() temp.write(yaml) temp.flush() assert call(["jenkins-jobs", 'test', temp.name]) == 0 temp.close()
def test_basic(self): filename = os.path.join(fixtures_path, 'rebuild-settings.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] rebuildsettings(root, parent) assert len(parent) == 1 assert "rebuild" in parent[0] rebuild = parent[0]["rebuild"] assert len(rebuild) == 2 assert rebuild["auto-rebuild"] is False assert rebuild["rebuild-disabled"] is False
def test_basic(self): filename = os.path.join(fixtures_path, 'authorization-matrix-property.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] authorizationmatrixproperty(root, parent) assert len(parent) == 1 assert 'authorization' in parent[0] jjb_authorization = parent[0]['authorization'] assert len(jjb_authorization) == 2 assert jjb_authorization['usera'] == ['job-build', 'job-read'] assert jjb_authorization['userb'] == ['job-configure', 'job-workspace']
def test_v2(self): filename = os.path.join(fixtures_path, 'groovy-postbuild-v2.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] groovypostbuildrecorder(root, parent) assert len(parent) == 1 assert 'groovy-postbuild' in parent[0] jjb_groovy_postbuild = parent[0]['groovy-postbuild'] assert jjb_groovy_postbuild['matrix-parent'] is False assert jjb_groovy_postbuild['on-failure'] == 'nothing' assert jjb_groovy_postbuild['sandbox'] is False assert jjb_groovy_postbuild['script'] == 'foo bar'
def run_jjb(self, name, jobname=None): filename = os.path.join(fixtures_path, name + '.xml') root = get_xml_root(filename=filename) if jobname is None: jobname = name yaml = root_to_yaml(root, jobname) # Run this wrecker YAML thru JJB. temp = tempfile.NamedTemporaryFile() temp.write(yaml) temp.flush() assert jenkins_jobs.cmd.main(['test', temp.name]) is None temp.close()
def run_jjb(self, name, jobname=None): filename = os.path.join(fixtures_path, name + '.xml') root = get_xml_root(filename=filename) if jobname is None: jobname = name yaml = root_to_yaml(root, jobname) # Run this wrecker YAML thru JJB. with tempfile.NamedTemporaryFile('w') as temp: temp.write(yaml) temp.flush() jjb = JenkinsJobs(['test', temp.name]) assert jjb.execute() is None
def test_aws(self): filename = os.path.join(fixtures_path, "awsbindings.xml") root = get_xml_root(filename=filename) assert root is not None parent = [] secretbuildwrapper(root, parent) assert len(parent) == 1 assert "credentials-binding" in parent[0] jjb_aws_binding = parent[0]["credentials-binding"][0][ "amazon-web-services"] assert jjb_aws_binding["credential-id"] == "001" assert jjb_aws_binding["access-key"] == "AWS_ACCESS_KEY" assert jjb_aws_binding["secret-key"] == "AWS_SECRET_KEY"
def test_basic(self): filename = os.path.join(fixtures_path, "prebuildcleanup.xml") root = get_xml_root(filename=filename) assert root is not None parent = [] prebuildcleanup(root, parent) assert len(parent) == 1 assert "workspace-cleanup" in parent[0] jjb_ws_cleanup = parent[0]["workspace-cleanup"] assert jjb_ws_cleanup["dirmatch"] is True assert jjb_ws_cleanup["disable-deferred-wipeout"] is True assert jjb_ws_cleanup["check-parameter"] == "DO_WS_CLEANUP" assert jjb_ws_cleanup["external-deletion-command"] == "shred -u %s"
def test_basic(self): filename = os.path.join(fixtures_path, 'prebuildcleanup.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] prebuildcleanup(root, parent) assert len(parent) == 1 assert 'workspace-cleanup' in parent[0] jjb_ws_cleanup = parent[0]['workspace-cleanup'] assert jjb_ws_cleanup['dirmatch'] is True assert jjb_ws_cleanup['disable-deferred-wipeout'] is True assert jjb_ws_cleanup['check-parameter'] == 'DO_WS_CLEANUP' assert jjb_ws_cleanup['external-deletion-command'] == 'shred -u %s'
def test_without_blocker_jobs(self): filename = os.path.join(fixtures_path, 'build-blocker-property-without-blocking-jobs.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] buildblockerproperty(root, parent) assert len(parent) == 1 build_blocker = parent[0]["build-blocker"] assert not build_blocker["use-build-blocker"] assert build_blocker["block-level"] == "GLOBAL" assert build_blocker["queue-scanning"] == "DISABLED" blocking_jobs = build_blocker["blocking-jobs"] assert len(blocking_jobs) == 0
def test_empty_value(self): filename = os.path.join(fixtures_path, 'prebuildcleanup_empty_value.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] prebuildcleanup(root, parent) assert len(parent) == 1 assert 'workspace-cleanup' in parent[0] jjb_ws_cleanup = parent[0]['workspace-cleanup'] assert jjb_ws_cleanup['dirmatch'] is True assert jjb_ws_cleanup['disable-deferred-wipeout'] is True assert 'external-deletion-command' not in jjb_ws_cleanup assert 'check-parameter' not in jjb_ws_cleanup
def test_empty_value(self): filename = os.path.join(fixtures_path, "prebuildcleanup_empty_value.xml") root = get_xml_root(filename=filename) assert root is not None parent = [] prebuildcleanup(root, parent) assert len(parent) == 1 assert "workspace-cleanup" in parent[0] jjb_ws_cleanup = parent[0]["workspace-cleanup"] assert jjb_ws_cleanup["dirmatch"] is True assert jjb_ws_cleanup["disable-deferred-wipeout"] is True assert "external-deletion-command" not in jjb_ws_cleanup assert "check-parameter" not in jjb_ws_cleanup
def test_basic(self): filename = os.path.join(fixtures_path, 'build-name-setter.xml') root = get_xml_root(filename=filename) assert root is not None parent = [] buildnameupdater(root, parent) assert len(parent) == 1 assert 'build-name-setter' in parent[0] build_name_setter = parent[0]["build-name-setter"] assert len(build_name_setter) == 5 assert build_name_setter["file"] == False assert build_name_setter["macro"] == True assert build_name_setter["macro-first"] == False assert build_name_setter["name"] == "version.txt" template_expected = '#${BUILD_NUMBER}-${FILE,path="BUILD_NAMER"}' assert build_name_setter["template"] == template_expected
def test_missing_arg(self): with pytest.raises(TypeError): get_xml_root()
def test_xml_root_with_string(self): root = get_xml_root(string='<testing></testing>') assert isinstance(root, xml.etree.ElementTree.Element)
def test_xml_root_with_file(self): root = get_xml_root(filename=ice_setup_xml_file) assert isinstance(root, xml.etree.ElementTree.Element)