def test_new_assessment_people(self, client_mock, _):
    """External Issue for Assessment contains correct people."""
    client_instance = client_mock.return_value
    client_instance.create_issue.return_value = {'issueId': 42}

    self.setup_audit_people({
        role_name: people for role_name, people in self.people.items()
        if role_name in ('Audit Captains', 'Auditors')
    })

    component_id = hash('Component id')
    hotlist_id = hash('Hotlist id')
    issue_type = 'Issue type'
    issue_priority = 'Issue priority'
    issue_severity = 'Issue severity'

    asmt = self.create_asmt_with_issue_tracker(
        role_name_to_people={
            role_name: people for role_name, people in self.people.items()
            if role_name in self.ROLE_NAMES
        },
        issue_tracker={
            'component_id': component_id,
            'hotlist_id': hotlist_id,
            'issue_type': issue_type,
            'issue_priority': issue_priority,
            'issue_severity': issue_severity,
        },
    )

    expected_cc_list = list(
        self.EMAILS["Assessment", "Assignees"] -
        {min(self.EMAILS["Assessment", "Assignees"])}
    )

    # pylint: disable=protected-access; we assert by non-exported constants
    client_instance.create_issue.assert_called_once_with({
        # common fields
        'comment': (assessment_integration._INITIAL_COMMENT_TMPL %
                    assessment_integration._get_assessment_url(asmt)),
        'component_id': component_id,
        'hotlist_ids': [hotlist_id],
        'priority': issue_priority,
        'severity': issue_severity,
        'status': 'ASSIGNED',
        'title': asmt.title,
        'type': issue_type,

        # person-related fields
        'reporter': min(self.EMAILS["Audit", "Audit Captains"]),
        'assignee': min(self.EMAILS["Assessment", "Assignees"]),
        'verifier': min(self.EMAILS["Assessment", "Assignees"]),
        'ccs': expected_cc_list,
    })
Exemple #2
0
  def test_new_assessment_people(self, client_mock, _):
    """External Issue for Assessment contains correct people."""
    client_instance = client_mock.return_value
    client_instance.create_issue.return_value = {'issueId': 42}

    self.setup_audit_people({
        role_name: people for role_name, people in self.people.items()
        if role_name in ('Audit Captains', 'Auditors')
    })

    component_id = hash('Component id')
    hotlist_id = hash('Hotlist id')
    issue_type = 'Issue type'
    issue_priority = 'Issue priority'
    issue_severity = 'Issue severity'

    asmt = self.create_asmt_with_issue_tracker(
        role_name_to_people={
            role_name: people for role_name, people in self.people.items()
            if role_name in self.ROLE_NAMES
        },
        issue_tracker={
            'component_id': component_id,
            'hotlist_id': hotlist_id,
            'issue_type': issue_type,
            'issue_priority': issue_priority,
            'issue_severity': issue_severity,
        },
    )

    expected_cc_list = list(
        self.EMAILS["Assessment", "Assignees"] -
        {min(self.EMAILS["Assessment", "Assignees"])}
    )

    # pylint: disable=protected-access; we assert by non-exported constants
    client_instance.create_issue.assert_called_once_with({
        # common fields
        'comment': (assessment_integration._INITIAL_COMMENT_TMPL %
                    assessment_integration._get_assessment_url(asmt)),
        'component_id': component_id,
        'hotlist_ids': [hotlist_id],
        'priority': issue_priority,
        'severity': issue_severity,
        'status': 'ASSIGNED',
        'title': asmt.title,
        'type': issue_type,

        # person-related fields
        'reporter': min(self.EMAILS["Audit", "Audit Captains"]),
        'assignee': min(self.EMAILS["Assessment", "Assignees"]),
        'verifier': min(self.EMAILS["Assessment", "Assignees"]),
        'ccs': expected_cc_list,
    })
Exemple #3
0
    def test_change_assessment_status(self, status, additional_kwargs,
                                      mocked_update_issue):
        """Issue status should be changed for assessment
    with {status} status."""
        email1 = "*****@*****.**"
        assignee_role_id = AccessControlRole.query.filter_by(
            object_type="Assessment", name="Assignees").first().id
        assignees = [factories.PersonFactory(email=email1)]
        iti_issue_id = []
        iti = factories.IssueTrackerIssueFactory(enabled=True)
        iti_issue_id.append(iti.issue_id)
        asmt = iti.issue_tracked_obj
        asmt_title = asmt.title
        with mock.patch.object(assessment_integration,
                               '_is_issue_tracker_enabled',
                               return_value=True):
            acl = [
                acl_helper.get_acl_json(assignee_role_id, assignee.id)
                for assignee in assignees
            ]
            self.api.put(asmt, {
                "access_control_list": acl,
                "status": status,
            })
            kwargs = {
                'component_id': None,
                'severity': None,
                'title': asmt_title,
                'hotlist_ids': [],
                'priority': None,
                'assignee': email1,
                'verifier': email1,
                'ccs': []
            }
            asmt_link = assessment_integration._get_assessment_url(asmt)
            if 'comment' in additional_kwargs:
                additional_kwargs['comment'] = \
                    additional_kwargs['comment'] % (status, asmt_link)
            kwargs.update(additional_kwargs)
            mocked_update_issue.assert_called_once_with(
                iti_issue_id[0], kwargs)

            issue = db.session.query(models.IssuetrackerIssue).get(iti.id)
            self.assertEqual(issue.assignee, email1)
            self.assertEqual(issue.cc_list, "")
  def test_change_assessment_status(self, status,
                                    additional_kwargs,
                                    mocked_update_issue):
    """Issue status should be changed for assessment
    with {status} status."""
    email1 = "*****@*****.**"
    assignee_role_id = AccessControlRole.query.filter_by(
        object_type="Assessment",
        name="Assignees"
    ).first().id
    assignees = [factories.PersonFactory(email=email1)]
    iti_issue_id = []
    iti = factories.IssueTrackerIssueFactory(enabled=True)
    iti_issue_id.append(iti.issue_id)
    asmt = iti.issue_tracked_obj
    asmt_title = asmt.title
    with mock.patch.object(assessment_integration, '_is_issue_tracker_enabled',
                           return_value=True):
      acl = [acl_helper.get_acl_json(assignee_role_id, assignee.id)
             for assignee in assignees]
      self.api.put(asmt, {
          "access_control_list": acl,
          "status": status,
      })
      kwargs = {'component_id': None,
                'severity': None,
                'title': asmt_title,
                'hotlist_ids': [],
                'priority': None,
                'assignee': email1,
                'verifier': email1,
                'ccs': []}
      asmt_link = assessment_integration._get_assessment_url(asmt)
      if 'comment' in additional_kwargs:
        additional_kwargs['comment'] = \
            additional_kwargs['comment'] % (status, asmt_link)
      kwargs.update(additional_kwargs)
      mocked_update_issue.assert_called_once_with(iti_issue_id[0], kwargs)

      issue = db.session.query(models.IssuetrackerIssue).get(iti.id)
      self.assertEqual(issue.assignee, email1)
      self.assertEqual(issue.cc_list, "")
 def test_adding_comment_to_assessment(self, desc, mocked_update_issue):
     """Test adding comment with blank lines in the end."""
     with mock.patch.object(assessment_integration,
                            '_is_issue_tracker_enabled',
                            return_value=True):
         iti_issue_id = []
         iti = factories.IssueTrackerIssueFactory(enabled=True)
         iti_issue_id.append(iti.issue_id)
         asmt = iti.issue_tracked_obj
         comment = factories.CommentFactory(description=desc)
         self.api.put(
             asmt, {
                 "actions": {
                     "add_related": [{
                         "id": comment.id,
                         "type": "Comment"
                     }]
                 },
             })
     asmt = db.session.query(models.Assessment).get(asmt.id)
     builder_class = params_builder.BaseIssueTrackerParamsBuilder
     expected_comment = builder_class.COMMENT_TMPL.format(
         author=None,
         comment="test comment",
         model="Assessment",
         link=assessment_integration._get_assessment_url(asmt),
     )
     kwargs = {
         'status': 'ASSIGNED',
         'component_id': None,
         'severity': None,
         'title': asmt.title,
         'hotlist_ids': [],
         'priority': None,
         'comment': expected_comment
     }
     mocked_update_issue.assert_called_once_with(iti_issue_id[0], kwargs)