示例#1
0
    def test_non_ascii_pr_title(self, jira_mock):
        helper = JiraHelper()

        payload = mock_pull_request_payload()
        payload['pull_request']['title'] = 'Standard title'
        helper.comment_issue('PROJ-42', payload)
        jira_mock.return_value.add_comment.assert_called_with('PROJ-42', ANY)

        payload = mock_pull_request_payload()
        payload['pull_request']['title'] = u'Non-ASCII \u2018title\u2019'
        helper.comment_issue('PROJ-42', payload)
        jira_mock.return_value.add_comment.assert_called_with('PROJ-42', ANY)
    def test_non_ascii_pr_title(self, jira_mock):
        helper = JiraHelper()

        payload = mock_pull_request_payload()
        payload['pull_request']['title'] = 'Standard title'
        helper.comment_issue('PROJ-42', payload)
        jira_mock.return_value.add_comment.assert_called_with('PROJ-42', ANY)

        payload = mock_pull_request_payload()
        payload['pull_request']['title'] = u'Non-ASCII \u2018title\u2019'
        helper.comment_issue('PROJ-42', payload)
        jira_mock.return_value.add_comment.assert_called_with('PROJ-42', ANY)
示例#3
0
    def test_trybot_payload(self, mock_requests_get, mock_requests_post):
        get_response = mock.Mock()
        get_response.status_code = 200
        get_response.text = '+++ some/file\n--- some/file\n+ new line\n'
        get_response.json.return_value = {'id': 3}
        mock_requests_get.return_value = get_response

        # One mock for each requests.post() call in the handler.
        post_response_comment = mock.Mock()
        post_response_comment.json.return_value = {'id': 1234}
        post_response_send_to_trybot = mock.Mock()

        mock_requests_post.side_effects = (post_response_comment,
                                           post_response_send_to_trybot)

        payload = mock_pull_request_payload()
        payload['pull_request']['base']['ref'] = 'crosswalk-4'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 0)
        self.assertEqual(mock_requests_get.call_count, 0)
        self.assertEqual(mock_requests_post.call_count, 0)

        payload = mock_pull_request_payload()
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 1)
        self.assertEqual(mock_requests_post.call_count, 3)
        payload = mock_requests_post.call_args[1]['data']
        expected_payload = {
            'user': u'rakuco',
            'name': u'Hello world',
            'email': '*****@*****.**',
            'revision': u'deadbeef',
            'project': u'crosswalk',
            'repository': u'crosswalk',
            'branch': u'master',
            'patch': '+++ some/file\n--- some/file\n+ new line\n',
            'issue': PullRequest.objects.get(pk=1).pk
        }
        self.assertEqual(payload, expected_payload)

        # FIXME(rakuco): Remove this part of the test once the 'crosswalk-lite'
        # hackish check is removed from handlers.py.
        payload = mock_pull_request_payload()
        payload['pull_request']['base']['ref'] = 'crosswalk-lite'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 2)
        self.assertEqual(mock_requests_post.call_count, 6)
        payload = mock_pull_request_payload()
        payload['pull_request']['base']['repo']['name'] = 'v8-crosswalk'
        payload['pull_request']['base']['ref'] = 'crosswalk-lite'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 2)
        self.assertEqual(mock_requests_post.call_count, 6)
    def test_trybot_payload(self, mock_requests_get, mock_requests_post):
        get_response = mock.Mock()
        get_response.status_code = 200
        get_response.text = '+++ some/file\n--- some/file\n+ new line\n'
        get_response.json.return_value = {'id': 3}
        mock_requests_get.return_value = get_response

        # One mock for each requests.post() call in the handler.
        post_response_comment = mock.Mock()
        post_response_comment.json.return_value = {'id': 1234}
        post_response_send_to_trybot = mock.Mock()

        mock_requests_post.side_effects = (post_response_comment,
                                           post_response_send_to_trybot)

        payload = mock_pull_request_payload()
        payload['pull_request']['base']['ref'] = 'crosswalk-4'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 0)
        self.assertEqual(mock_requests_get.call_count, 0)
        self.assertEqual(mock_requests_post.call_count, 0)

        payload = mock_pull_request_payload()
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 1)
        self.assertEqual(mock_requests_post.call_count, 3)
        payload = mock_requests_post.call_args[1]['data']
        expected_payload = {'user': u'rakuco',
                            'name': u'Hello world',
                            'email': '*****@*****.**',
                            'revision': u'deadbeef',
                            'project': u'crosswalk',
                            'repository': u'crosswalk',
                            'branch': u'master',
                            'patch': '+++ some/file\n--- some/file\n+ new line\n',
                            'issue': PullRequest.objects.get(pk=1).pk}
        self.assertEqual(payload, expected_payload)

        # FIXME(rakuco): Remove this part of the test once the 'crosswalk-lite'
        # hackish check is removed from handlers.py.
        payload = mock_pull_request_payload()
        payload['pull_request']['base']['ref'] = 'crosswalk-lite'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 2)
        self.assertEqual(mock_requests_post.call_count, 6)
        payload = mock_pull_request_payload()
        payload['pull_request']['base']['repo']['name'] = 'v8-crosswalk'
        payload['pull_request']['base']['ref'] = 'crosswalk-lite'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 2)
        self.assertEqual(mock_requests_post.call_count, 6)
    def test_success(self, mock_requests_get, mock_requests_post):
        payload = mock_pull_request_payload()

        get_response = mock.Mock()
        get_response.status_code = 200
        get_response.text = '+++ some/file\n--- some/file\n+ new line\n'
        get_response.json.return_value = {'id': 3}
        mock_requests_get.return_value = get_response
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 1)
        pr = PullRequest.objects.get(pk=1)
        self.assertEqual(pr.number, 42)
        self.assertEqual(pr.head_sha, 'deadbeef')
        self.assertEqual(pr.base_repo_path, 'crosswalk-project/crosswalk')
        self.assertEqual(pr.head_repo_path, 'rakuco/crosswalk-fork')
        self.assertEqual(pr.status, STATUS_PENDING)
        self.assertEqual(pr.needs_sync, True)

        payload['action'] = 'synchronize'
        payload['pull_request']['head']['sha'] = 'f00b4r'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 2)
        pr = PullRequest.objects.get(pk=2)
        self.assertEqual(pr.number, 42)
        self.assertEqual(pr.head_sha, 'f00b4r')
        self.assertEqual(pr.base_repo_path, 'crosswalk-project/crosswalk')
        self.assertEqual(pr.head_repo_path, 'rakuco/crosswalk-fork')
        self.assertEqual(pr.status, STATUS_PENDING)
        self.assertEqual(pr.needs_sync, True)
示例#6
0
    def test_success(self, mock_requests_get, mock_requests_post):
        payload = mock_pull_request_payload()

        get_response = mock.Mock()
        get_response.status_code = 200
        get_response.text = '+++ some/file\n--- some/file\n+ new line\n'
        get_response.json.return_value = {'id': 3}
        mock_requests_get.return_value = get_response
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 1)
        pr = PullRequest.objects.get(pk=1)
        self.assertEqual(pr.number, 42)
        self.assertEqual(pr.head_sha, 'deadbeef')
        self.assertEqual(pr.base_repo_path, 'crosswalk-project/crosswalk')
        self.assertEqual(pr.head_repo_path, 'rakuco/crosswalk-fork')
        self.assertEqual(pr.status, STATUS_PENDING)
        self.assertEqual(pr.needs_sync, True)

        payload['action'] = 'synchronize'
        payload['pull_request']['head']['sha'] = 'f00b4r'
        response = self.client.post(self.url, payload)
        self.assertEqual(PullRequest.objects.count(), 2)
        pr = PullRequest.objects.get(pk=2)
        self.assertEqual(pr.number, 42)
        self.assertEqual(pr.head_sha, 'f00b4r')
        self.assertEqual(pr.base_repo_path, 'crosswalk-project/crosswalk')
        self.assertEqual(pr.head_repo_path, 'rakuco/crosswalk-fork')
        self.assertEqual(pr.status, STATUS_PENDING)
        self.assertEqual(pr.needs_sync, True)
示例#7
0
 def test_comment_issue(self, jira_mock):
     payload = mock_pull_request_payload()
     payload['pull_request']['body'] = \
         'This PR will resolve the issue'\
         'mentioned below:'\
         '\n'\
         'BUG=https://crosswalk-project.org/jira/bug=PROJ-2'
     response = self.client.post(self.url, payload)
     jira_mock.return_value.add_comment.assert_called_with('PROJ-2', ANY)
 def test_comment_issue(self, jira_mock):
     payload = mock_pull_request_payload()
     payload['pull_request']['body'] = \
         'This PR will resolve the issue'\
         'mentioned below:'\
         '\n'\
         'BUG=https://crosswalk-project.org/jira/bug=PROJ-2'
     response = self.client.post(self.url, payload)
     jira_mock.return_value.add_comment.assert_called_with('PROJ-2', ANY)
    def test_patch_fetch_error(self, mock_requests_get):
        payload = mock_pull_request_payload()

        mock_response = mock.Mock()
        mock_response.status_code = 404
        mock_requests_get.return_value = mock_response
        response = self.client.post(self.url, payload)
        self.assertEqual(response.status_code, 500)
        self.assertEqual(PullRequest.objects.count(), 0)
示例#10
0
    def test_patch_fetch_error(self, mock_requests_get):
        payload = mock_pull_request_payload()

        mock_response = mock.Mock()
        mock_response.status_code = 404
        mock_requests_get.return_value = mock_response
        response = self.client.post(self.url, payload)
        self.assertEqual(response.status_code, 500)
        self.assertEqual(PullRequest.objects.count(), 0)
示例#11
0
    def test_no_issue(self, jira_mock):
        payload = mock_pull_request_payload()

        payload['pull_request']['body'] = 'This PR does not fix any issue'
        response = self.client.post(self.url, payload)
        self.assertEqual(jira_mock.called, False)

        payload['pull_request']['body'] = None
        response = self.client.post(self.url, payload)
        self.assertEqual(jira_mock.called, False)
    def test_no_issue(self, jira_mock):
        payload = mock_pull_request_payload()

        payload['pull_request']['body'] = 'This PR does not fix any issue'
        response = self.client.post(self.url, payload)
        self.assertEqual(jira_mock.called, False)

        payload['pull_request']['body'] = None
        response = self.client.post(self.url, payload)
        self.assertEqual(jira_mock.called, False)
示例#13
0
    def test_resolve_issue(self, jira_mock):
        payload = mock_pull_request_payload()
        payload['action'] = 'closed'
        payload['pull_request']['body'] = \
            'This PR will close the issue'\
            'mentioned below:'\
            '\n'\
            'BUG=https://crosswalk-project.org/jira/bug=PROJ-2'
        payload['pull_request']['merged'] = True

        issue_mock = Mock()
        jira_mock.return_value.issue.return_value = issue_mock
        jira_mock.return_value.transitions.return_value = (
            {
                'id': '1',
                'name': 'Triage'
            },
            {
                'id': '2',
                'name': 'Resolve'
            },
        )
        response = self.client.post(self.url, payload)
        jira_mock.return_value.issue.assert_called_with('PROJ-2')
        jira_mock.return_value.transition_issue.assert_called_with(
            issue_mock,
            '2',
            comment=ANY,
            resolution={'id': settings.JIRA_RESOLUTION_FIXED_ID})
        self.assertEqual(jira_mock.return_value.transitions.call_count, 1)
        self.assertEqual(jira_mock.return_value.add_comment.call_count, 0)
        self.assertEqual(jira_mock.return_value.transition_issue.call_count, 1)

        issue_mock = Mock()
        jira_mock.return_value.issue.return_value = issue_mock
        jira_mock.return_value.transitions.return_value = (
            {
                'id': '1',
                'name': 'Triage'
            },
            {
                'id': '2',
                'name': 'Close'
            },
            {
                'id': '5',
                'name': 'New'
            },
        )
        response = self.client.post(self.url, payload)
        self.assertEqual(jira_mock.return_value.transitions.call_count, 2)
        self.assertEqual(jira_mock.return_value.add_comment.call_count, 0)
        self.assertEqual(jira_mock.return_value.transition_issue.call_count, 1)
    def test_ignored_action(self):
        payload = mock_pull_request_payload()

        payload['action'] = 'closed'
        response = self.client.post(self.url, payload)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(PullRequest.objects.count(), 0)

        payload['action'] = 'reopened'
        response = self.client.post(self.url, payload)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(PullRequest.objects.count(), 0)
示例#15
0
    def test_ignored_action(self):
        payload = mock_pull_request_payload()

        payload['action'] = 'closed'
        response = self.client.post(self.url, payload)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(PullRequest.objects.count(), 0)

        payload['action'] = 'reopened'
        response = self.client.post(self.url, payload)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(PullRequest.objects.count(), 0)
    def test_resolve_issue(self, jira_mock):
        payload = mock_pull_request_payload()
        payload['action'] = 'closed'
        payload['pull_request']['body'] = \
            'This PR will close the issue'\
            'mentioned below:'\
            '\n'\
            'BUG=https://crosswalk-project.org/jira/bug=PROJ-2'
        payload['pull_request']['merged'] = True

        issue_mock = Mock()
        jira_mock.return_value.issue.return_value = issue_mock
        jira_mock.return_value.transitions.return_value = (
            {'id': '1', 'name': 'Triage'},
            {'id': '2', 'name': 'Resolve'},
        )
        response = self.client.post(self.url, payload)
        jira_mock.return_value.issue.assert_called_with('PROJ-2')
        jira_mock.return_value.transition_issue.assert_called_with(
            issue_mock,
            '2',
            comment=ANY,
            resolution={'id': settings.JIRA_RESOLUTION_FIXED_ID}
            )
        self.assertEqual(jira_mock.return_value.transitions.call_count, 1)
        self.assertEqual(jira_mock.return_value.add_comment.call_count, 0)
        self.assertEqual(jira_mock.return_value.transition_issue.call_count, 1)

        issue_mock = Mock()
        jira_mock.return_value.issue.return_value = issue_mock
        jira_mock.return_value.transitions.return_value = (
            {'id': '1', 'name': 'Triage'},
            {'id': '2', 'name': 'Close'},
            {'id': '5', 'name': 'New'},
        )
        response = self.client.post(self.url, payload)
        self.assertEqual(jira_mock.return_value.transitions.call_count, 2)
        self.assertEqual(jira_mock.return_value.add_comment.call_count, 0)
        self.assertEqual(jira_mock.return_value.transition_issue.call_count, 1)