示例#1
0
    def test_author_not_commenter_is_collaborator(self):
        payload = fakes.Payload.new_comment()
        payload._payload['issue']['user']['login'] = '******'

        handler = newpr.HighfiveHandler(payload, dummy_config())
        api_req_mock = ApiReqMocker([
            (
                (
                    "GET",
                    newpr.user_collabo_url % (
                        'rust-lang', 'rust', 'davidalber'
                    ),
                    None
                ),
                {'body': {}},
            ),
            (
                (
                    'PATCH', newpr.issue_url % ('rust-lang', 'rust', '1'),
                    {'assignee': 'davidalber'}
                ),
                {'body': {}},
            ),
        ])
        handler.new_comment()
        api_req_mock.verify_calls()
示例#2
0
    def __init__(self,
                 payload,
                 integration_user='******',
                 integration_token='integrationToken',
                 repo_config={}):
        assert (type(payload) == Payload)
        self.integration_user = integration_user
        self.integration_token = integration_token

        self.patchers_stopped = False

        with responses.RequestsMock() as resp:
            resp.add(
                responses.GET,
                'https://api.github.com/user',
                json={'login': integration_user},
            )
            if integration_token:
                config = Config(integration_token)
            else:
                config = Config('dummy')
                config.github_token = ''

        self.config_patcher = mock.patch('highfive.newpr.ConfigParser')

        self.load_repo_config_patcher = mock.patch(
            'highfive.newpr.HighfiveHandler.load_repo_config')
        self.mock_load_repo_config = self.load_repo_config_patcher.start()
        self.mock_load_repo_config.return_value = repo_config

        self.handler = newpr.HighfiveHandler(payload, config)
示例#3
0
    def __init__(
        self, payload, integration_user='******',
        integration_token='integrationToken', repo_config={}
    ):
        assert(type(payload) == Payload)
        self.integration_user = integration_user
        self.integration_token = integration_token

        def config_handler(section, key):
            if section == 'github':
                if key == 'user':
                    return integration_user
                if key == 'token':
                    return integration_token

        self.patchers_stopped = False
        self.config_patcher = mock.patch('highfive.newpr.ConfigParser')
        self.mock_config_parser = self.config_patcher.start()
        self.mock_config = mock.Mock()
        self.mock_config.get.side_effect = config_handler
        self.mock_config_parser.RawConfigParser.return_value = self.mock_config

        self.load_repo_config_patcher = mock.patch(
            'highfive.newpr.HighfiveHandler.load_repo_config'
        )
        self.mock_load_repo_config = self.load_repo_config_patcher.start()
        self.mock_load_repo_config.return_value = repo_config

        self.handler = newpr.HighfiveHandler(payload)
    def test_new_pr_contributor_with_labels(self):
        self.mocks['load_json_file'].side_effect = (
            fakes.get_repo_configs()['individuals_no_dirs_labels'],
            fakes.get_global_configs()['base'],
        )
        payload = fakes.Payload.new_pr(repo_owner='rust-lang',
                                       repo_name='rust',
                                       pr_author='pnkfelix')
        handler = newpr.HighfiveHandler(payload, dummy_config())

        api_req_mock = ApiReqMocker([
            (
                ('GET', 'https://the.url/', None,
                 'application/vnd.github.v3.diff'),
                {
                    'body': fakes.load_fake('normal.diff')
                },
            ),
            (
                ('PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), {
                    'assignee': 'nrc'
                }),
                {
                    'body': {}
                },
            ),
            (
                ('GET',
                 newpr.commit_search_url % ('rust-lang', 'rust', 'pnkfelix'),
                 None, 'application/vnd.github.cloak-preview'),
                {
                    'body': '{"total_count": 1}'
                },
            ),
            (
                ('POST', newpr.post_comment_url % ('rust-lang', 'rust', '7'), {
                    'body':
                    'r? @nrc\n\n(rust_highfive has picked a reviewer for you, use r? to override)'
                }),
                {
                    'body': {}
                },
            ),
            (
                ('POST', newpr.issue_labels_url % ('rust-lang', 'rust', '7'),
                 ['a', 'b']),
                {
                    'body': {}
                },
            ),
        ])
        handler.new_pr()

        api_req_mock.verify_calls()
示例#5
0
 def test_author_is_commenter(self):
     payload = fakes.Payload.new_comment()
     handler = newpr.HighfiveHandler(payload, dummy_config())
     api_req_mock = ApiReqMocker([
         (
             (
                 'PATCH', newpr.issue_url % ('rust-lang', 'rust', '1'),
                 {'assignee': 'davidalber'}
             ),
             {'body': {}},
         ),
     ])
     handler.new_comment()
     api_req_mock.verify_calls()
    def test_new_pr_empty_body(self):
        payload = fakes.Payload.new_pr(
            repo_owner='rust-lang',
            repo_name='rust',
            pr_author='pnkfelix',
            pr_body=None,
        )
        handler = newpr.HighfiveHandler(payload, dummy_config())

        api_req_mock = ApiReqMocker([
            (
                ('GET', 'https://the.url/', None,
                 'application/vnd.github.v3.diff'),
                {
                    'body': fakes.load_fake('normal.diff')
                },
            ),
            (
                ('PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), {
                    'assignee': 'nrc'
                }),
                {
                    'body': {}
                },
            ),
            (
                ('GET',
                 newpr.commit_search_url % ('rust-lang', 'rust', 'pnkfelix'),
                 None, 'application/vnd.github.cloak-preview'),
                {
                    'body': '{"total_count": 0}'
                },
            ),
            (
                ('POST', newpr.post_comment_url % ('rust-lang', 'rust', '7'), {
                    'body':
                    "Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (or someone else) soon.\n\nIf any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.\n\nPlease see [the contribution instructions](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md) for more information.\n"
                }),
                {
                    'body': {}
                },
            ),
        ])
        handler.new_pr()

        api_req_mock.verify_calls()
示例#7
0
    def test_new_pr_empty_body(self):
        payload = fakes.Payload.new_pr(
            repo_owner='rust-lang',
            repo_name='rust',
            pr_author='pnkfelix',
            pr_body=None,
        )
        handler = newpr.HighfiveHandler(payload, dummy_config())

        api_req_mock = ApiReqMocker([
            (
                ('GET', 'https://the.url/', None,
                 'application/vnd.github.v3.diff'),
                {
                    'body': fakes.load_fake('normal.diff')
                },
            ),
            (
                ('PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), {
                    'assignee': 'nrc'
                }),
                {
                    'body': {}
                },
            ),
            (
                ('GET',
                 newpr.commit_search_url % ('rust-lang', 'rust', 'pnkfelix'),
                 None, 'application/vnd.github.cloak-preview'),
                {
                    'body': '{"total_count": 0}'
                },
            ),
            (
                ('POST', newpr.post_comment_url % ('rust-lang', 'rust', '7'), {
                    'body':
                    "Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nrc (or someone else) soon.\n\nPlease see [the contribution instructions](https://rustc-dev-guide.rust-lang.org/contributing.html) for more information.\n"
                }),
                {
                    'body': {}
                },
            ),
        ])
        handler.new_pr()

        api_req_mock.verify_calls()
    def test_new_pr_contributor(self):
        payload = fakes.Payload.new_pr(repo_owner='rust-lang',
                                       repo_name='rust',
                                       pr_author='pnkfelix')
        handler = newpr.HighfiveHandler(payload, dummy_config())

        api_req_mock = ApiReqMocker([
            (
                ('GET', 'https://the.url/', None,
                 'application/vnd.github.v3.diff'),
                {
                    'body': fakes.load_fake('normal.diff')
                },
            ),
            (
                ('PATCH', newpr.issue_url % ('rust-lang', 'rust', '7'), {
                    'assignee': 'nrc'
                }),
                {
                    'body': {}
                },
            ),
            (
                ('GET',
                 newpr.commit_search_url % ('rust-lang', 'rust', 'pnkfelix'),
                 None, 'application/vnd.github.cloak-preview'),
                {
                    'body': '{"total_count": 1}'
                },
            ),
            (
                ('POST', newpr.post_comment_url % ('rust-lang', 'rust', '7'), {
                    'body':
                    'r? @nrc\n\n(rust_highfive has picked a reviewer for you, use r? to override)'
                }),
                {
                    'body': {}
                },
            ),
        ])
        handler.new_pr()

        api_req_mock.verify_calls()