Exemplo n.º 1
0
def test_register_hook(http):
    response = Response()
    response._content = '[]'
    http.return_value = response

    gh = Github()
    gh.repos.hooks.create = Mock()
    url = 'http://example.com/review/start'

    github.register_hook(gh, url, 'mark', 'lint-test')

    assert gh.repos.hooks.create.called, 'Create not called'
    calls = gh.repos.hooks.create.call_args_list
    expected = call(
        {
            'name': 'web',
            'active': True,
            'config': {
                'content_type': 'json',
                'url': url,
            },
            'events': ['pull_request']
        },
        user='******',
        repo='lint-test')
    eq_(calls[0], expected)
Exemplo n.º 2
0
def test_register_hook__already_exists():
    repo = Mock(spec=github3.repos.repo.Repository,
                full_name='mark/lint-review')
    repo.hooks.return_value = [github3.repos.hook.Hook(f) for f in json.loads(load_fixture('webhook_list.json'))]
    url = 'http://example.com/review/start'

    github.register_hook(repo, url)
    assert repo.create_hook.called is False, 'Create called'
Exemplo n.º 3
0
    def test_register_hook__already_exists(self):
        repo = Mock(spec=Repository, full_name='mark/lint-review')
        repo.hooks.return_value = [
            Hook(f, session)
            for f in json.loads(load_fixture('webhook_list.json'))
        ]
        url = 'http://example.com/review/start'

        github.register_hook(repo, url)
        assert repo.create_hook.called is False, 'Create called'
Exemplo n.º 4
0
def test_register_hook__already_exists():
    repo = Mock(spec=github3.repos.repo.Repository,
                full_name='mark/lint-review')
    repo.hooks.return_value = map(
        lambda f: github3.repos.hook.Hook(f),
        json.loads(load_fixture('webhook_list.json')))
    url = 'http://example.com/review/start'

    github.register_hook(repo, url)
    assert repo.create_hook.called is False, 'Create called'
Exemplo n.º 5
0
def test_register_hook__already_exists(http):
    response = Response()
    response._content = load_fixture('webhook_list.json')
    http.return_value = response

    gh = Github()
    gh.repos.hooks.create = Mock()
    url = 'http://example.com/review/start'

    github.register_hook(gh, url, 'mark', 'lint-test')

    assert gh.repos.hooks.create.called is False, 'Create called'
Exemplo n.º 6
0
def test_register_hook__already_exists(http):
    response = Response()
    response._content = load_fixture('webhook_list.json')
    http.return_value = response

    gh = Github()
    gh.repos.hooks.create = Mock()
    url = 'http://example.com/review/start'

    github.register_hook(gh, url, 'mark', 'lint-test')

    assert gh.repos.hooks.create.called is False, 'Create called'
Exemplo n.º 7
0
    def test_register_hook_logs_message_on_failure(self):
        repo = Mock(spec=Repository,
                    full_name='mark/lint-review')
        repo.hooks.return_value = []

        repo.create_hook.side_effect = Exception('uh oh')
        fake_logger = Mock()

        with self.assertRaises(Exception), patch('lintreview.github.log', fake_logger):
            url = 'http://example.com/review/start'
            github.register_hook(repo, url)

        fake_logger.error.assert_called_with(
            "Unable to save webhook. You need to have administration "
            "privileges over the repository to add webhooks."
        )
Exemplo n.º 8
0
    def test_register_hook(self):
        repo = Mock(spec=Repository, full_name='mark/lint-review')
        repo.hooks.return_value = []

        url = 'http://example.com/review/start'
        github.register_hook(repo, url)

        assert repo.create_hook.called, 'Create not called'
        calls = repo.create_hook.call_args_list
        expected = call(name='web',
                        active=True,
                        config={
                            'content_type': 'json',
                            'url': url,
                        },
                        events=['pull_request'])
        self.assertEqual(calls[0], expected)
Exemplo n.º 9
0
def test_register_hook():
    repo = Mock(spec=github3.repos.repo.Repository,
                full_name='mark/lint-review')
    repo.hooks.return_value = []

    url = 'http://example.com/review/start'
    github.register_hook(repo, url)

    assert repo.create_hook.called, 'Create not called'
    calls = repo.create_hook.call_args_list
    expected = call(
        name='web',
        active=True,
        config={
            'content_type': 'json',
            'url': url,
        },
        events=['pull_request']
    )
    eq_(calls[0], expected)
Exemplo n.º 10
0
def test_register_hook(http):
    response = Response()
    response._content = '[]'
    http.return_value = response

    gh = Github()
    gh.repos.hooks.create = Mock()
    url = 'http://example.com/review/start'

    github.register_hook(gh, url, 'mark', 'lint-test')

    assert gh.repos.hooks.create.called, 'Create not called'
    calls = gh.repos.hooks.create.call_args_list
    expected = call({
        'name': 'web',
        'active': True,
        'config': {
            'content_type': 'json',
            'url': url,
        },
        'events': ['pull_request']
    }, user='******', repo='lint-test')
    eq_(calls[0], expected)