def test_unregister_hook__success(): repo = Mock(spec=github3.repos.repo.Repository, full_name='mark/lint-review') hooks = [github3.repos.hook.Hook(f) for f in json.loads(load_fixture('webhook_list.json'))] repo.hooks.return_value = hooks url = 'http://example.com/review/start' github.unregister_hook(repo, url) assert repo.hook().delete.called, 'Delete not called'
def test_unregister_hook__success(): repo = Mock(spec=github3.repos.repo.Repository, full_name='mark/lint-review') hooks = map(lambda f: github3.repos.hook.Hook(f), json.loads(load_fixture('webhook_list.json'))) repo.hooks.return_value = hooks url = 'http://example.com/review/start' github.unregister_hook(repo, url) assert repo.hook().delete.called, 'Delete not called'
def test_unregister_hook__success(self): repo = Mock(spec=Repository, full_name='mark/lint-review') repo.hooks.return_value = [ github3.repos.hook.Hook(f, session) for f in json.loads(load_fixture('webhook_list.json')) ] url = 'http://example.com/review/start' github.unregister_hook(repo, url) assert repo.hook().delete.called, 'Delete not called'
def test_unregister_hook__success(http): response = Response() response._content = load_fixture('webhook_list.json') http.return_value = response gh = Github() gh.repos.hooks.delete = Mock() url = 'http://example.com/review/start' github.unregister_hook(gh, url, 'mark', 'lint-test') assert gh.repos.hooks.delete.called, 'Delete not called'
def test_unregister_hook__not_there(): repo = Mock(spec=github3.repos.repo.Repository, full_name='mark/lint-review') repo.hooks.return_value = [] url = 'http://example.com/review/start' try: github.unregister_hook(repo, url) assert False, 'No exception' except: assert True, 'Exception raised' assert repo.hook().delete.called is False, 'Delete called'
def test_unregister_hook__not_there(http): response = Response() response._content = "[]" http.return_value = response gh = Github() gh.repos.hooks.delete = Mock() url = 'http://example.com/review/start' try: github.unregister_hook(gh, url, 'mark', 'lint-test') assert False, 'No exception' except: assert True, 'Exception raised' assert gh.repos.hooks.delete.called is False, 'Delete called'
def test_unregister_hook_logs_message_on_failure(self): repo = Mock(spec=Repository, full_name='mark/lint-review') repo.hooks.return_value = [ github3.repos.hook.Hook(f, session) for f in json.loads(load_fixture('webhook_list.json')) ] hook_delete = Mock() hook_delete.side_effect = Exception('uh oh') repo.hook.return_value.delete = hook_delete fake_logger = Mock() with self.assertRaises(Exception), patch('lintreview.github.log', fake_logger): url = 'http://example.com/review/start' github.unregister_hook(repo, url) fake_logger.error.assert_called_with( "Unable to remove webhook. You need to have administration " "privileges over the repository to remove webhooks." )