Beispiel #1
0
    def render_admin_panel(self, req, cat, page, path_info):
        """ main request handler
        """
        if TESTER_PERMISSION in req.perm:
            #template data
            data = dict()
            data["info"] = req.args.get("info", "")
            data["warning"] = req.args.get("warning", "")
            data["error"] = req.args.get("error", "")
            data["display_status"] = get_display_states(self)
            data["id"] = req.args.get("path_info", None)
            data["page"] = 'TestManager_accordion.html'

            data["url"] = req.abs_href + req.path_info
            # get the testcase

            data['priorities'] = self.get_priorities()
            data['default_priority'] = self.get_default_priority()
            if data["id"]:
                try:
                    testcase = models.TestCaseQuery(
                        self.env,
                        tcid=data['id']
                    ).execute()[0]
                    for action in testcase.actions:
                        action.color = {
                            "style": ("background:%s"
                                      % get_status_color(action.status))
                        }
                    data["TestCaseTitle"] = testcase.title.strip('=')
                    data["TestCaseDescription"] = testcase.description
                    data["TestCaseActions"] = testcase.actions
                    data["revision"] = testcase.revision
                    data["title"] = '(%s) ' % testcase.tcid + testcase.wiki
                    # XXX: we have to fix this in 1.0 because
                    #      wiki_to_html is deprecated
                    for action in testcase.actions:
                        action.description = wiki_to_html(
                            action.description, self.env, req)
                        action.expected_result = wiki_to_html(
                            "''Result:''[[BR]]" + action.expected_result,
                            self.env, req)
                        for comment in action.comments:
                            comment["text"] = wiki_to_html(
                                comment["text"], self.env, req)
                    if req.authname != testcase.tester:
                        # assigned to someone else
                        # but can be done by mr urlaubsvertretung
                        data["warning"] = 'this testcase %s %s' % (
                            'has been assigned to',
                            testcase.tester)
                except TracError:
                    # not found
                    data["error"] = '%s %s %s' % ('the requested testcase ',
                                                  'could not be found or has',
                                                  'been erased')
            return data["page"], data
Beispiel #2
0
    def get_testcase_group_stats(self, tc_ids):
        total_cnt = len(tc_ids)
        all_statuses = set(models.test_status())
        status_cnt = {}
        for s in all_statuses:
            status_cnt[s] = 0

        if total_cnt:
            db = self.env.get_db_cnx()
            cursor = db.cursor()
            str_ids = [str(x) for x in sorted(tc_ids)]
            cursor.execute("SELECT status, count(status) FROM testcase "
                           "WHERE tcid IN (%s) GROUP BY status" %
                           ",".join(str_ids))
            for s, cnt in cursor:
                status_cnt[s] = cnt

        stat = TestItemGroupStats('testcase status', 'testcases')

        groups = default_teststatus_groups()

        display = get_display_states(self.env)
        for group in groups:
            group_cnt = 0
            query_args = {}
            for s, cnt in status_cnt.iteritems():
                if s in group['statuses']:
                    group_cnt += cnt
                    query_args.setdefault('status', []).append(s)
            for arg in [kv for kv in group.get('query_args', '').split(',')
                        if '=' in kv]:
                k, v = [a.strip() for a in arg.split('=', 1)]
                query_args.setdefault(k, []).append(v)
            group['label'] = display.get(STATES_DISPLAY[group['name']])
            stat.add_interval(
                group.get('label', display.get(STATES_DISPLAY[group['name']])),
                group_cnt, query_args,
                group.get('css_class', group['name']),
                bool(group.get('overall_completion'))
            )
        stat.refresh_calcs()
        return stat
Beispiel #3
0
    def render_admin_panel(self, req, cat, page, path_info):
        """ main request handler
        """
        if not TESTER_PERMISSION in req.perm:
            return

        data = dict() #template data
        data["info"] = req.args.get("info", "")
        data["warning"] = req.args.get("warning", "")
        data["error"] = req.args.get("error", "")
        display = get_display_states(self)
        tm_href = self.env.abs_href("TestManager/general")

        # get the testcase filter args
        filters= dict()
        for arg in req.args:
            if arg in models.TC_KEYS:
                filters[arg]= req.args.get(arg, "")

        # as a filter we get that form value like "passed_comment"
        # in that case we have to use the STATES_DISPLAY const where the real
        # values are stored. As this is bad to understand - this is a real
        # FIXME
        if filters.get('status'):
            for k,v in STATES_DISPLAY.items():
                if v == filters.get('status'):
                    filters['status'] = k
        runs = list()
        if filters.get('testrun', None) is None:
            runs = models.TestRunQuery(self.env, status='accepted').execute()
        else:
            try:
                runs.append(models.TestRun(self.env,
                    int(filters.get('testrun', None))))
            except TypeError:
                # we have more than one testrun
                for run in filters.get('testrun'):
                    runs.append(models.TestRun(self.env, int(run)))
            finally:
                # drop testrun filter
                filters.pop('testrun')

        for run in runs:
            run.testcases = models.TestCaseQuery(
                self.env, testrun=run.id, **filters
            ).execute()

            # build link with genshi
            for tc in run.testcases:
                tc.ref = build_testcase_link(tm_href, tc)

        # The template to be rendered
        display[req.authname] = req.authname
        display['all'] = 'all'
        data["filter"] = {}
        data["testcases"] = runs
        data["page"] = 'TestManager_base.html'
        data["title"] = 'TestCases'

        data["url"] = req.abs_href + req.path_info + "?" + req.query_string
        data["filter_caption"] = "Testcase Status: "
        data["filter"] = [
            models.FAILED, models.NOT_TESTED, models.SKIPPED,
            models.PASSED, models.PASSED_COMMENT
        ]
        html_disp = STATES_DISPLAY.copy()
        for k,v in html_disp.items():
            html_disp[k] = display.get(v)
        data['display_filter'] = html_disp
        return 'TestManager_base.html', data
Beispiel #4
0
    def _create_or_update_ticket(self, runid, testaction, comment, req):
        """ creates or updates a ticket for an action (default ticket
        type if failed, enhancement if otherwise (e.g. passed with comment))
        update means add a comment to the already created ticket
        and add keyword if neccesary
        """
        self.dbg('accordion.request._create_or_update_ticket(%s)' % req.args)
        testrun = Ticket(self.env, tkt_id=runid)
        display = get_display_states(self.env)

        # build ticket summary: <todo>: <action> of <testcase>, e.g.:
        # 'Creator checks in the model of TcCaddocCreate failed.'
        todo = STATES_DISPLAY[testaction.status]
        testcase = models.TestCaseQuery(self.env,
                                        tcid=testaction.tcid).execute()[0]
        summary = "%s of %s %s." % (
            testaction.title, testcase.wiki, display[todo])

        # build description
        description = "Related test case: %s.\n\n%s" % (
            self._build_tc_link(testaction, req),
            comment
        )
        # check if a similar ticket already exists...
        existing_tickets = Query.from_string(
            self.env, "summary=%s" % summary
        ).execute()
        if existing_tickets:
            # if yes return the ticket id
            t = Ticket(self.env, existing_tickets[0]['id'])
            tp_title = self._get_testplan_title(testrun)
            if t['keywords']:
                kws = t['keywords'].split(',')
                if not tp_title in kws:
                    t['keywords'] += ',%s' % tp_title
            else:
                t['keywords'] = tp_title
            t.save_changes(author=req.authname, comment=description)
            return t.id

        # build the ticket
        ticket = Ticket(self.env)

        # determine type of ticket
        ticket_type = ticket.get_default('type')
        if testaction.status != FAILED:
            ticket_type = 'enhancement'

        data = {
            'reporter': req.authname,
            'summary': summary,
            'type': ticket_type,
            'description': description,
            'priority': req.args.get('priority', 'major'),
            'status': 'new',
            'keywords': self._get_testplan_title(testrun),
        }
        self.dbg('ticket data: %s' % data)

        try:
            ticket.populate(data)
            tid = ticket.insert()
            ticket.save_changes()

        except TracError as e:
            self.env.log.error(e)
            raise TracError(
                safe_unicode(
                    "ticket could not be created: %s" % e.message
                )
            )

        return tid