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 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 test_005_test_record_by_fields(self): """This test does the following: * gets a TestRun object * Adds a TestRecord to it ** verifies that it fails with an invalid result ** verifies that it fails if it adds a duplicate case. * Adds an attachment to the record. ** verifies that the attachment is there * deletes the attachment ** verifies the attachment is not there * updates the test record. """ tr = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID) with self.assertRaises(PylarionLibException): tr.add_test_record_by_fields(self.NEW_TEST_CASE, "invalid", "No Comment", tr.logged_in_user_id, datetime.datetime.now(), "50.5") tr.add_test_record_by_fields(self.NEW_TEST_CASE, "passed", "No Comment", tr.logged_in_user_id, datetime.datetime.now(), "50.5") tr.reload() self.assertEqual(tr.status, "finished") # test that the same case cannot be added multiple times. with self.assertRaises(PylarionLibException): tr.add_test_record_by_fields(self.NEW_TEST_CASE, "passed", "No Comment", tr.logged_in_user_id, datetime.datetime.now(), "50.5") tr.reload() rec = tr.records[-1] tr.add_attachment_to_test_record(rec.test_case_id, ATTACH_PATH, ATTACH_TITLE) tr.reload() rec = tr.records[-1] self.assertTrue(len(rec.attachments) == 1) self.assertEqual(rec.attachments[0].title, ATTACH_TITLE) tr.delete_attachment_from_test_record(rec.test_case_id, rec.attachments[0].filename) tr.reload() rec = tr.records[-1] self.assertEqual(rec.attachments, []) tr.update_test_record_by_fields(rec.test_case_id, rec.result, "Yes Comment", rec.executed_by, rec.executed, rec.duration) tr.reload() rec = tr.records[-1] self.assertEqual(rec.comment, "Yes Comment")