Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/github/tests/Exceptions.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
| author | bcclaywell |
|---|---|
| date | Mon, 12 Oct 2015 17:43:33 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d67268158946 |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 | |
| 3 # ########################## Copyrights and license ############################ | |
| 4 # # | |
| 5 # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 6 # Copyright 2012 Zearin <zearin@gonk.net> # | |
| 7 # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> # | |
| 8 # # | |
| 9 # This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ # | |
| 10 # # | |
| 11 # PyGithub is free software: you can redistribute it and/or modify it under # | |
| 12 # the terms of the GNU Lesser General Public License as published by the Free # | |
| 13 # Software Foundation, either version 3 of the License, or (at your option) # | |
| 14 # any later version. # | |
| 15 # # | |
| 16 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # | |
| 17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # | |
| 18 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # | |
| 19 # details. # | |
| 20 # # | |
| 21 # You should have received a copy of the GNU Lesser General Public License # | |
| 22 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # | |
| 23 # # | |
| 24 # ############################################################################## | |
| 25 | |
| 26 import github | |
| 27 import sys | |
| 28 | |
| 29 import Framework | |
| 30 | |
| 31 atLeastPython26 = sys.hexversion >= 0x02060000 | |
| 32 atMostPython2 = sys.hexversion < 0x03000000 | |
| 33 | |
| 34 | |
| 35 class Exceptions(Framework.TestCase): # To stay compatible with Python 2.6, we do not use self.assertRaises with only one argument | |
| 36 def testInvalidInput(self): | |
| 37 raised = False | |
| 38 try: | |
| 39 self.g.get_user().create_key("Bad key", "xxx") | |
| 40 except github.GithubException, exception: | |
| 41 raised = True | |
| 42 self.assertEqual(exception.status, 422) | |
| 43 self.assertEqual( | |
| 44 exception.data, | |
| 45 { | |
| 46 "errors": [ | |
| 47 { | |
| 48 "code": "custom", | |
| 49 "field": "key", | |
| 50 "message": "key is invalid. It must begin with 'ssh-rsa' or 'ssh-dss'. Check that you're copying the public half of the key", | |
| 51 "resource": "PublicKey" | |
| 52 } | |
| 53 ], | |
| 54 "message": "Validation Failed" | |
| 55 } | |
| 56 ) | |
| 57 self.assertTrue(raised) | |
| 58 | |
| 59 def testNonJsonDataReturnedByGithub(self): | |
| 60 # Replay data was forged according to https://github.com/jacquev6/PyGithub/pull/182 | |
| 61 raised = False | |
| 62 try: | |
| 63 self.g.get_user("jacquev6") | |
| 64 except github.GithubException, exception: | |
| 65 raised = True | |
| 66 self.assertEqual(exception.status, 503) | |
| 67 self.assertEqual( | |
| 68 exception.data, | |
| 69 { | |
| 70 "data": "<html><body><h1>503 Service Unavailable</h1>No server is available to handle this request.</body></html>", | |
| 71 } | |
| 72 ) | |
| 73 self.assertTrue(raised) | |
| 74 | |
| 75 def testUnknownObject(self): | |
| 76 raised = False | |
| 77 try: | |
| 78 self.g.get_user().get_repo("Xxx") | |
| 79 except github.GithubException, exception: | |
| 80 raised = True | |
| 81 self.assertEqual(exception.status, 404) | |
| 82 self.assertEqual(exception.data, {"message": "Not Found"}) | |
| 83 if atLeastPython26 and atMostPython2: | |
| 84 self.assertEqual(str(exception), "404 {u'message': u'Not Found'}") | |
| 85 else: | |
| 86 self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover (Covered with Python 3) | |
| 87 self.assertTrue(raised) | |
| 88 | |
| 89 def testUnknownUser(self): | |
| 90 raised = False | |
| 91 try: | |
| 92 self.g.get_user("ThisUserShouldReallyNotExist") | |
| 93 except github.GithubException, exception: | |
| 94 raised = True | |
| 95 self.assertEqual(exception.status, 404) | |
| 96 self.assertEqual(exception.data, {"message": "Not Found"}) | |
| 97 if atLeastPython26 and atMostPython2: | |
| 98 self.assertEqual(str(exception), "404 {u'message': u'Not Found'}") | |
| 99 else: | |
| 100 self.assertEqual(str(exception), "404 {'message': 'Not Found'}") # pragma no cover (Covered with Python 3) | |
| 101 self.assertTrue(raised) | |
| 102 | |
| 103 def testBadAuthentication(self): | |
| 104 raised = False | |
| 105 try: | |
| 106 github.Github("BadUser", "BadPassword").get_user().login | |
| 107 except github.GithubException, exception: | |
| 108 raised = True | |
| 109 self.assertEqual(exception.status, 401) | |
| 110 self.assertEqual(exception.data, {"message": "Bad credentials"}) | |
| 111 if atLeastPython26 and atMostPython2: | |
| 112 self.assertEqual(str(exception), "401 {u'message': u'Bad credentials'}") | |
| 113 else: | |
| 114 self.assertEqual(str(exception), "401 {'message': 'Bad credentials'}") # pragma no cover (Covered with Python 3) | |
| 115 self.assertTrue(raised) | |
| 116 | |
| 117 | |
| 118 class SpecificExceptions(Framework.TestCase): | |
| 119 def testBadCredentials(self): | |
| 120 self.assertRaises(github.BadCredentialsException, lambda: github.Github("BadUser", "BadPassword").get_user().login) | |
| 121 | |
| 122 def testUnknownObject(self): | |
| 123 self.assertRaises(github.UnknownObjectException, lambda: self.g.get_user().get_repo("Xxx")) | |
| 124 | |
| 125 def testBadUserAgent(self): | |
| 126 self.assertRaises(github.BadUserAgentException, lambda: github.Github(self.login, self.password, user_agent="").get_user().name) | |
| 127 | |
| 128 def testRateLimitExceeded(self): | |
| 129 g = github.Github() | |
| 130 | |
| 131 def exceed(): | |
| 132 for i in range(100): | |
| 133 g.get_user("jacquev6") | |
| 134 | |
| 135 self.assertRaises(github.RateLimitExceededException, exceed) |
