예제 #1
0
 def testAuthorizationHeaderWithLogin(self):
     # See special case in Framework.fixAuthorizationHeader
     g = pygithub.Github("fake_login", "fake_password")
     try:
         g.get_user().name
     except pygithub.GithubException:
         pass
예제 #2
0
 def testAuthorizationHeaderWithToken(self):
     # See special case in Framework.fixAuthorizationHeader
     g = pygithub.Github("ZmFrZV9sb2dpbjpmYWtlX3Bhc3N3b3Jk")
     try:
         g.get_user().name
     except pygithub.GithubException:
         pass
예제 #3
0
 def testLoggingWithoutAuthentication(self):
     self.assertEqual(pygithub.Github().get_user("jacquev6").name,
                      "Vincent Jacques")
     if atMostPython32:
         self.assertEqual(
             self.__handler.handled,
             'GET https://api.github.com/users/jacquev6 {\'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'628\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept\', \'x-ratelimit-remaining\': \'4989\', \'server\': \'nginx\', \'last-modified\': \'Tue, 25 Sep 2012 07:42:42 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"9bd085221a16b6d2ea95e72634c3c1ac"\', \'cache-control\': \'public, max-age=60, s-maxage=60\', \'date\': \'Tue, 25 Sep 2012 20:38:56 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"type":"User","html_url":"https://github.com/jacquev6","login":"******","followers":14,"company":"Criteo","created_at":"2010-07-09T06:10:06Z","email":"*****@*****.**","hireable":false,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","public_gists":3,"bio":"","following":29,"name":"Vincent Jacques","blog":"http://vincent-jacques.net","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"public_repos":13,"location":"Paris, France","url":"https://api.github.com/users/jacquev6"}'
         )
예제 #4
0
    def testRateLimitExceeded(self):
        g = pygithub.Github()

        def exceed():
            for i in range(100):
                g.get_user("jacquev6")

        self.assertRaises(pygithub.RateLimitExceededException, exceed)
예제 #5
0
 def testGetAuthorizationsFailsWhenAutenticatedThroughOAuth(self):
     g = pygithub.Github(self.oauth_token)
     raised = False
     try:
         list(g.get_user().get_authorizations())
     except pygithub.GithubException, exception:
         raised = True
         self.assertEqual(exception.status, 404)
예제 #6
0
    def setUp(self):
        BasicTestCase.setUp(self)

        # Set up frame debugging
        pygithub.GithubObject.GithubObject.setCheckAfterInitFlag(True)
        pygithub.Requester.Requester.setDebugFlag(True)
        pygithub.Requester.Requester.setOnCheckMe(self.getFrameChecker())

        self.g = pygithub.Github(self.login, self.password)
예제 #7
0
 def testUnknownUrlScheme(
     self
 ):  # To stay compatible with Python 2.6, we do not use self.assertRaises with only one argument
     try:
         pygithub.Github(self.login,
                         self.password,
                         base_url="foobar://my.enterprise.com")
     except AssertionError, exception:
         raised = True
         self.assertEqual(exception.args[0], "Unknown URL scheme")
예제 #8
0
 def testSpecificPort(self):
     g = pygithub.Github(self.login,
                         self.password,
                         base_url="http://my.enterprise.com:8080")
     self.assertListKeyEqual(g.get_user().get_repos(), lambda r: r.name, [
         "TestPyGithub", "django", "PyGithub", "developer.github.com",
         "acme-public-website", "C4Planner", "Hacking",
         "vincent-jacques.net", "Contests", "Candidates", "Tests",
         "DrawTurksHead", "DrawSyntax", "QuadProgMm",
         "Boost.HierarchicalEnum", "ViDE"
     ])
예제 #9
0
 def testLoggingWithBasicAuthentication(self):
     self.assertEqual(
         pygithub.Github(self.login, self.password).get_user().name,
         "Vincent Jacques")
     # In Python 3.3, dicts are not output in the same order as in Python 2.5 -> 3.2.
     # So, logging is not deterministic and we cannot test it.
     if atMostPython32:
         self.assertEqual(
             self.__handler.handled,
             'GET https://api.github.com/user {\'Authorization\': \'Basic (login and password removed)\', \'User-Agent\': \'PyGithub/Python\'} null ==> 200 {\'status\': \'200 OK\', \'content-length\': \'806\', \'x-github-media-type\': \'github.beta; format=json\', \'x-content-type-options\': \'nosniff\', \'vary\': \'Accept, Authorization, Cookie\', \'x-ratelimit-remaining\': \'4993\', \'server\': \'nginx\', \'last-modified\': \'Fri, 14 Sep 2012 18:47:46 GMT\', \'connection\': \'keep-alive\', \'x-ratelimit-limit\': \'5000\', \'etag\': \'"434dfe5d3f50558fe3cea087cb95c401"\', \'cache-control\': \'private, s-maxage=60, max-age=60\', \'date\': \'Mon, 17 Sep 2012 17:12:32 GMT\', \'content-type\': \'application/json; charset=utf-8\'} {"owned_private_repos":3,"disk_usage":18612,"following":28,"type":"User","public_repos":13,"location":"Paris, France","company":"Criteo","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png","plan":{"space":614400,"private_repos":5,"name":"micro","collaborators":1},"blog":"http://vincent-jacques.net","login":"******","public_gists":3,"html_url":"https://github.com/jacquev6","hireable":false,"created_at":"2010-07-09T06:10:06Z","private_gists":5,"followers":13,"name":"Vincent Jacques","email":"*****@*****.**","bio":"","total_private_repos":3,"collaborators":0,"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","id":327146,"url":"https://api.github.com/users/jacquev6"}'
         )
예제 #10
0
 def testBadAuthentication(self):
     raised = False
     try:
         pygithub.Github("BadUser", "BadPassword").get_user().login
     except pygithub.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)
예제 #11
0
 def testGetAuthorizationsSucceedsWhenAutenticatedThroughLoginPassword(
         self):
     g = pygithub.Github(self.login, self.password)
     self.assertListKeyEqual(
         g.get_user().get_authorizations(), lambda a: a.note,
         [None, None, 'cligh', None, None, 'GitHub Android App'])
예제 #12
0
 def testIgnoreHttpsFromGithubEnterpriseWithPort(self):
     g = pygithub.Github(self.login, self.password, base_url="http://my.enterprise.com:1234/some/prefix")  # http here
     org = g.get_organization("BeaverSoftware")
     self.assertEqual(org.url, "https://my.enterprise.com:1234/some/prefix/orgs/BeaverSoftware")  # https returned
     self.assertListKeyEqual(org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"])  # But still http in second request based on org.url
예제 #13
0
 def testUserAgent(self):
     g = pygithub.Github(user_agent="PyGithubTester")
     self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques")
예제 #14
0
 def testSecretKeyAuthentication(self):
     g = pygithub.Github(client_id=self.client_id,
                         client_secret=self.client_secret)
     self.assertListKeyEqual(
         g.get_organization("BeaverSoftware").get_repos("public"),
         lambda r: r.name, ["FatherBeaver", "PyGithub"])
예제 #15
0
 def testOAuthAuthentication(self):
     g = pygithub.Github(self.oauth_token)
     self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques")
예제 #16
0
 def testBasicAuthentication(self):
     g = pygithub.Github(self.login, self.password)
     self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques")
예제 #17
0
 def testNoAuthentication(self):
     g = pygithub.Github()
     self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques")
예제 #18
0
 def testGetOAuthScopesFromHeader(self):
     g = pygithub.Github(self.oauth_token)
     self.assertEqual(g.oauth_scopes, None)
     g.get_user().name
     self.assertEqual(g.oauth_scopes, ['repo', 'user', 'gist'])
예제 #19
0
 def testDecodeJson(self):
     # This test has to hit GitHub for real, because the record-replay framework looses types
     # and python3 does not behave like python2 for strings and bytes
     self.assertEqual(pygithub.Github().get_rate_limit().rate.limit, 60)
예제 #20
0
 def testBadCredentials(self):
     self.assertRaises(pygithub.BadCredentialsException, lambda: pygithub.Github("BadUser", "BadPassword").get_user().login)
예제 #21
0
 def testBadUserAgent(self):
     self.assertRaises(pygithub.BadUserAgentException, lambda: pygithub.Github(self.login, self.password, user_agent="").get_user().name)