python类GithubException()的实例源码

test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__handle_synchronize__when_handle_pr_sync_raises_exception__handle_labeled_sync_should_be_called_anyway(self):
        hook_data = {'pull_request': {'number': 12, 'head': {'repo': {'full_name': 'repo'}}}}
        pr_labels = ['label1', 'label2']
        github_controller = GithubController(mock(), mock(), mock(), mock())

        # expect
        expect(github_controller, times=1).get_pr_labels(repository='repo', pr_number=12).thenReturn(pr_labels)
        expect(github_controller, times=1).handle_pr_sync(hook_data, pr_labels).thenRaise(GithubException(404, 'PR not found'))
        expect(github_controller, times=1).handle_labeled_sync(hook_data, pr_labels).thenReturn(async_value(None))

        # when
        with pytest.raises(GithubException):
            await github_controller.handle_synchronize(hook_data)
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__handle_synchronize__when_handle_pr_and_labeled_sync_raise_exceptions__it_should_be_raised_up(self):
        hook_data = {'pull_request': {'number': 12, 'head': {'repo': {'full_name': 'repo'}}}}
        pr_labels = ['label1', 'label2']
        github_controller = GithubController(mock(), mock(), mock(), mock())

        # expect
        expect(github_controller, times=1).get_pr_labels(repository='repo', pr_number=12).thenReturn(pr_labels)
        expect(github_controller, times=1).handle_pr_sync(hook_data, pr_labels).thenRaise(GithubException(404, 'PR not found'))
        expect(github_controller, times=1).handle_labeled_sync(hook_data, pr_labels).thenRaise(jenkins.JenkinsException())

        # when
        with pytest.raises(jenkins.JenkinsException):
            await github_controller.handle_synchronize(hook_data)
test_github_controller.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__are_files_in_repo__should_return_false_on_any_missing_file(self):
        github_client: github.Github = mock(spec=github.Github, strict=True)
        github_repo: github.Repository.Repository = mock(spec=github.Repository.Repository, strict=True)
        github_controller = GithubController(github_client, mock(), mock(), mock())

        hook_details = mock({'repository': 'repo', 'sha': '123qwe', 'branch': 'master'}, spec=HookDetails, strict=True)
        files = ['app/main.py', '.gitignore']

        expect(github_client).get_repo('repo').thenReturn(github_repo)
        expect(github_repo).get_file_contents(path='app/main.py', ref='123qwe').thenReturn(None)
        expect(github_repo).get_file_contents(path='.gitignore', ref='123qwe').thenRaise(GithubException(404, 'File not found'))

        assert not await github_controller.are_files_in_repo(files, hook_details)
test_err_handling.py 文件源码 项目:triggear 作者: futuresimple 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test__when_method_raises_github_exception__should_return_its_status__and_data_as_reason(self):
        @handle_exceptions()
        async def github_exception_raising_coro():
            raise github.GithubException(404, {'message': 'Not found'})

        response: aiohttp.web.Response = await github_exception_raising_coro()

        assert response.status == 404
        assert response.reason == "{'message': 'Not found'}"
Authentication.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def testAuthorizationHeaderWithLogin(self):
        # See special case in Framework.fixAuthorizationHeader
        g = github.Github("fake_login", "fake_password")
        try:
            g.get_user().name
        except github.GithubException:
            pass
Authentication.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def testAuthorizationHeaderWithToken(self):
        # See special case in Framework.fixAuthorizationHeader
        g = github.Github("ZmFrZV9sb2dpbjpmYWtlX3Bhc3N3b3Jk")
        try:
            g.get_user().name
        except github.GithubException:
            pass
Exceptions.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def testNonJsonDataReturnedByGithub(self):
        # Replay data was forged according to https://github.com/jacquev6/PyGithub/pull/182
        raised = False
        try:
            self.g.get_user("jacquev6")
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 503)
            self.assertEqual(
                exception.data,
                {
                    "data": "<html><body><h1>503 Service Unavailable</h1>No server is available to handle this request.</body></html>",
                }
            )
        self.assertTrue(raised)
Exceptions.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def testUnknownObject(self):
        raised = False
        try:
            self.g.get_user().get_repo("Xxx")
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 404)
            self.assertEqual(exception.data, {"message": "Not Found"})
            if atLeastPython26 and atMostPython2:
                self.assertEqual(str(exception), "404 {u'message': u'Not Found'}")
            else:
                self.assertEqual(str(exception), "404 {'message': 'Not Found'}")  # pragma no cover (Covered with Python 3)
        self.assertTrue(raised)
Exceptions.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def testBadAuthentication(self):
        raised = False
        try:
            github.Github("BadUser", "BadPassword").get_user().login
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 401)
            self.assertEqual(exception.data, {"message": "Bad credentials"})
            if atLeastPython26 and atMostPython2:
                self.assertEqual(str(exception), "401 {u'message': u'Bad credentials'}")
            else:
                self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}")  # pragma no cover (Covered with Python 3)
        self.assertTrue(raised)
Exceptions.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def testExceptionPickling(self):
        pickle.loads(pickle.dumps(github.GithubException('foo', 'bar')))
Issue134.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def testGetAuthorizationsFailsWhenAutenticatedThroughOAuth(self):
        g = github.Github(self.oauth_token)
        raised = False
        try:
            list(g.get_user().get_authorizations())
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 404)
        self.assertTrue(raised)
Repository.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def testRaiseErrorWithOutBranch(self):
        raised = False
        try:
            self.repo.protect_branch("", True, "everyone", ["test"])
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 404)
            self.assertEqual(
                exception.data, {
                    u'documentation_url': u'https://developer.github.com/v3/repos/#get-branch',
                    u'message': u'Branch not found'
                }
            )
            self.assertTrue(raised)
Repository.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testRaiseErrorWithBranchProtectionWithOutContext(self):
        raised = False
        try:
            self.repo.protect_branch("master", True, "everyone")
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 422)
            self.assertEqual(
                exception.data, {
                    u'documentation_url': u'https://developer.github.com/v3',
                    u'message': u'Invalid request.\n\n"contexts" wasn\'t supplied.'
                }
            )
            self.assertTrue(raised)
Repository.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def testMergeWithConflict(self):
        raised = False
        try:
            commit = self.repo.merge("branchForBase", "branchForHead")
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 409)
            self.assertEqual(exception.data, {"message": "Merge conflict"})
        self.assertTrue(raised)
Repository.py 文件源码 项目:TutLab 作者: KingsMentor 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def testBadSubscribePubSubHubbub(self):
        raised = False
        try:
            self.repo.subscribe_to_hub("non-existing-event", "http://requestb.in/1bc1sc61")
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 422)
            self.assertEqual(exception.data, {"message": "Invalid event: \"non-existing-event\""})
        self.assertTrue(raised)
Authentication.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def testAuthorizationHeaderWithLogin(self):
        # See special case in Framework.fixAuthorizationHeader
        g = github.Github("fake_login", "fake_password")
        try:
            g.get_user().name
        except github.GithubException:
            pass
Authentication.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def testAuthorizationHeaderWithToken(self):
        # See special case in Framework.fixAuthorizationHeader
        g = github.Github("ZmFrZV9sb2dpbjpmYWtlX3Bhc3N3b3Jk")
        try:
            g.get_user().name
        except github.GithubException:
            pass
Exceptions.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def testNonJsonDataReturnedByGithub(self):
        # Replay data was forged according to https://github.com/jacquev6/PyGithub/pull/182
        raised = False
        try:
            self.g.get_user("jacquev6")
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 503)
            self.assertEqual(
                exception.data,
                {
                    "data": "<html><body><h1>503 Service Unavailable</h1>No server is available to handle this request.</body></html>",
                }
            )
        self.assertTrue(raised)
Exceptions.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def testUnknownObject(self):
        raised = False
        try:
            self.g.get_user().get_repo("Xxx")
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 404)
            self.assertEqual(exception.data, {"message": "Not Found"})
            if atLeastPython26 and atMostPython2:
                self.assertEqual(str(exception), "404 {u'message': u'Not Found'}")
            else:
                self.assertEqual(str(exception), "404 {'message': 'Not Found'}")  # pragma no cover (Covered with Python 3)
        self.assertTrue(raised)
Exceptions.py 文件源码 项目:skill-for-github 作者: dkavanagh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def testBadAuthentication(self):
        raised = False
        try:
            github.Github("BadUser", "BadPassword").get_user().login
        except github.GithubException, exception:
            raised = True
            self.assertEqual(exception.status, 401)
            self.assertEqual(exception.data, {"message": "Bad credentials"})
            if atLeastPython26 and atMostPython2:
                self.assertEqual(str(exception), "401 {u'message': u'Bad credentials'}")
            else:
                self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}")  # pragma no cover (Covered with Python 3)
        self.assertTrue(raised)


问题


面经


文章

微信
公众号

扫码关注公众号