Exemple #1
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
Exemple #2
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