def test_002_5_create_run_with_title(self): """This test does the following: * creates a test run based on the template created in previous test * with both a title and an id * with just a title. * Verifies that the returned object exists and is not a template """ tr1 = TestRun.create(DEFAULT_PROJ, TEST_RUN_ID2, TEMPLATE_ID, TITLE1) self.assertIsNotNone(tr1.test_run_id) self.assertEqual(tr1.title, TITLE1) self.assertFalse(tr1.is_template) tr2 = TestRun.create(DEFAULT_PROJ, None, TEMPLATE_ID, TITLE2) self.assertIsNotNone(tr2.test_run_id) self.assertEqual(tr2.title, TITLE2) self.assertFalse(tr2.is_template)
def test_run(path, test_run_id, test_template_id, user, project): """Execute a test run based on jUnit XML file.""" results = parse_junit(path) try: test_run = TestRun(test_run_id, project_id=project) click.echo('Test run {0} found.'.format(test_run_id)) except PylarionLibException as err: click.echo(err, err=True) click.echo('Creating test run {0}.'.format(test_run_id)) test_run = TestRun.create(project, test_run_id, test_template_id) for result in results: test_case_id = '{0}.{1}'.format(result['classname'], result['name']) test_case = TestCase.query(test_case_id) if len(test_case) == 0: click.echo( 'Was not able to find test case with id {0}, skipping...'. format(test_case_id)) continue status = POLARION_STATUS[result['status']] work_item_id = test_case[0].work_item_id click.echo( 'Adding test record for test case {0} with status {1}.'.format( work_item_id, status)) try: test_run.add_test_record_by_fields( test_case_id=work_item_id, test_result=status, test_comment=result.get('message'), executed_by=user, executed=datetime.datetime.now(), duration=float(result.get('time', '0'))) except PylarionLibException as err: click.echo('Skipping test case {0}.'.format(work_item_id)) click.echo(err, err=True)
def setUpClass(cls): global TEST_RUN_ID cls.doc = Document.create(DEFAULT_PROJ, "Testing", DOC_NAME, "Attribute_Test", ["testcase"], "testspecification") cls.testrun = TestRun.create(DEFAULT_PROJ, TEST_RUN_ID, "example", TEST_RUN_TITLE) TEST_RUN_ID = cls.testrun.test_run_id # arch is a custom field defined by global admins for test runs. # It is set here for a test on custom fields that requires at least two # valid values. If in the future, this custom field is removed, or the # number of valid values is lowered to 1, a different custom field will # have to be used. valid_values = cls.testrun.get_valid_field_values("arch") cls.testrun.arch = valid_values[1] cls.testrun.update() cls.tc = TestCase.create(DEFAULT_PROJ, "regression", "regression", caseimportance="high", caselevel="component", caseautomation="notautomated", caseposneg="positive", testtype="functional", subtype1="-") cls.TEST_CASE_ID = cls.tc.work_item_id
def test_009_dynamic_records(self): """This test does the following: * creates a TestCase * creates a TestRun based on the Example template (Dynamic query) * verifies that it is a dynamic query * updates an test record. * reloads * verifies that the record has been added """ TestCase.create(DEFAULT_PROJ, TIME_STAMP, "regression", caseimportance="high", caselevel="component", caseautomation="notautomated", caseposneg="positive", testtype="functional", subtype1="-") tr = TestRun.create("proj1", "querytest-%s" % TIME_STAMP, "Example", "querytest-%s" % TIME_STAMP, query=TIME_STAMP) self.assertEquals(tr.select_test_cases_by, "dynamicQueryResult") num_recs = len(tr.records) test_case_id = tr.records[0].test_case_id tr.update_test_record_by_fields(test_case_id, "blocked", "comment", tr.logged_in_user_id, datetime.datetime.now(), 0) tr.reload() self.assertEquals(num_recs, len(tr.records)) self.assertEquals(test_case_id, tr.records[0].test_case_id) self.assertEquals(tr.records[0].result, "blocked")
def update_test_run(all_cases): project_name_name = 'RedHatEnterpriseLinux7' # template_name = 'virtkvmqe-x86-acceptance-rhev-auto' template_name = 'Empty' ISOTIMEFORMAT = '%Y-%m-%d %H-%M-%S' testrun_name = 'virtkvmqe-x86-acceptance ' + time.strftime( ISOTIMEFORMAT, time.gmtime( time.time() ) ) # create a test run tr = TestRun.create("RedHatEnterpriseLinux7",testrun_name,template_name) session = TestCase.session session.tx_begin() client = session.test_management_client for case in all_cases: # for each autocase, create a test record testcase_record = client.factory.create('tns3:TestRecord') testcase_record.testCaseURI = ("subterra:data-service:objects:/default/""RedHatEnterpriseLinux7${WorkItem}%s"%case['polarioncase_id']) testcase_record.duration = case['time'] testcase_record.executed = datetime.datetime.now() testcase_result = client.factory.create('tns4:EnumOptionId') testcase_result.id = case['result'] testcase_record.result = testcase_result # create a comment for each autocase comment_obj = client.factory.create('tns2:Text') comment_obj.type = "text/html" # add the fullname of a autocase content = case['full_name'] + '\n' content = content + case['error_info'] comment_obj.content = '<pre>%s</pre>' % content comment_obj.contentLossy = False testcase_record.comment = comment_obj client.service.addTestRecordToTestRun(tr.uri, testcase_record) # update the test run session.tx_commit()
def pytest_cmdline_main(config): if config.getoption('polarion_template') is not None and \ not config.getoption('collectonly'): fields = { field.split('=')[0]: field.split('=')[1] for field in config.getoption('field') } # generate TestRun name out of given Fields # otherwise, adding random 4 chars string as suffix tr_name = config.getoption('polarion_template') for f in fields.items(): tr_name += '-{0}_{1}'.format(*f) if tr_name == config.getoption('polarion_template'): tr_name += '-random_{}'.format(id_generator()) tr_name = tr_name.replace('.', '_') tr = TestRun.create(project_id=config.getoption('polarion_project'), test_run_id=tr_name, template=config.getoption('polarion_template')) for k, v in fields.iteritems(): try: setattr(tr, k, v) except AttributeError: print('Failed to set attribute {}={}'.format(k, v)) # tr.build = fields.get('build', '') tr.update() config.option.polarion_run = tr_name
def update_run(self, run, template=None, plannedin=None, assignee=None, status=None, description=None, is_template=False): run = run.strip() query_ful = 'project.id:%s AND id:%s' % (TestRun.default_project, run) fields = [ 'query', 'created', 'test_run_id', 'select_test_cases_by', 'status', 'plannedin', 'assignee', 'author' ] st = TestRun.search(query_ful, fields, 'created', -1, is_template) # Update run if exists, otherwise create it. if st: print('Update the existing run: %s' % run) tr = TestRun(run, None, TestRun.default_project) # set fields if assignee != 'None': tr.assignee = assignee print('%4sSet Assignee to %s' % ('', assignee)) if plannedin is not None: tr.plannedin = plannedin print('%4sSet Plannedin to %s' % ('', plannedin)) if status is not None: tr.status = status print('%4sSet Status to %s' % ('', status)) if description is not None: tr.description = description print('%4sSet Description to %s' % ('', description)) tr.update() else: tr = TestRun.create(TestRun.default_project, run, template, assignee=assignee, plannedin=plannedin, status=status, description=description) # display fields if assignee != 'None': print('%4sSet Assignee to %s' % ('', assignee)) if plannedin is not None: print('%4sSet Plannedin to %s' % ('', plannedin)) if status is not None: print('%4sSet Status to %s' % ('', status)) if description is not None: print('%4sSet Description to %s' % ('', description)) print('Created %s:' % run)
def test_002_create_run(self): """This test does the following: * creates a test run based on the template created in previous test * Verifies that the returned object exists and is not a template """ global TEST_RUN_ID tr = TestRun.create(DEFAULT_PROJ, TEST_RUN_ID, TEMPLATE_ID, TEST_RUN_TITLE) TEST_RUN_ID = tr.test_run_id self.assertIsNotNone(tr.test_run_id) self.assertFalse(tr.is_template)
def update_run(self, run, template=None, plannedin=None, assignee=None, is_template=False): qrun = run.replace('-', '\-') query_ful = 'project.id:%s AND id:%s' % (TestRun.default_project, qrun.strip()) fields = ['query', 'created', 'test_run_id', 'select_test_cases_by', 'status', 'plannedin', 'assignee', 'author'] st = TestRun.search(query_ful, fields, 'created', -1, is_template) # Update run if exists, otherwise create it. if st: print 'Update the existing run: %s' % run tr = TestRun(run.strip(), None, TestRun.default_project) else: tr = TestRun.create(TestRun.default_project, run.strip(), template) print '\nCreated %s:' % run # set customer filed of plannedin if plannedin: tr.plannedin = plannedin print '%4sSet Plannedin to %s' % ('', plannedin) if assignee == 'None': tr.assignee = TestRun.logged_in_user_id else: tr.assignee = assignee print '%4sSet Assignee to %s' % ('', tr.assignee) tr.update()
def test_run( context, path, source_code_path, test_run_id, test_run_type, test_template_id, user, custom_fields, project): """Execute a test run based on jUnit XML file.""" custom_fields = load_custom_fields(custom_fields) test_run_id = re.sub(INVALID_CHARS_REGEX, '', test_run_id) testcases = { generate_test_id(test): test.tokens.get('id') for test in itertools.chain( *testimony.get_testcases([source_code_path]).values() ) } results = parse_junit(path) try: test_run = TestRun(test_run_id, project_id=project) click.echo('Test run {0} found.'.format(test_run_id)) except PylarionLibException as err: click.echo(err, err=True) click.echo('Creating test run {0}.'.format(test_run_id)) test_run = TestRun.create( project, test_run_id, test_template_id, type=test_run_type, **custom_fields) update = False if test_run.type != test_run_type: test_run.type = test_run_type update = True for field, value in custom_fields.items(): if getattr(test_run, field) != value: setattr(test_run, field, value) click.echo( 'Test Run {0} updated with {1}={2}.'.format( test_run_id, field, value) ) update = True if update: test_run.update() OBJ_CACHE['test_run'] = test_run OBJ_CACHE['user'] = user OBJ_CACHE['testcases'] = testcases TestRun.session.tx_begin() pool = multiprocessing.Pool(context.obj['jobs']) pool.map(add_test_record, results) pool.close() pool.join() TestRun.session.tx_commit()
def test_008_doc_test_run_template(self): global TEMPLATE_ID global TEST_RUN_ID doc_with_space = self.doc_create.space self.doc_create.session.tx_begin() tmp = TestRun.create_template(project_id=Document.default_project, template_id=TEMPLATE_ID, doc_with_space=doc_with_space, title=TEMPLATE_TITLE) TEMPLATE_ID = tmp.test_run_id tr = TestRun.create(project_id=Document.default_project, test_run_id=TEST_RUN_ID, template=TEMPLATE_ID, title=TEST_RUN_TITLE) TEST_RUN_ID = tr.test_run_id self.assertEquals(len(tr.records), 1) self.assertEquals(tr.records[0].test_case_id, WI_ID) self.doc_create.session.tx_commit()
def test_run(context, path, test_run_id, test_template_id, user, project): """Execute a test run based on jUnit XML file.""" test_run_id = re.sub(INVALID_TEST_RUN_CHARS_REGEX, '', test_run_id) results = parse_junit(path) try: test_run = TestRun(test_run_id, project_id=project) click.echo('Test run {0} found.'.format(test_run_id)) except PylarionLibException as err: click.echo(err, err=True) click.echo('Creating test run {0}.'.format(test_run_id)) test_run = TestRun.create(project, test_run_id, test_template_id) OBJ_CACHE['test_run'] = test_run OBJ_CACHE['user'] = user TestRun.session.tx_begin() pool = multiprocessing.Pool(context.obj['jobs']) pool.map(add_test_record, results) pool.close() pool.join() TestRun.session.tx_commit()
def main(): """ This script will create a Test Run with id sys.argv[1] and execute all test cases. After this script execution complete, the new Test Run should show all test cases passed and the Test Run status is finished. argument sys.argv[1]: id name of a new Test Run """ PROJECT = "MaistraIstio" # Creating a Test Run: tr = TestRun.create(project_id=PROJECT, test_run_id=sys.argv[1], template="Build Acceptance type", title="Istio-Tech-Preview-" + sys.argv[1]) # changing status tr.status = "inprogress" # Adding a test record num_recs = len(tr.records) print("Number of records: ", num_recs) sorted_records = sorted(tr.records, key=lambda record: record.test_case_id) for i in range(num_recs): tr.update_test_record_by_fields( test_case_id=sorted_records[i].test_case_id, test_result="passed", test_comment="Test case " + sorted_records[i].test_case_id + " passed smoothly", executed_by="yuaxu", executed=datetime.datetime.now(), duration=150) print(sorted_records[i].test_case_id + " executed.") if i % 10 == 0: tr.reload() # changing status tr.status = "finished"
def test_run(path, test_run_id, test_template_id, user, project): """Execute a test run based on jUnit XML file.""" results = parse_junit(path) try: test_run = TestRun(test_run_id, project_id=project) click.echo('Test run {0} found.'.format(test_run_id)) except PylarionLibException as err: click.echo(err, err=True) click.echo('Creating test run {0}.'.format(test_run_id)) test_run = TestRun.create(project, test_run_id, test_template_id) for result in results: test_case_id = '{0}.{1}'.format(result['classname'], result['name']) test_case = TestCase.query(test_case_id) if len(test_case) == 0: click.echo( 'Was not able to find test case with id {0}, skipping...' .format(test_case_id) ) continue status = POLARION_STATUS[result['status']] work_item_id = test_case[0].work_item_id click.echo( 'Adding test record for test case {0} with status {1}.' .format(work_item_id, status) ) try: test_run.add_test_record_by_fields( test_case_id=work_item_id, test_result=status, test_comment=result.get('message'), executed_by=user, executed=datetime.datetime.now(), duration=float(result.get('time', '0')) ) except PylarionLibException as err: click.echo('Skipping test case {0}.'.format(work_item_id)) click.echo(err, err=True)
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))
def create_testrun(self, title, level='Must'): ret = TestRun.create( TR_PROJECT_ID, TR_ID.format(title.replace(".", "_"), self.get_current_date()), TR_TPL.format(level)) return ret