First integration test

This commit is contained in:
Vincent Jacques
2012-02-12 16:33:27 +01:00
parent fd24a2d8f1
commit d9e79948b9
5 changed files with 67 additions and 1 deletions
+35
View File
@@ -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 )
+13
View File
@@ -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"
),
)
+1
View File
@@ -0,0 +1 @@
from Github import Github