예제 #1
0
파일: models.py 프로젝트: tigerruncode/Kiwi
    def add_bug(self,
                bug_id,
                bug_system_id,
                summary=None,
                description=None,
                case_run=None,
                bz_external_track=False):
        bug, created = self.case_bug.get_or_create(
            bug_id=bug_id,
            case_run=case_run,
            bug_system_id=bug_system_id,
            summary=summary,
            description=description,
        )

        if created:
            if bz_external_track:
                bug_system = BugSystem.objects.get(pk=bug_system_id)
                it = IssueTrackerType.from_name(
                    bug_system.tracker_type)(bug_system)
                if not it.is_adding_testcase_to_issue_disabled():
                    it.add_testcase_to_issue([self], bug)
                else:
                    raise ValueError(
                        'Enable linking test cases by configuring API parameters '
                        'for this Issue Tracker!')
        else:
            raise ValueError('Bug %s already exist.' % bug_id)
예제 #2
0
파일: bug.py 프로젝트: veryhan/Kiwi
def report(test_case_run_id, tracker_id):
    """
    .. function:: XML-RPC Bug.report(test_case_run_id, tracker_id)

        Returns a URL which will open the bug tracker with predefined fields
        indicating the error was detected by the specified TestCaseRun.

        :param test_case_run_id: PK for :class:`tcms.testruns.models.TestCaseRun` object
        :type test_case_run_id: int
        :param tracker_id: PK for :class:`tcms.testcases.models.BugSystem` object
        :type tracker_id: int
        :return: Success response with bug URL or failure message
        :rtype: dict
    """
    response = {
        'rc':
        1,
        'response':
        _('Enable reporting to this Issue Tracker by configuring its base_url!'
          ),
    }

    test_case_run = TestExecution.objects.get(pk=test_case_run_id)
    bug_system = BugSystem.objects.get(pk=tracker_id)
    if bug_system.base_url:
        tracker = IssueTrackerType.from_name(
            bug_system.tracker_type)(bug_system)
        url = tracker.report_issue_from_testcase(test_case_run)
        response = {'rc': 0, 'response': url}

    return response
예제 #3
0
    def tracker_from_url(cls, url):
        """
            Return the IssueTrackerType class for the system
            where ``base_url`` is part of ``url``. Usually we pass
            URLs to pre-existing defects to this method.
        """
        for bug_system in cls.objects.all():
            if url.startswith(bug_system.base_url):
                return IssueTrackerType.from_name(bug_system.tracker_type)

        return None
예제 #4
0
        def file(self):
            bug_system_id = request.GET.get('bug_system_id')
            bug_system = BugSystem.objects.get(pk=bug_system_id)

            if bug_system.base_url:
                tracker = IssueTrackerType.from_name(bug_system.tracker_type)(bug_system)
                url = tracker.report_issue_from_testcase(self.case_run)
                response = {'rc': 0, 'response': url}

            response = {'rc': 1, 'response': 'Enable reporting to this Issue Tracker '
                                             'by configuring its base_url!'}
            return JsonResponse(response)
예제 #5
0
파일: bug.py 프로젝트: veryhan/Kiwi
def create(values, auto_report=False):
    """
    .. function:: XML-RPC Bug.create(values, auto_report=False)

        Attach a bug to pre-existing TestCase or TestCaseRun object.

        :param values: Field values for :class:`tcms.testcases.models.Bug`
        :type values: dict
        :param auto_report: Automatically report to Issue Tracker
        :type auto_report: bool, default=False
        :return: Serialized :class:`tcms.testcases.models.Bug` object
        :raises: PermissionDenied if missing the *testcases.add_bug* permission

        .. note::

            `case_run_id` can be None. In this case the bug will be attached only
            to the TestCase with specified `case_id`.

        Example (doesn't specify case_run_id)::

            >>> Bug.create({
                'case_id': 12345,
                'bug_id': 67890,
                'bug_system_id': 1,
                'summary': 'Testing TCMS',
                'description': 'Just foo and bar',
            })
    """
    bug, _ = Bug.objects.get_or_create(**values)
    response = bug.serialize()
    response['rc'] = 0

    if auto_report:
        tracker = IssueTrackerType.from_name(bug.bug_system.tracker_type)(
            bug.bug_system)

        if not tracker.is_adding_testcase_to_issue_disabled():
            tracker.add_testcase_to_issue([bug.case], bug)
        else:
            response['rc'] = 1
            response['response'] = _(
                'Enable linking test cases by configuring '
                'API parameters for this Issue Tracker!')
    return response
예제 #6
0
파일: views.py 프로젝트: fmca/Kiwi
    def get_context_data(self, **kwargs):
        """Generate report for specific TestRun

        There are four data source to generate this report.
        1. TestRun
        2. Test case runs included in the TestRun
        3. Comments associated with each test case run
        4. Statistics
        5. bugs
        """
        run = TestRun.objects.select_related('manager',
                                             'plan').get(pk=self.run_id)

        case_runs = TestCaseRun.objects.filter(run=run).select_related(
            'case_run_status', 'case',
            'tested_by').only('close_date', 'case_run_status__name',
                              'case__category__name', 'case__summary',
                              'case__is_automated',
                              'case__is_automated_proposed',
                              'tested_by__username')
        mode_stats = self.stats_mode_case_runs(case_runs)
        summary_stats = self.get_summary_stats(case_runs)

        test_case_run_bugs = []
        bug_system_types = {}
        for _bug in get_run_bug_ids(self.run_id):
            # format the bug URLs based on DB settings
            test_case_run_bugs.append((
                _bug['bug_id'],
                _bug['bug_system__url_reg_exp'] % _bug['bug_id'],
            ))
            # find out all unique bug tracking systems which were used to record
            # bugs in this particular test run. we use this data for reporting
            if _bug['bug_system'] not in bug_system_types:
                # store a tracker type object for producing the report URL
                tracker_class = IssueTrackerType.from_name(
                    _bug['bug_system__tracker_type'])
                bug_system = BugSystem.objects.get(pk=_bug['bug_system'])
                tracker = tracker_class(bug_system)
                bug_system_types[_bug['bug_system']] = (tracker, [])

            # store the list of bugs as well
            bug_system_types[_bug['bug_system']][1].append(_bug['bug_id'])

        # list of URLs which opens all bugs reported to every different
        # issue tracker used in this test run
        report_urls = []
        for (issue_tracker, ids) in bug_system_types.values():
            report_url = issue_tracker.all_issues_link(ids)
            # if IT doesn't support this feature or report url is not configured
            # the above method will return None
            if report_url:
                report_urls.append((issue_tracker.tracker.name, report_url))

        case_run_bugs = self.get_case_runs_bugs(run.pk)
        comments = self.get_case_runs_comments(run.pk)

        for case_run in case_runs:
            case_run.bugs = case_run_bugs.get(case_run.pk, ())
            case_run.user_comments = comments.get(case_run.pk, [])

        context = super().get_context_data(**kwargs)
        context.update({
            'test_run': run,
            'test_case_runs': case_runs,
            'test_case_runs_count': len(case_runs),
            'test_case_run_bugs': test_case_run_bugs,
            'mode_stats': mode_stats,
            'summary_stats': summary_stats,
            'report_urls': report_urls,
        })

        return context