示例#1
0
    def test_handle_github_message_successful(self,
                                              mock_issue_from_github,
                                              mock_github):
        """
        This function tests 'handle_github_message' where everything goes smoothly!
        """
        # Set up return values
        mock_issue_from_github.return_value = "Successful Call!"
        mock_github.return_value = self.mock_github_client

        # Call function
        response = u.handle_github_message(
            msg=self.mock_github_message,
            config=self.mock_config
        )

        # Assert that calls were made correctly
        mock_issue_from_github.assert_called_with('org/repo',
                                                  {'labels': ['custom_tag'], 'number': 'mock_number',
                                                   'comments': [{'body': 'mock_body', 'name': 'mock_user_login',
                                                                 'author': 'mock_username', 'changed': None,
                                                                 'date_created': 'mock_created_at', 'id': 'mock_id'}],
                                                   'assignees': [{'fullname': 'mock_name'}],
                                                   'filter1': 'filter1', 'user':
                                                       {'login': '******', 'fullname': 'mock_name'},
                                                   'milestone': 'mock_milestone'}, self.mock_config)
        mock_github.assert_called_with('mock_token')
        self.assertEqual('Successful Call!', response)
        self.mock_github_client.get_repo.assert_called_with('org/repo')
        self.mock_github_repo.get_issue.assert_called_with(number='mock_number')
        self.mock_github_issue.get_comments.assert_any_call()
        self.mock_github_client.get_user.assert_called_with('mock_login')
示例#2
0
    def test_handle_github_message_no_comments(self,
                                              mock_issue_from_github,
                                              mock_github):
        """
        This function tests 'handle_github_message' where we have no comments
        """
        # Set up return values
        mock_issue_from_github.return_value = "Successful Call!"
        mock_github.return_value = self.mock_github_client
        self.mock_github_message['msg']['issue']['comments'] = 0

        # Call function
        response = u.handle_github_message(
            msg=self.mock_github_message,
            config=self.mock_config
        )
        # Assert that calls were made correctly
        mock_issue_from_github.assert_called_with('org/repo',
                                                  {'labels': ['custom_tag'], 'number': 'mock_number',
                                                   'comments': [], 'assignees': [{'fullname': 'mock_name'}],
                                                   'filter1': 'filter1',
                                                   'user': {'login': '******', 'fullname': 'mock_name'},
                                                   'milestone': 'mock_milestone'},
                                                  self.mock_config)
        mock_github.assert_called_with('mock_token')
        self.assertEqual('Successful Call!', response)
        self.mock_github_client.get_repo.assert_not_called()
        self.mock_github_repo.get_issue.assert_not_called()
        self.mock_github_issue.get_comments.assert_not_called()
        self.mock_github_client.get_user.assert_called_with('mock_login')
示例#3
0
def handle_message(config, incoming_json):
    # Constantly refresh the config file when we handle a new message
    config = load_config()

    # Ensure we are only dealing with one issue at a time, get our lock
    with lock:
        if ('pull_request' in incoming_json.keys()):
            pr = u_pr.handle_github_message(config, incoming_json)
            if pr:
                d_pr.sync_with_jira(pr, config)
        elif ('issue' in incoming_json.keys()
              and '/pull/' not in incoming_json['issue']['html_url']):
            issue = u_issue.handle_github_message(config, incoming_json)
            if issue:
                d_issue.sync_with_jira(issue, config)
示例#4
0
    def test_handle_github_message_bad_label(self,
                                             mock_issue_from_github):
        """
        This function tests 'handle_github_message' where comparing the actual vs. filter does not equate
        """
        # Set up return values
        self.mock_github_message['msg']['issue']['labels'] = [{'name': 'bad_label'}]

        # Call function
        response = u.handle_github_message(
            msg=self.mock_github_message,
            config=self.mock_config
        )
        # Assert that calls were made correctly
        mock_issue_from_github.assert_not_called()
        self.assertEqual(None, response)
示例#5
0
    def test_handle_github_message_pull_request(self,
                                                mock_issue_from_github,
                                                mock_github):
        """
        This function tests 'handle_github_message' the issue is a pull request comment
        """
        # Set up return values
        self.mock_github_message['msg']['issue'] = {'pull_request': 'test'}

        # Call the function
        response = u.handle_github_message(
            msg=self.mock_github_message,
            config=self.mock_config
        )

        # Assert that all calls were made correctly
        mock_issue_from_github.assert_not_called()
        mock_github.assert_not_called()
        self.assertEqual(None, response)
示例#6
0
    def test_handle_github_message_not_in_mapped(self,
                                                 mock_issue_from_github,
                                                 mock_github):
        """
        This function tests 'handle_github_message' where upstream is not in mapped repos
        """
        # Set up return values
        self.mock_github_message['msg']['repository']['owner']['login'] = '******'

        # Call the function
        response = u.handle_github_message(
            msg=self.mock_github_message,
            config=self.mock_config
        )

        # Assert that all calls were made correctly
        mock_issue_from_github.assert_not_called()
        mock_github.assert_not_called()
        self.assertEqual(None, response)