Esempio n. 1
0
 def map_tc2req(self, qc_test_id, requirement_id):
     coverage = self.client.getReqCoverageByTCID(qc_test_id)
     if requirement_id in coverage:
         Log.info('Requirement map already exists - no need to create')
     else:
         Log.info('Requirement map missing - creating')
         self.client.addReqCoverage(qc_test_id, requirement_id)
Esempio n. 2
0
 def add_tc(self, test_path, test_id, test_name, test_prio):
     parent_id = self.client.resolveTestFolderQcId(test_path)
     existing_test_id = self.client.getTestCaseByTCID(
         test_id, parent_id=parent_id, raise_on_empty_match=False)
     if existing_test_id:
         Log.info('test %s: id=%s already exists - updating' %
                  (test_id, existing_test_id))
         self.client.updateTestCase(existing_test_id, parent_id, test_id,
                                    test_name, test_prio)
     else:
         Log.info('test %s: not existing - adding' % (test_id))
         existing_test_id = self.client.addTestCase(parent_id, test_id,
                                                    test_name, test_prio)
     return int(existing_test_id)
Esempio n. 3
0
 def _report(self, testset_opt, testset_id_opt, release=None, build=None):
     Log.critical("Trying to connect QualityCenter...")
     # Log.info('Connected to QCXML version %s' % client.GetVersion())
     Log.critical("Validating data...")
     if testset_id_opt:
         testset_qcid = testset_id_opt
     else:
         testset_path, testset_name = self._split_testset_argument(
             testset_opt)
         try:
             testset_qcid = self.client.FindTestSet(testset_path,
                                                    testset_name)
         except:
             testset_qcid = self.client.AddTestSet(testset_path,
                                                   testset_name)
     already_added_cases = self.client.GetTestSetInstances(testset_qcid)
     Log.info(
         'QC internal ID for the test set is "%s". It contains instances for %s test cases'
         % (testset_qcid, len(already_added_cases)))
     results = []
     for result in self.results:
         # Extend result dicts with QC internal IDs for test cases
         try:
             test_case_id = result['test_case_id'].split()[0]
             qcid = self.client.FindTestCase(test_case_id)
             Log.info('QC internal ID for test case "%s" is "%s"' %
                      (test_case_id, qcid))
             result['qcid'] = qcid
             qcstatus = "Passed" if result['status'] == "PASS" else "Failed"
             result['qcstatus'] = qcstatus
             results.append(result)
         except Exception, errmsg:
             Log.info("test case id <%s> error: %s" %
                      (test_case_id, errmsg))
Esempio n. 4
0
 def test_case_search_root(self):
     Log.info('Password not given in configuration %s' % self.config_path)
     tc_root = self.config.get('test_case_search_root')
     return re.sub('&', '&amp;', tc_root)
Esempio n. 5
0
class RobotToQcReporter(QcXmlHandler):
    def __init__(self):
        super(RobotToQcReporter, self).__init__()
        self.results = None

    def run(self, args):
        self.results = RobotResultParser(args.report).get_results()
        self._report(args.testset, args.testset_id, args.release, args.build)

    @staticmethod
    def _split_testset_argument(testset_input):
        Log.debug("Parsing test set '%s'" % testset_input)
        match = re.search(r'\\', testset_input)
        if not match:
            raise QcReporterException(
                "Test set path must look like 'Root\\Folder\\...\\Test set name' "
                "and it must contain at least one path separator character ('\\')"
            )
        testset_components = testset_input.rsplit('\\', 1)
        testset_path = testset_components[0]
        testset_name = testset_components[1]
        Log.debug("Looking for test set %s in path %s" %
                  (testset_name, testset_path))
        return (testset_path, testset_name)

    def _report(self, testset_opt, testset_id_opt, release=None, build=None):
        Log.critical("Trying to connect QualityCenter...")
        # Log.info('Connected to QCXML version %s' % client.GetVersion())
        Log.critical("Validating data...")
        if testset_id_opt:
            testset_qcid = testset_id_opt
        else:
            testset_path, testset_name = self._split_testset_argument(
                testset_opt)
            try:
                testset_qcid = self.client.FindTestSet(testset_path,
                                                       testset_name)
            except:
                testset_qcid = self.client.AddTestSet(testset_path,
                                                      testset_name)
        already_added_cases = self.client.GetTestSetInstances(testset_qcid)
        Log.info(
            'QC internal ID for the test set is "%s". It contains instances for %s test cases'
            % (testset_qcid, len(already_added_cases)))
        results = []
        for result in self.results:
            # Extend result dicts with QC internal IDs for test cases
            try:
                test_case_id = result['test_case_id'].split()[0]
                qcid = self.client.FindTestCase(test_case_id)
                Log.info('QC internal ID for test case "%s" is "%s"' %
                         (test_case_id, qcid))
                result['qcid'] = qcid
                qcstatus = "Passed" if result['status'] == "PASS" else "Failed"
                result['qcstatus'] = qcstatus
                results.append(result)
            except Exception, errmsg:
                Log.info("test case id <%s> error: %s" %
                         (test_case_id, errmsg))

        Log.critical("Reporting results...")
        for r in results:
            Log.info('Reporting "%s" ("%s", QC: %s) as "%s"' %
                     (r['name'], r['test_case_id'], r['qcid'], r['qcstatus']))
            if r['qcid'] in already_added_cases:
                instance_qcid = already_added_cases[r['qcid']]
            else:
                instance_qcid = self.client.AddTestToTestSet(
                    r['qcid'], testset_qcid)
            self.client.AddRunToTestSet(instance_qcid, testset_qcid,
                                        r['qcstatus'], release, build)
        Log.info("Source result [%s] -> uploaded result [%s]" %
                 (self.results.__len__(), results.__len__()))
        Log.critical("Reporting completed")