mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
First integration test
This commit is contained in:
+1
-1
@@ -1,3 +1,3 @@
|
||||
*.pyc
|
||||
Credentials.py
|
||||
GithubCredentials.py
|
||||
.coverage
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/env python
|
||||
|
||||
import unittest
|
||||
|
||||
from github import Github
|
||||
import GithubCredentials
|
||||
|
||||
class TestCase( unittest.TestCase ):
|
||||
def setUp( self ):
|
||||
self.g = Github( GithubCredentials.login, GithubCredentials.password )
|
||||
|
||||
def testAuthenticatedUser( self ):
|
||||
u = self.g.get_user()
|
||||
self.assertEqual( u.login, "jacquev6" )
|
||||
self.assertEqual( u.name, "Vincent Jacques" )
|
||||
|
||||
unittest.main()
|
||||
@@ -0,0 +1,35 @@
|
||||
import urllib2
|
||||
import json
|
||||
import base64
|
||||
|
||||
from User import AuthenticatedUser
|
||||
|
||||
class Github:
|
||||
def __init__( self, login, password ):
|
||||
self.__login = login
|
||||
self.__password = password
|
||||
|
||||
class _Request( urllib2.Request ):
|
||||
def __init__( self, verb, url, data ):
|
||||
urllib2.Request.__init__( self, url, data )
|
||||
self.__verb = verb
|
||||
|
||||
def get_method( self ):
|
||||
return self.__verb
|
||||
|
||||
def _rawRequest( self, verb, url, data = None ):
|
||||
assert( verb in [ "HEAD", "GET", "POST", "PATCH", "PUT", "DELETE" ] )
|
||||
|
||||
# print verb, url, data
|
||||
|
||||
req = Github._Request( verb, "https://api.github.com" + url, json.dumps( data ) )
|
||||
b64_userpass = base64.b64encode( '%s:%s' % ( self.__login, self.__password ) )
|
||||
b64_userpass = b64_userpass.replace( '\n', '' )
|
||||
req.add_header(
|
||||
"Authorization", "Basic %s" % b64_userpass
|
||||
)
|
||||
|
||||
return json.load( urllib2.urlopen( req ) )
|
||||
|
||||
def get_user( self ):
|
||||
return AuthenticatedUser( self, {}, lazy = True )
|
||||
@@ -0,0 +1,13 @@
|
||||
from GithubObject import *
|
||||
|
||||
AuthenticatedUser = GithubObject(
|
||||
"AuthenticatedUser",
|
||||
BaseUrl( lambda obj: "/user" ),
|
||||
SimpleScalarAttributes(
|
||||
"login", "id", "avatar_url", "gravatar_id", "url", "name", "company",
|
||||
"blog", "location", "email", "hireable", "bio", "public_repos",
|
||||
"public_gists", "followers", "following", "html_url", "created_at",
|
||||
"type", "total_private_repos", "owned_private_repos", "private_gists",
|
||||
"disk_usage", "collaborators", "plan"
|
||||
),
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
from Github import Github
|
||||
Reference in New Issue
Block a user