示例#1
0
    def get_cases(userid):

        # the mongodb store status as 1,2,3,4,5,6, transfer to noticable strings
        status = ["IDLE", "PASS", "FAIL", "RUNNING", "PAUSE", "BLOCK", "ERROR"]

        # get all UNPASSED case_run of person
        all_case_run = mongo_tt.find(
            {"name": "case_run", "assignee": userid, "iscurrent": 1, "case_run_status_id": {"$ne": 2}}, {"_id": 0}
        )

        items = {}
        """items stores params that will be sent to template, like follow:
        {runid_1: {'summary':'summary_of_run',
                   'cases':[{case_run_id:xx,...{bugs:[bug1,bug2]},},
                            {case2....}]},
         runid_2: {'summary':'summary_of_run',...}
        }"""
        # get expired runs
        expired_run = []
        for i in mongo_tt.find({"name": "runs", "expire": 1}, {"run_id": 1}):
            expired_run.append(i["run_id"])

        for i in all_case_run:
            # escape cases in expired run
            run_id = i.pop("run_id")
            if run_id in expired_run:
                continue

            item = items.setdefault(run_id, {})
            # get summary of run
            if "summary" not in item:
                run_info = mongo_tt.find_one({"name": "runs", "run_id": run_id})
                run_summary = run_info.get("summary")
                item["summary"] = run_summary

            case_run_status = i["case_run_status_id"]
            i["case_run_status_id"] = status[case_run_status - 1]

            # show bugs of test case
            bugs = mongo_tt.find(
                {"name": "bugs", "case_id": i["case_id"]}, {"_id": 0, "bug_id": 1, "bug_status": 1, "short_desc": 1}
            )
            if "bugs" not in i:
                i["bugs"] = [bug for bug in bugs]

            item_cases = item.setdefault("cases", [])
            item_cases.append(i)
        return items
示例#2
0
    def get(self, person):
            if '@' not in person:
                person = person + '@suse.com'
            userid, realname = util.get_id_by_email(person)
            #get all UNPASSED case_run of person
            all_case_run= mongo_tt.find({'name':'case_run', 'assignee':userid,
                            'iscurrent':1, 'case_run_status_id':{'$ne':2}})

            items={}
            '''items stores params that will be sent to template, like follow:
            {runid_1: {'summary':'summary_of_run',
                       'cases':[{case_run_id:xx,...{bugs:[bug1,bug2]},},
                                {case2....}]},
             runid_2: {'summary':'summary_of_run',...}
            }'''
            #get expired runs
            expired_run = []
            for i in mongo_tt.find({'name':'runs', 'expire':1}, {'run_id':1}):
                expired_run.append(i['run_id'])

            for i in all_case_run:
                i.pop('_id')

                #escape cases in expired run
                run_id = i.pop('run_id')
                if run_id in expired_run:
                    continue

                item = items.setdefault(run_id, {})
                #get summary of run
                if 'summary' not in item:
                    run_info = mongo_tt.find_one({'name':'runs', 'run_id':run_id})
                    run_summary = run_info.get('summary')
                    item['summary'] = run_summary

                case_run_status = i['case_run_status_id']
                i['case_run_status_id'] = self.status[case_run_status - 1]

                #show bugs of test case
                bugs = mongo_tt.find({'name':'bugs', 'case_id':i['case_id']},
                        {'_id':0, 'bug_id':1, 'bug_status':1, 'short_desc':1})
                if 'bugs' not in i:
                    i['bugs'] = [bug for bug in bugs]

                item_cases = item.setdefault('cases', [])
                item_cases.append(i)
            self.render('person.html', person=realname, items=items)
def update_testcase_bugs():
    # only to query cases that are failed or blocked to save server force
    cases = mongo_tt.find({"name": "case_run", "case_run_status_id": {"$in": [3, 4, 5, 6]}}, {"case_id": 1})
    caseids = [i["case_id"] for i in cases]
    caseids = set(caseids)  # avoid duplicate cases
    for case in caseids:
        print(case)
        bugs = proxy.TestCase.get_bugs(case)
        for bug in bugs:
            # I found a situation that a bug binded with a test case bug have no
            # run. I don't know why. So escape it
            if "case_run_id" not in bug:
                continue
            bug["name"] = "bugs"
            bug["case_id"] = case
            mongo_tt.update_one({"name": "bugs", "case_run_id": bug["case_run_id"]}, {"$set": bug}, upsert=True)
def update_case_runs():
    runs = mongo_tt.find({"name": "runs"}, {"run_id": 1, "_id": 0})
    runids = [r["run_id"] for r in runs]
    print(runids)
    for runid in runids:
        case_runs = proxy.TestRun.get_test_case_runs(runid)
        for case_run in case_runs:
            case_run["name"] = "case_run"
            mongo_tt.update_one(
                {"name": "case_run", "case_run_id": case_run["case_run_id"]}, {"$set": case_run}, upsert=True
            )

    for runid in runids:
        cases = proxy.TestRun.get_test_cases(runid)
        for case in cases:
            # use update_many, since a case may have many case_run
            mongo_tt.update_many({"name": "case_run", "case_id": case["case_id"]}, {"$set": case}, upsert=True)