def link_requirements(self, tc_obj): """ :param tc_obj: :return: """ linked_items = tc_obj.linked_work_items if not self.requirement: log.warning("No requirement exists for this test case") else: duplicates = filter(lambda x: x == self.requirement, [li.work_item_id for li in linked_items]) num_duplicates = len(duplicates) if num_duplicates == 0: log.info("Linking requirement {} to TestCase {}".format( self.requirement, tc_obj.work_item_id)) tc_obj.add_linked_item(self.requirement, "verifies") elif num_duplicates > 1: msg = "Found duplicate linked Requirements {} for TestCase {}. Cleaning...." log.warning( msg.format(itz.first(duplicates), tc_obj.work_item_id)) for _ in range(len(duplicates) - 1): tc_obj.remove_linked_item(self.requirement, "verifies") else: msg = "Requirement {} already linked to TestCase {}" log.info(msg.format(itz.first(duplicates), tc_obj.work_item_id))
def create_requirement(project_id, title, description="", reqtype="functional", severity="should_have"): if True: log.warning("No longer creating a requirement automatically") return None else: from pylarion.work_item import Requirement req = is_requirement_exists(title) if req: log.info("Found existing Requirement {}".format(req.title)) return req else: log.info("Creating a new Requirement: {}".format(title)) return Requirement.create(project_id, title, description, severity=severity, reqtype=reqtype)
def field_factory(self, *args, **kwargs): """ This function does two things: it forwards args to parser.add_arguments, and other args to field() There is one keyword collision for add_argument and field, which is 'type'. If 'type' exists, we will use it for field :param long_name: The "--long-arg" name :param short_name: :param cli_help: :param parser: :param kwargs: :return: """ short_name = None if len(args) == 2: long_name = args[1] short_name = args[0] elif len(args) == 1: long_name = args[0] if short_name is not None and short_name in self.short_names: log.warning("{0} already used. Not setting {0} for {1}".format(short_name, long_name)) else: self.short_names.add(short_name) if "short_name" in kwargs: kwargs.pop("short_name") parser_kwargs = {} for x in ["required", "nargs", "choices", "default", "help", "dest"]: if x in kwargs: parser_kwargs[x] = kwargs.pop(x) field_kwargs = kwargs if short_name is not None: self.parser.add_argument(short_name, long_name, **parser_kwargs) else: self.parser.add_argument(long_name, **parser_kwargs) # print "Option {}:".format(long_name), field_kwargs return field(**field_kwargs)
def link_requirements(self, tc_obj): """ :param tc_obj: :return: """ linked_items = tc_obj.linked_work_items if not self.requirement: log.warning("No requirement exists for this test case") else: duplicates = filter(lambda x: x == self.requirement, [li.work_item_id for li in linked_items]) num_duplicates = len(duplicates) if num_duplicates == 0: log.info("Linking requirement {} to TestCase {}".format(self.requirement, tc_obj.work_item_id)) tc_obj.add_linked_item(self.requirement, "verifies") elif num_duplicates > 1: msg = "Found duplicate linked Requirements {} for TestCase {}. Cleaning...." log.warning(msg.format(itz.first(duplicates), tc_obj.work_item_id)) for _ in range(len(duplicates) - 1): tc_obj.remove_linked_item(self.requirement, "verifies") else: msg = "Requirement {} already linked to TestCase {}" log.info(msg.format(itz.first(duplicates), tc_obj.work_item_id))
# Extra Credit: do this functionally. Though maybe we should keep the duplicates? if 0: refl = {} for clazz, items in reflected.items(): nameset = [] maps = [] qualset = set() for m in items: methname = m['methodName'] qual = "{}.{}".format(clazz, methname) if qual not in qualset: nameset.append(methname) qualset.add(qual) maps.append(m) else: log.warning("Found duplicate {} in {}.".format(qual, nameset)) refl[clazz] = maps reflected = refl mapped = [] for class_meth, tc in matched: mapping = {} class_prefix = "rhsm.{}.tests.".format(class_meth[0]) klass, meth = class_meth[1].split(".") klass = class_prefix + klass try: class_group = reflected[klass] except KeyError as ke: log.warning(ke.message) continue
def create_test_run(self, template_id, test_run_base=None, runner=None): """ Creates a new Polarion TestRun :param template_id: id of the template to use for TestRun :param test_run_base: a str to look up most recent TestRuns (eg "Jenkins Run" if the full name of TestRuns is "Jenkins Run 200" :param runner: str of the user id (eg stoner, not "Sean Toner") :return: None """ from pylarion.test_run import TestRun runner = self.get_runner(runner) tr_temp = self.get_template(template_id) log.info(tr_temp.plannedin) for s, testngs in self.tests.items(): if not testngs: continue if test_run_base is None: base_name = self.transformer.generate_base_testrun_id(s) else: base_name = test_run_base # Find our latest run. If it doesn't exist, we'll generate one tr = get_latest_test_run(base_name) if tr: new_id = make_test_run_id_from_latest(tr) else: base_name = remove_run(base_name) new_id = base_name + " Run 1" log.info("Creating new Test Run ID: {}".format(new_id)) plannedin = self.transformer.config.testrun_plannedin assignee = self.transformer.config.testrun_assignee retries = 3 while retries > 0: retries -= 1 if not plannedin: if hasattr(tr_temp, "plannedin") and tr_temp.plannedin: plannedin = tr_temp.plannedin else: raise PlannedinException("No plannedin value in template or from config") if not assignee: if hasattr(tr_temp, "assignee") and tr_temp.assignee: assignee = tr_temp.assignee else: raise AssigneeException("No assignee value in template or from config") try: test_run = TestRun.create(self.project, new_id, template_id, plannedin=plannedin, assignee=assignee) break except PlannedinException as pex: log.error(pex.message) raise pex except AssigneeException as aex: log.error(aex.message) raise aex except Exception as ex: log.warning("Retrying {} more times".format(retries)) else: raise Exception("Could not create a new TestRun") test_run.status = "inprogress" test_run.variant = [self.transformer.config.distro.variant.lower()] test_run.jenkinsjobs = self.transformer.config.testrun_jenkinsjobs test_run.notes = self.transformer.config.testrun_notes test_run.arch = [self.transformer.config.distro.arch.replace("_", "")] test_run.group_id = self.transformer.config.testrun_group_id for tc in testngs: tc.create_test_record(test_run, run_by=runner) test_run.status = "finished" test_run.update() log.info("Created test run for {}".format(new_id))