def load_test_xml(self): yaml_file = open(os.path.join(self.file_path, 'sectioned_view.yaml'), 'r') yaml = yaml_file.read() _, xml_view = convert_to_xml(yaml) return ET.fromstring(xml_view)
def take_action(self, parsed_args): out_dir = parsed_args.out_dir or tempfile.mkdtemp() if os.path.isdir(out_dir): shutil.rmtree(out_dir, ignore_errors=True) if not os.path.exists(out_dir): os.makedirs(out_dir) for yaml_location in parsed_args.yaml: if yaml_location and os.path.isdir(yaml_location): yaml_files = glob.glob(os.path.join(yaml_location, '*.yml')) else: yaml_files = [yaml_location] for yaml_filename in yaml_files: self.log.debug("Testing view file %s" % yaml_filename) with open(os.path.join(yaml_filename), 'r') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) try: xmls = convert_to_xml(yaml) except Exception as e: raise (e) if isinstance(xmls[0], str): name, xml = xmls with open(os.path.join(out_dir, name + ".xml"), 'wb') as xml_file: xml_file.write(xml) else: for name, xml in xmls: with open(os.path.join(out_dir, name + ".xml"), 'wb') as xml_file: xml_file.write(xml)
def test_should_raise_exception_for_invalid_view_type(self): yaml_file = open( os.path.join(self.file_path, 'invalid_view_type.yaml'), 'r') yaml = yaml_file.read() self.assertRaises(lambda: convert_to_xml(yaml))
def read_update(self, config, view_yaml): with open(view_yaml, 'r') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) name, xml = convert_to_xml(yaml) self.log.debug(xml) update(config, name, xml)
def take_action(self, parsed_args): import io import six out_dir = parsed_args.out_dir if os.path.isdir(out_dir): shutil.rmtree(out_dir, ignore_errors=True) os.makedirs(out_dir) for yaml_filename in parsed_args.yaml: self.log.debug("Testing view file %s" % yaml_filename) with io.open(os.path.join(yaml_filename), 'r', encoding='utf-8') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) try: xmls = convert_to_xml(yaml) except Exception as e: raise (e) if isinstance(xmls[0], six.string_types): name, xml = xmls with open(os.path.join(out_dir, name + ".xml"), 'wb') as xml_file: xml_file.write(xml) else: for name, xml in xmls: with open(os.path.join(out_dir, name + ".xml"), 'wb') as xml_file: xml_file.write(xml)
def test_should_include_description_in_xml(self): yaml_file = open(os.path.join(self.file_path, 'list_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) description = xml_root.find('description') self.assertEqual(description.text, 'Merge ply jobs')
def test_should_include_recurse_flag_in_xml(self): yaml_file = open(os.path.join(self.file_path, 'list_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) recurse = xml_root.find('recurse') self.assertEqual(recurse.text, 'false')
def test_should_have_a_name_tag_in_view_xml(self): yaml_file = open(os.path.join(self.file_path, 'list_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) name = xml_root.find('name') self.assertEqual(name.text, 'monsanto')
def test_should_trigger_only_latest(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) trigger_latest = xml_root.find('triggerOnlyLatestJob') self.assertEqual(trigger_latest.text, 'true')
def test_should_set_refresh_frequency(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) refresh_frequency = xml_root.find('refreshFrequency') self.assertEqual(refresh_frequency.text, '5')
def test_should_include_number_of_displayed_builds(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) displayed_builds = xml_root.find('noOfDisplayedBuilds') self.assertEqual(displayed_builds.text, '20')
def test_should_have_first_job_of_the_pipeline(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) first_job = xml_root.find('gridBuilder/firstJob') self.assertEqual(first_job.text, 'joby job')
def test_should_have_title_in_view_xml(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) name = xml_root.find('buildViewTitle') self.assertEqual(name.text, 'build pipeline')
def test_should_set_allow_manual_trigger(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) always_allow_manual_trigger = xml_root.find('alwaysAllowManualTrigger') self.assertEqual(always_allow_manual_trigger.text, 'true')
def test_should_have_jobs_in_view_xml(self): yaml_file = open(os.path.join(self.file_path, "list_view.yaml"), "r") yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) jobs = xml_root.findall("jobNames/string") jobs = [job.text for job in jobs] self.assertListEqual(jobs, ["Merge-bark-Ply", "Merge-Config-Ply", "Merge-nova-Ply"])
def test_should_have_columns_in_view_xml(self): yaml_file = open(os.path.join(self.file_path, "list_view.yaml"), "r") yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) columns = xml_root.findall("columns/") column_tags = [column.tag for column in columns] self.assertListEqual(column_tags, ["hudson.views.StatusColumn", "hudson.views.WeatherColumn"])
def test_should_have_jobs_in_view_xml(self): yaml_file = open(os.path.join(self.file_path, 'list_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) jobs = xml_root.findall('jobNames/string') jobs = [job.text for job in jobs] self.assertListEqual( jobs, ['Merge-bark-Ply', 'Merge-Config-Ply', 'Merge-nova-Ply'])
def test_should_have_columns_in_view_xml(self): yaml_file = open(os.path.join(self.file_path, 'list_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) columns = xml_root.findall('columns/') column_tags = [column.tag for column in columns] self.assertListEqual( column_tags, ['hudson.views.StatusColumn', 'hudson.views.WeatherColumn'])
def take_action(self, parsed_args): with open(os.path.join(parsed_args.yaml), 'r') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) try: name, xml = convert_to_xml(yaml) except Exception as e: raise (e) if os.path.isdir("out"): shutil.rmtree("out", ignore_errors=True) os.makedirs("out") with open(os.path.join("out", name + ".xml"), 'w') as xml_file: xml_file.write(xml)
def test_should_have_multi_name_tags_in_view_xml(self): yaml_file = open(os.path.join(self.file_path, 'multi_list_view.yaml'), 'r') yaml = yaml_file.read() names = [] for name, xml_view in convert_to_xml(yaml): xml_root = ET.fromstring(xml_view) name = xml_root.find('name') print name.text names.append(name.text) self.assertListEqual(names, ['monsanto', 'second'])
def read_update(self, config, view_yaml): with open(view_yaml, 'r') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) try: xmls = convert_to_xml(yaml) except Exception as e: raise (e) if isinstance(xmls[0], str): name, xml = xmls self.log.debug(xml) update(config, name, xml) else: for name, xml in xmls: self.log.debug(xml) update(config, name, xml)
def read_update(self, config, view_yaml): with open(view_yaml, 'r') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) try: xmls = convert_to_xml(yaml) except Exception as e: raise(e) if isinstance(xmls[0], str): name, xml = xmls self.log.debug(xml) update(config, name, xml) else: for name, xml in xmls: self.log.debug(xml) update(config, name, xml)
def test_should_set_includeRegex_using_includeRegex_flag(self, yaml_filename=None): if yaml_filename is None: yaml_file = open(os.path.join(self.file_path, "list_view_includeRegex.yaml"), "r") else: print(yaml_filename) yaml_file = open(os.path.join(self.file_path, yaml_filename), "r") yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) includeRegex = xml_root.find("includeRegex") self.assertEqual(includeRegex.text, "Merge-*-Ply") job_name = xml_root.find("jobNames") job1 = job_name.findall("string")[0] self.assertEqual(job1.text, "create-package-latest")
def test_should_set_pipeline_parameters(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) show_pipeline_params = xml_root.find('showPipelineParameters') show_pipeline_params_headers = xml_root.find('showPipelineParametersInHeaders') starts_with_params = xml_root.find('startsWithParameters') show_pipeline_defn_header = xml_root.find('showPipelineDefinitionHeader') self.assertEqual(show_pipeline_params.text, 'false') self.assertEqual(show_pipeline_params_headers.text, 'false') self.assertEqual(starts_with_params.text, 'false') self.assertEqual(show_pipeline_defn_header.text, 'false')
def take_action(self, parsed_args): out_dir = parsed_args.out_dir if os.path.isdir(out_dir): shutil.rmtree(out_dir, ignore_errors=True) os.makedirs(out_dir) for yaml_filename in parsed_args.yaml: self.log.debug("Testing view file %s" % yaml_filename) with open(os.path.join(yaml_filename), 'r') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) try: name, xml = convert_to_xml(yaml) except Exception as e: raise(e) with open(os.path.join(out_dir, name + ".xml"), 'w') as xml_file: xml_file.write(xml)
def take_action(self, parsed_args): out_dir = parsed_args.out_dir if os.path.isdir(out_dir): shutil.rmtree(out_dir, ignore_errors=True) os.makedirs(out_dir) for yaml_filename in parsed_args.yaml: self.log.debug("Testing view file %s" % yaml_filename) with open(os.path.join(yaml_filename), 'r') as yaml_file: yaml = yaml_file.read() self.log.debug(yaml) try: name, xml = convert_to_xml(yaml) except Exception as e: raise (e) with open(os.path.join(out_dir, name + ".xml"), 'w') as xml_file: xml_file.write(xml)
def test_should_set_includeRegex(self, yaml_filename=None): if yaml_filename is None: yaml_file = open( os.path.join(self.file_path, 'list_view_regex.yaml'), 'r') else: print(yaml_filename) yaml_file = open(os.path.join(self.file_path, yaml_filename), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) includeRegex = xml_root.find('includeRegex') self.assertEqual(includeRegex.text, 'Merge-*-Ply') job_name = xml_root.find("jobNames") job1 = job_name.findall("string")[0] self.assertEqual(job1.text, "create-package-latest")
def read_update(self, config, view_yaml): import io import six with io.open(view_yaml, 'r', encoding='utf-8') as yaml_file: _yaml = yaml_file.read() self.log.debug(_yaml) try: xmls = convert_to_xml(_yaml) except Exception as e: raise (e) if isinstance(xmls[0], six.string_types): name, xml = xmls self.log.debug(xml) update(config, name, xml) else: for name, xml in xmls: self.log.debug(xml) update(config, name, xml)
def test_should_set_pipeline_parameters(self): yaml_file = open(os.path.join(self.file_path, 'pipeline_view.yaml'), 'r') yaml = yaml_file.read() name, xml_view = convert_to_xml(yaml) xml_root = ET.fromstring(xml_view) show_pipeline_params = xml_root.find('showPipelineParameters') show_pipeline_params_headers = xml_root.find( 'showPipelineParametersInHeaders') starts_with_params = xml_root.find('startsWithParameters') show_pipeline_defn_header = xml_root.find( 'showPipelineDefinitionHeader') self.assertEqual(show_pipeline_params.text, 'false') self.assertEqual(show_pipeline_params_headers.text, 'false') self.assertEqual(starts_with_params.text, 'false') self.assertEqual(show_pipeline_defn_header.text, 'false')
def test_should_raise_exception_for_invalid_view_type(self): yaml_file = open(os.path.join(self.file_path, 'invalid_view_type.yaml'), 'r') yaml = yaml_file.read() self.assertRaises(lambda: convert_to_xml(yaml))