Beispiel #1
0
    def add_issue(self, issue_key, case, case_run=None,
                  summary=None, description=None, add_case_to_issue=None):
        """Add new issue

        An issue could be associated with a single case or with a case and
        corresponding case run together.

        :param str issue_key: issue key to add.
        :param case: issue key will be added to this case.
        :type case: :class:`TestCase <tcms.testcases.models.TestCase>`
        :param case_run: optional case run. If passed, issue is associated
            with this case run as well.
        :type case_run: :class:`TestCaseRun <tcms.testruns.models.TestCaseRun>`
        :param str summary: optional summary of this issue.
        :param str description: optional description of this issue.
        :param bool add_case_to_issue: whether to link case to issue tracker's
            external tracker. Defaults to not link test case to the new issue,
            however if it is required, :meth:`link_external_tracker` has to be
            called explicitly.
        :return: the newly created issue.
        :rtype: :class:`Issue <tcms.issuetracker.models.Issue>`
        :raises ValidationError: if fail to validate the new issue.
        """
        issue = Issue(issue_key=issue_key,
                      tracker=self.tracker_model,
                      case=case,
                      case_run=case_run,
                      summary=summary,
                      description=description)
        issue.full_clean()
        issue.save()
        if self.tracker_model.allow_add_case_to_issue and add_case_to_issue:
            self.link_external_tracker(issue)
        return issue
Beispiel #2
0
    def add_issue(self, issue_key, issue_tracker,
                  summary=None, description=None,
                  case_run=None, link_external_tracker=False):
        """Add issue to case or case run

        :param str issue_key: issue key to add.
        :param issue_tracker: to which the issue is added.
        :type issue_tracker: :class:`IssueTracker`
        :param str summary: issue's summary. It's optional.
        :param str description: a longer description for the issue. It's
            optional.
        :param case_run: If specified, that means issue is added to a test case
            run and also associated with this case. If omitted, it just means
            issue is added to this case only.
        :type case_run: :class:`TestCaseRun`
        :param bool link_external_tracker: whether to add the issue to issue
            tracker's external tracker just after issue is added. Default to
            not to do that.
        :return: newly created issue. If issue already exists (checking the
            existence of issue key), nothing changes and just return
            immediately with None.
        :rtype: :class:`Issue`
        :raises ValueError: if passed case run is not associated with this case.

        .. versionchanged:: 4.2
           ``bug_id`` is replaced with ``issue_key``. ``bug_system_id`` is
           replaced with ``issue_tracker``.
        """
        if case_run and case_run.case != self:
            raise ValueError('Case run {} is not associated with case {}'
                             .format(case_run, self))

        existing_issue = Issue.objects.filter(
            issue_key=issue_key, tracker=issue_tracker
        ).only('issue_key').first()
        if existing_issue is not None:
            log.info('Issue %s already exist. Skip add.', issue_key)
            return existing_issue

        issue = Issue(issue_key=issue_key,
                      tracker=issue_tracker,
                      case=self,
                      case_run=case_run,
                      summary=summary,
                      description=description)
        issue.full_clean()
        issue.save()

        if link_external_tracker:
            service = find_service(issue_tracker)
            service.add_external_tracker(issue_key)

        return issue
Beispiel #3
0
def get_issues_s(request, run_id, case_id, build_id, environment_id=0):
    """Get the list of issues that are associated with this test case run

    :param int case_id: case ID.
    :param int run_id: run ID.
    :param int build_id: build ID.
    :param int environment_id: optional environment ID. Defaults to ``0``.
    :return: a list of found :class:`Issue`.
    :rtype: list[dict]

    Example::

        >>> TestCaseRun.get_issues_s(1, 2, 3, 4)
    """
    query = {
        'case_run__run': int(run_id),
        'case_run__build': int(build_id),
        'case_run__case': int(case_id),
    }
    # Just keep the same with original implementation that calls
    # pre_process_tcr_s. In which following logical exists. I don't why this
    # should happen there exactly.
    # FIXME: seems it should be `if environment_id is not None`, otherwise such
    # judgement should not happen.
    if environment_id:
        query['case_run__environment_id'] = int(environment_id)
    return Issue.to_xmlrpc(query)
Beispiel #4
0
def get_issues_s(request, run_id, case_id, build_id, environment_id=0):
    """Get the list of issues that are associated with this test case run

    :param int case_id: case ID.
    :param int run_id: run ID.
    :param int build_id: build ID.
    :param int environment_id: optional environment ID. Defaults to ``0``.
    :return: a list of found :class:`Issue`.
    :rtype: list[dict]

    Example::

        TestCaseRun.get_issues_s(1, 2, 3, 4)
    """
    query = {
        'case_run__run': int(run_id),
        'case_run__build': int(build_id),
        'case_run__case': int(case_id),
    }
    # Just keep the same with original implementation that calls
    # pre_process_tcr_s. In which following logical exists. I don't why this
    # should happen there exactly.
    # FIXME: seems it should be `if environment_id is not None`, otherwise such
    # judgement should not happen.
    if environment_id:
        query['case_run__environment_id'] = int(environment_id)
    return Issue.to_xmlrpc(query)
Beispiel #5
0
    def add_issue(self,
                  issue_key,
                  issue_tracker,
                  summary=None,
                  description=None,
                  case_run=None,
                  link_external_tracker=False):
        """Add issue to case or case run

        :param str issue_key: issue key to add.
        :param issue_tracker: to which the issue is added.
        :type issue_tracker: :class:`IssueTracker`
        :param str summary: issue's summary. It's optional.
        :param str description: a longer description for the issue. It's
            optional.
        :param case_run: If specified, that means issue is added to a test case
            run and also associated with this case. If omitted, it just means
            issue is added to this case only.
        :type case_run: :class:`TestCaseRun`
        :param bool link_external_tracker: whether to add the issue to issue
            tracker's external tracker just after issue is added. Default to
            not to do that.
        :return: newly created issue. If issue already exists (checking the
            existence of issue key), nothing changes and just return
            immediately with None.
        :rtype: :class:`Issue`
        :raises ValueError: if passed case run is not associated with this case.

        .. versionchanged:: 4.2
           ``bug_id`` is replaced with ``issue_key``. ``bug_system_id`` is
           replaced with ``issue_tracker``.
        """
        if case_run and case_run.case != self:
            raise ValueError(
                'Case run {} is not associated with case {}'.format(
                    case_run, self))

        existing_issue = Issue.objects.filter(
            issue_key=issue_key,
            tracker=issue_tracker).only('issue_key').first()
        if existing_issue is not None:
            log.info('Issue %s already exist. Skip add.', issue_key)
            return existing_issue

        issue = Issue(issue_key=issue_key,
                      tracker=issue_tracker,
                      case=self,
                      case_run=case_run,
                      summary=summary,
                      description=description)
        issue.full_clean()
        issue.save()

        if link_external_tracker:
            service = find_service(issue_tracker)
            service.add_external_tracker(issue_key)

        return issue
Beispiel #6
0
        def run_issues_info(self, case_runs):
            """Return a JSON response including run's issues info"""
            return JsonResponse({
                # The total number of issues this run has
                'run_issues_count': self.run.get_issues_count(),

                # The number of issues each of case run has
                'caserun_issues_count': Issue.count_by_case_run(
                    list(map(attrgetter('pk'), case_runs)))
            })
Beispiel #7
0
        def run_issues_info(self, case_runs):
            """Return a JSON response including run's issues info"""
            return JsonResponse({
                # The total number of issues this run has
                'run_issues_count':
                self.run.get_issues_count(),

                # The number of issues each of case run has
                'caserun_issues_count':
                Issue.count_by_case_run(list(map(attrgetter('pk'), case_runs)))
            })
Beispiel #8
0
def get_issues(request, case_run_id):
    """Get the list of issues that are associated with this test case run

    :param int case_run_id: case run ID.
    :return: a list of mappings of :class:`Issue`.
    :rytpe: list[dict]

    Example::

        >>> TestCaseRun.get_issues(10)
    """
    query = {'case_run': int(case_run_id)}
    return Issue.to_xmlrpc(query)
Beispiel #9
0
def get_issues(request, case_run_id):
    """Get the list of issues that are associated with this test case run

    :param int case_run_id: case run ID.
    :return: a list of mappings of :class:`Issue`.
    :rytpe: list[dict]

    Example::

        TestCaseRun.get_issues(10)
    """
    query = {'case_run': int(case_run_id)}
    return Issue.to_xmlrpc(query)
Beispiel #10
0
def get_issues(request, run_ids):
    """Get the list of issues attached to this run.

    :param run_ids: give one or more run IDs. It could be an integer, a
        string containing comma separated IDs, or a list of int each of them is
        a run ID.
    :type run_ids: int, str or list
    :return: a list of mappings of :class:`Issue <tcms.issuetracker.models.Issue>`.
    :rtype: list[dict]

    Example::

        # Get issues belonging to ID 12345
        TestRun.get_issues(1)
        # Get issues belonging to run ids list [1, 2]
        TestRun.get_issues([1, 2])
        # Get issues belonging to run ids list 1 and 2 with string
        TestRun.get_issues('1, 2')
    """
    query = {'case_run__run__in': pre_process_ids(run_ids)}
    return Issue.to_xmlrpc(query)
Beispiel #11
0
def get_issues(request, run_ids):
    """Get the list of issues attached to this run.

    :param run_ids: give one or more run IDs. It could be an integer, a
        string containing comma separated IDs, or a list of int each of them is
        a run ID.
    :type run_ids: int, str or list
    :return: a list of mappings of :class:`Issue <tcms.issuetracker.models.Issue>`.
    :rtype: list[dict]

    Example::

        # Get issues belonging to ID 12345
        >>> TestRun.get_issues(1)
        # Get issues belonging to run ids list [1, 2]
        >>> TestRun.get_issues([1, 2])
        # Get issues belonging to run ids list 1 and 2 with string
        >>> TestRun.get_issues('1, 2')
    """
    query = {'case_run__run__in': pre_process_ids(run_ids)}
    return Issue.to_xmlrpc(query)
Beispiel #12
0
def get_issues(request, case_ids):
    """Get the list of issues that are associated with this test case.

    :param case_ids: give one or more case IDs. It could be an integer, a
        string containing comma separated IDs, or a list of int each of them is
        a case ID.
    :type case_ids: int, str or list
    :return: list of mappings of :class:`Issue`.
    :rtype: list[dict]

    Example::

        # Get issues belonging to case 1
        TestCase.get_issues(1)
        # Get issues belonging to cases [1, 2]
        TestCase.get_issues([1, 2])
        # Get issues belonging to case 1 and 2 with string
        TestCase.get_issues('1, 2')
    """
    case_ids = pre_process_ids(case_ids)
    query = {'case__in': case_ids}
    return Issue.to_xmlrpc(query)
Beispiel #13
0
        :type case: :class:`TestCase <tcms.testcases.models.TestCase>`
        :param case_run: optional case run. If passed, issue is associated
            with this case run as well.
        :type case_run: :class:`TestCaseRun <tcms.testruns.models.TestCaseRun>`
        :param str summary: optional summary of this issue.
        :param str description: optional description of this issue.
        :param bool add_case_to_issue: whether to link case to issue tracker's
            external tracker. Defaults to not link test case to the new issue,
            however if it is required, :meth:`link_external_tracker` has to be
            called explicitly.
        :return: the newly created issue.
        :rtype: :class:`Issue <tcms.issuetracker.models.Issue>`
        :raises ValidationError: if fail to validate the new issue.
        """
        issue = Issue(issue_key=issue_key,
                      tracker=self.tracker_model,
                      case=case,
                      case_run=case_run,
                      summary=summary,
                      description=description)
        issue.full_clean()
        issue.save()
        if self.tracker_model.allow_add_case_to_issue and add_case_to_issue:
            self.link_external_tracker(issue)
        return issue

    def format_issue_report_content(self, build_name, case_text):
        """Format issue report content with a set of information

        This method works with ``IssueTracker.issue_report_templ`` and provides
        a set of information to format issue report content. Please refer to