def revert_svn():
    proj = Project(Project.default_project)
    proj_grp = proj.project_group.name
    svn_url = "%s/%s/%s" % (proj.repo, proj_grp, proj.project_id)
    LOCAL_DIR = "/tmp/%s" % proj.project_id
    USER = proj.logged_in_user_id
    PASS = proj.session.password
    svn = pysvn.Client()
    svn.set_default_username(USER)
    svn.set_default_password(PASS)
    svn.set_store_passwords(False)
    svn.checkout(svn_url, LOCAL_DIR)
    svn_log = svn.log(LOCAL_DIR)
    #    first_revision = svn_log[-1].revision
    for log in svn_log:
        if log.revision.number == REVERT_TO:
            break
    first_revision = log.revision
    last_revision = svn_log[0].revision
    svn.merge(LOCAL_DIR, last_revision, LOCAL_DIR, first_revision, LOCAL_DIR)
    svn.checkin(LOCAL_DIR, "revert to original version")
    # The original Example template query has an extra colon.
    # After revert, must fix that.
    tmpl = TestRun(project_id=proj.project_id, test_run_id="Example")
    tmpl.query = tmpl.query.replace("::", ":")
    tmpl.update()
Ejemplo n.º 2
0
    def update_all_case_results_for_run(self, run, result, user, comment):

        run = run.strip()
        tr = TestRun(run, None, TestRun.default_project)
        print('\nUpdate %s:' % run)

        if not comment:
            comment = ''

        print('Total records: %d' % len(tr.records))
        print('Updated Date Time    Result  CaseID')
        print('-------------------  ------  -----------')

        if user == 'None':
            user = TestRun.logged_in_user_id

        for rec in tr.records:
            rec.executed = datetime.datetime.now()
            rec.executed_by = user
            executed_str = str(rec.executed).split('.')[0]
            rec.result = result
            rec.comment = comment

            print('%-20s %-7s %s' % (executed_str, result, rec.test_case_id))
            tr.update_test_record_by_object(rec.test_case_id, rec)
        print('Done!')
Ejemplo n.º 3
0
    def update_all_results_for_run(self, run, result, user, comment):

        tr = TestRun(run.strip(), None, TestRun.default_project)
        print 'Update %s:' % run.strip()

        if not comment:
            comment = ''

        print 'Total records: %d' % len(tr.records)
        print 'Updated Date Time    Result  CaseID'
        print '-------------------  ------  -----------'

        if user == 'None':
            user = TestRun.logged_in_user_id

        for rec in tr.records:
            rec.executed = datetime.datetime.now()
            rec.executed_by = user
            executed_str = str(rec.executed).split('.')[0]
            rec.result = result
            rec.comment = comment

            print '%-20s %-7s %s' % (executed_str,
                                     result,
                                     rec.test_case_id)
            tr.update_test_record_by_object(rec.test_case_id,
                                            rec)
        print 'Done!'
Ejemplo n.º 4
0
    def update_1_result_for_run(self,
                                run,
                                testcase,
                                result,
                                user,
                                comment):

        if not comment:
            comment = ''

        tr = TestRun(run.strip(), None, TestRun.default_project)
        print 'Update %s:' % run

        if user == 'None':
            user = TestRun.logged_in_user_id

        for rec in tr.records:
            rec.executed = datetime.datetime.now()
            rec.executed_by = user
            rec.result = result
            rec.comment = comment

            if rec.test_case_id == testcase:
                tr.update_test_record_by_object(testcase, rec)
                print '%4sSet %s to %s (verdict %s)' % ('',
                                                        testcase,
                                                        result,
                                                        comment)
        print 'Done!'
Ejemplo n.º 5
0
 def test_001_create_template(self):
     """This test does the following:
     * Creates a TestRun template based on the "Empty" template
     * Verifies that the returned object exists and is a template
     * Adds a custom field as a kwarg
     * Tries to create another template with an invalid enum value in kwarg
     * Tries to create another template with an invalid kwarg
     """
     global TEMPLATE_ID
     template = TestRun.create_template(DEFAULT_PROJ,
                                        TEMPLATE_ID,
                                        "Empty",
                                        title=TEMPLATE_TITLE,
                                        arch="i386")
     TEMPLATE_ID = template.test_run_id
     self.assertIsNotNone(template.test_run_id)
     self.assertTrue(template.is_template)
     self.assertEqual(template.arch, "i386")
     with self.assertRaises(PylarionLibException):
         template = TestRun.create_template(DEFAULT_PROJ,
                                            TEMPLATE_ID + "1",
                                            "Empty",
                                            TEMPLATE_TITLE + "1",
                                            arch="BAD")
     with self.assertRaises(PylarionLibException):
         template = TestRun.create_template(DEFAULT_PROJ,
                                            TEMPLATE_ID + "2",
                                            "Empty",
                                            TEMPLATE_TITLE + "2",
                                            notaparm="BAD")
Ejemplo n.º 6
0
    def update_1_case_result_for_run(self, run, testcase, result, user,
                                     comment):

        if not comment:
            comment = ''

        tr = TestRun(run.strip(), None, TestRun.default_project)
        print('Update %s:' % run)

        if user == 'None':
            user = TestRun.logged_in_user_id

        is_found = False
        for rec in tr.records:
            if rec.test_case_id == testcase:
                is_found = True
                rec.executed = datetime.datetime.now()
                rec.executed_by = user
                rec.result = result
                rec.comment = comment

                tr.update_test_record_by_object(testcase, rec)
                print("%4sSet %s to %s (verdict comment: '%s')" %
                      ('', testcase, result, comment))
                return 0

        if not is_found:
            print('Test case %s is not found in run.' % testcase)
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
    def update_status_for_run(self,
                              run,
                              status):

        tr = TestRun(run.strip(), None, TestRun.default_project)
        tr.status = status
        tr.update()
        print 'Updated %s status -> %s' % (run, status)
 def test_custom_testrun(self):
     testrun = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     self.assertIsNotNone(testrun.arch)
     with self.assertRaises(PylarionLibException):
         testrun.arch = "bad"
     valid_values = testrun.get_valid_field_values("arch")
     testrun.arch = valid_values[0]
     self.assertEqual(valid_values[0], testrun.arch)
Ejemplo n.º 10
0
    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_uri_obj(self):
     testrun2 = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     self.assertEqual(testrun2.template, "example")
     new_template = TestRun.create_template(DEFAULT_PROJ,
                                            TEMPLATE_ID,
                                            "example",
                                            title=TEMPLATE_TITLE)
     testrun2.template = new_template
     self.assertEqual(testrun2.template, new_template.test_run_id)
     self.assertNotEqual(testrun2.template, "example")
Ejemplo n.º 12
0
 def test_003_get(self):
     """This test does the following:
     * Verifies error with invalid test_run_id
     * Gets a valid TestRun
     * verifies that the TestRun retrieves has the expected test_run_id
     """
     with self.assertRaises(PylarionLibException):
         TestRun(project_id=DEFAULT_PROJ, test_run_id="InValid")
     tr = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     self.assertEqual(tr.test_run_id, TEST_RUN_ID)
 def test_custom_testrun2(self):
     """this test does the following:
     * Instantiate an empty test run.
     * verify that the custom field exists and is None
     * test an invalid value
     * test a valid value
     * verify that it saves it in the attribute
     """
     testrun = TestRun()
     self.assertIsNone(testrun.arch)
     with self.assertRaises(PylarionLibException):
         testrun.arch = "bad"
     valid_values = testrun.get_valid_field_values("arch")
     testrun.arch = valid_values[0]
     self.assertEqual(valid_values[0], testrun.arch)
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 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")
Ejemplo n.º 16
0
    def get_template(self, temp_id):
        """
        Gets a TestRun template

        :param temp_id:
        :return:
        """
        from pylarion.test_run import TestRun

        for x in ["-", "."]:
            if x in temp_id:
                temp_id = temp_id.replace(x, "\{}".format(x))
        t_runs = TestRun.search('"{}"'.format(temp_id), fields=["test_run_id", "created", "is_template"],
                                sort="created",
                                search_templates=True)
        from pylarion.exceptions import PylarionLibException
        tr = None
        for t in t_runs:
            tr = TestRun(uri=t.uri)
            try:
                if tr.plannedin is not None:
                    break
            except PylarionLibException:
                pass
        else:
            raise Exception("Could not find template")

        return tr
Ejemplo n.º 17
0
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()
Ejemplo n.º 18
0
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 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
Ejemplo n.º 20
0
def collect():
    args = parse()
    trs = TestRun.search("project.id:{0} AND status:notrun AND isautomated:true".format(args.project_id))
    jenkins_url = 'http://{}:{}'.format(args.jenkins, args.jenkins_port)
    jenkins_obj = jenkins.Jenkins(jenkins_url, username=args.jenkins_user, password=args.jenkins_pass)
    for tr in trs:
        jenkins_obj.build_job('PolarionTest', {'PROJECT_ID': args.project_id, 'RUN_ID': tr.test_run_id})
Ejemplo n.º 21
0
    def print_runs_by_query(self, query, is_template=False):
        query_ful = 'project.id:%s AND %s' % (TestRun.default_project, query)
        fields = [
            'query', 'created', 'test_run_id', 'select_test_cases_by',
            'status', 'plannedin', 'assignee', 'author'
        ]

        st = TestRun.search(query_ful, fields, 'created', -1, is_template)
        Object = ''
        if is_template:
            Object = 'Template'

        prestr = 'Created Time %8sAuthor %3sAssignee' % ('', '')
        latstr = '%sStatus %3sPlanID%10s%s' % ('', '', '', Object)
        preln = '------------%9s------%4s------' % ('', '')
        latln = '%2s--------%2s-------%9s--------' % ('', '', '')

        print('%s %s' % (prestr, latstr))
        print('%s %s' % (preln, latln))

        for tp in st:
            created_time = str(tp.created).split('.')[0]
            print('%-20s %-9s %-8s %-10s%-15s %s' %
                  (created_time, tp.author, tp.assignee, tp.status,
                   tp.plannedin, tp.test_run_id))
Ejemplo n.º 22
0
 def test_010_search_with_custom_fields(self):
     """This test does the following:
     * Gets a TestRun
     * Searches using the same query as the testrun (adding project id)
     * and with custom_field 'plannedin'
     * verifies that the 'plannedin' field of the returnd TestRun is None
     * The purpose here is to check that it doesnt throws exception
     """
     query = "id:%s" % (TEST_RUN_ID)
     lst_tr = TestRun.search(query, ["plannedin"])
     self.assertEqual(lst_tr[0].plannedin, None)
     lst_tr[0].plannedin = self.NEW_PLAN
     lst_tr[0].update()
     lst_tr = TestRun.search(query, ["plannedin"])
     self.assertEqual(lst_tr[0].plannedin, self.NEW_PLAN)
     lst_tr[0].plannedin = None
     lst_tr[0].update()
Ejemplo n.º 23
0
 def test_013_incident_report_test(self):
     """This test does the following:
     * gets a TestRun
     * gets a TestCase
     * adds test_steps
     * creates a TestRecord
     * populates the TestRecord
     * Fail the testRecord
     * reloads the TestCase
     * Verifies that an Incident Report was Created
     """
     tr = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     tests = [["Test 1", "Result 1"], ["Test 2", "Result 2"],
              ["Test 3", "Result 3"]]
     set_steps = []
     for test in tests:
         ts = TestStep()
         ts.values = test
         set_steps.append(ts)
     tc = TestCase(work_item_id=self.NEW_TEST_CASE)
     tc.set_test_steps(set_steps)
     tc.update()
     tc.reload()
     steps = tc.test_steps.steps
     results = []
     for step in steps:
         res = TestStepResult()
         res.result = "failed"
         res.comment = "This is the result"
         results.append(res)
     rec = TestRecord()
     rec.test_step_results = results
     rec.test_case_id = self.NEW_TEST_CASE
     rec.comment = "Incident Report was Created"
     rec.duration = "50.5"
     rec.result = "failed"
     rec.executed_by = tr.logged_in_user_id
     rec.executed = datetime.datetime.now()
     tr.update_test_record_by_object(self.NEW_TEST_CASE, rec)
     tc.reload()
     linked_work_items = tc.linked_work_items_derived
     idx = len(linked_work_items) - 1
     incident = Incident(project_id="proj1",
                         work_item_id=linked_work_items[idx].work_item_id)
     self.assertIsNotNone(incident)
Ejemplo n.º 24
0
 def test_012_search_with_URI_fields(self):
     """This test does the following:
     * Gets a TestRun
     * Searches using the same query as the testrun (adding project id)
     * Verify that 'author' is instantiated
     """
     query = "id:%s" % (TEST_RUN_ID)
     lst_tr = TestRun.search(query, fields=["author"])
     self.assertIsNotNone(lst_tr[0].author)
 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()
Ejemplo n.º 26
0
def check_for_spare_test_runs_in_excel():

    print("Test run in excel but not in Polarion already: ")
    test_run_ids = [""]
    print(test_run_ids.__len__())

    for id in test_run_ids:
        test_run = TestRun.search(id)
        if not test_run.__len__():
            print(id)
Ejemplo n.º 27
0
 def test_004_search(self):
     """This test does the following:
     * Gets a TestRun
     * Searches using the same query as the testrun (adding project id)
     * verifies that there are number of records returned as are in the
       records attribute of the TestRun
     """
     query = "id:%s" % (TEST_RUN_ID)
     lst_tr = TestRun.search(query)
     self.assertEqual(lst_tr[0].test_run_id, TEST_RUN_ID)
Ejemplo n.º 28
0
 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 test_arr_obj(self):
     testrun = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     recs = testrun.records
     if not isinstance(recs, list):
         recs = []
         cnt = 0
     else:
         cnt = len(recs)
     rec = TestRecord()
     rec.test_case_id = self.TEST_CASE_ID
     rec.executed = datetime.datetime.now()
     rec.executed_by = USER
     rec.duration = "5.0"
     rec.result = "passed"
     recs.append(rec)
     testrun.records = recs
     self.assertEqual(cnt + 1, len(testrun.records))
     recs = testrun.records
     rec = recs[-1]
     self.assertEqual(rec.result, "passed")
Ejemplo n.º 30
0
    def create_test_run_template(self, template_id, case_type="automatedProcess", query=None):
        """
        Creates a TestRun template that can be used as a basis for other TestRuns

        :param template_id: a unique str to give as ID for this template
        :param case_type:
        :param query:
        :return:
        """
        from pylarion.test_run import TestRun
        test_template = TestRun.create_template(self.project, template_id, query=query,
                                                select_test_cases_by=case_type)
        return test_template
Ejemplo n.º 31
0
    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()
Ejemplo n.º 32
0
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)
Ejemplo n.º 33
0
    def print_testcases_from_run(self, run):
        tr = TestRun(run, None, TestRun.default_project)
        print('(Only CaseID can be displayed when --run=$template)')
        print('List cases for: %s\n' % run)
        ttstr = ('Created Time %8sStatus %1sExecutedBy %2sCaseID' %
                 ('', '', ''))
        lnstr = ('------------%9s------%2s----------%3s------' % ('', '', ''))
        print(ttstr)
        print(lnstr)

        for rec in tr.records:
            time = str(rec.executed).split('.')[0]
            print('%-21s%-9s%-12s%-10s' %
                  (time, rec.result, rec.executed_by, rec.test_case_id))
Ejemplo n.º 34
0
    def get_test_run(test_run_id):
        """
        Looks for matching TestRun given a test_run_id string

        :param test_run_id:
        :return:
        """
        from pylarion.test_run import TestRun
        tr = TestRun.search('"{}"'.format(test_run_id), fields=[u"test_run_id"],
                            sort="created")
        tr = itz.first(tr)
        if tr:
            tr = TestRun(uri=tr.uri)
        return tr
Ejemplo n.º 35
0
def collect():
    args = parse()
    trs = TestRun.search(
        "project.id:{0} AND status:notrun AND isautomated:true".format(
            args.project_id))
    jenkins_url = 'http://{}:{}'.format(args.jenkins, args.jenkins_port)
    jenkins_obj = jenkins.Jenkins(jenkins_url,
                                  username=args.jenkins_user,
                                  password=args.jenkins_pass)
    for tr in trs:
        jenkins_obj.build_job('PolarionTest', {
            'PROJECT_ID': args.project_id,
            'RUN_ID': tr.test_run_id
        })
Ejemplo n.º 36
0
 def test_008_update(self):
     """This test does the following:
     * gets a TestRun
     * modifies an attribute
     * updates the TestRun
     * reloads the TestRun
     * verifies that the TestRun attribute has changed
     """
     tr = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     tr.type = "featureverification"
     tr.update()
     tr.reload()
     self.assertEqual(tr.type, "featureverification")
Ejemplo n.º 37
0
def polarion_collect_items(config):
    polarion_run = config.getoption('polarion_run')
    polarion_proj = config.getoption('polarion_project')
    tr = TestRun(project_id=polarion_proj, test_run_id=polarion_run)

    # caching TestRun
    config.option.test_run_obj = tr

    items = {rec.test_case_id: rec for rec in tr.records}
    if not items:
        pytest.fail('Failed to collect items from polarion {} run'.format(polarion_run))

    # caching test records
    config.option.test_run_records = items
    return items
Ejemplo n.º 38
0
 def test_011_customfield_object(self):
     """This test does the following:
     * gets a TestRun
     * Adds a Plan to it
     * Verifies that the plan was added
     * Verifies that a non valid plan cant be added
     """
     tr = TestRun(project_id=DEFAULT_PROJ, test_run_id=TEST_RUN_ID)
     with self.assertRaises(PylarionLibException):
         tr.plannedin = "not_valid"
     tr.plannedin = self.NEW_PLAN
     self.assertEquals(tr.plannedin, self.NEW_PLAN)
     tr.update()
Ejemplo n.º 39
0
def get_latest_test_run(test_run_name):
    """
    Gets the most recent TestRun based on the test_run_name

    NOTE: the test_run_name should be the name of a test run without the integer.
    For example, if your TestRun id is normally "Jenkins Run 1", then test_run_name
    should be "Jenkins Run".

    :param test_run_name: test run id string
    :return: TestRun
    """
    from pylarion.test_run import TestRun
    s = TestRun.search('"{}"'.format(test_run_name),
                       fields=["test_run_id", "created", "status"],
                       sort="created")
    current = None
    if s:
        latest = itz.last(s)
        current = TestRun(uri=latest.uri)
    return current
Ejemplo n.º 40
0
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()
Ejemplo n.º 41
0
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()
Ejemplo n.º 42
0
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"
Ejemplo n.º 43
0
    def print_runs_by_query(self, query, is_template=False):
        query_ful = 'project.id:%s AND %s' % (TestRun.default_project, query)
        fields = ['query',
                  'created',
                  'test_run_id',
                  'select_test_cases_by',
                  'status',
                  'plannedin',
                  'assignee',
                  'author']

        st = TestRun.search(query_ful,
                            fields,
                            'created',
                            -1,
                            is_template)
        Object = ''
        if is_template:
            Object = 'Template'

        prestr = 'Created Time %8sAuthor %3sAssignee' % ('', '')
        latstr = '%sStatus %3sPlanID%10s%s' % ('', '', '', Object)
        preln = '------------%9s------%4s------' % ('', '')
        latln = '%2s--------%2s-------%9s--------' % ('', '', '')

        print '%s %s' % (prestr, latstr)
        print '%s %s' % (preln, latln)

        for tp in st:
            created_time = str(tp.created).split('.')[0]
            print '%-20s %-9s %-8s %-10s%-15s %s' % (created_time,
                                                     tp.author,
                                                     tp.assignee,
                                                     tp.status,
                                                     tp.plannedin,
                                                     tp.test_run_id)
Ejemplo n.º 44
0
    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))