Merge branch 'topic/GetObjectFromIdentity' into develop

This commit is contained in:
Vincent Jacques
2012-02-20 17:35:36 +01:00
3 changed files with 30 additions and 5 deletions
+18
View File
@@ -286,6 +286,24 @@ class GithubObjectWithModifiableListOfObjects( TestCaseWithGithubTestObject ):
self.expectDataPost( "/test/a3s", { "name": "nameCreate" } ).andReturn( { "id": "idCreate" } )
self.assertEqual( self.o.create_a3s( name = "nameCreate" ).id, "idCreate" )
class GithubObjectWithObjectGetter( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
BasicAttributes( "id", "name" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
BasicAttributes( "a1", "a2" ),
ObjectGetter( "a3", ContainedObject, lambda obj, id : { "id": id } )
)
def testGetList( self ):
self.expectDataGet( "/test/a3s/idGet" ).andReturn( { "id": "idGet" } )
self.assertEqual( self.o.get_a3( "idGet" ).id, "idGet" )
def myCallable( obj, mock, arg ):
return mock.call( arg )
+9
View File
@@ -185,6 +185,15 @@ class Deletable( MethodFromCallable ):
def __execute( self, obj, *args, **kwds ):
obj._github._statusRequest( "DELETE", obj._baseUrl, None, None )
class ObjectGetter( MethodFromCallable ):
def __init__( self, singularName, type, attributes ):
MethodFromCallable.__init__( self, "get_" + singularName, self.__execute )
self.__attributes = attributes
self.__type = type
def __execute( self, obj, *args, **kwds ):
return self.__type( obj._github, self.__attributes( obj, *args, **kwds ), lazy = False )
def GithubObject( className, *attributePolicies ):
class GithubObject:
__attributeDefinitions = dict()
+3 -5
View File
@@ -84,11 +84,9 @@ AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, creat
NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository ) )
Organization._addAttributePolicy( ListOfObjects( "repos", Repository, creatable = True, singularName = "repo" ) )
def __repoFromUser( user, name ):
return Repository( user._github, { "name": name, "owner": { "login": user.login } }, lazy = False )
AuthenticatedUser._addAttributePolicy( MethodFromCallable( "get_repo", __repoFromUser ) )
NamedUser._addAttributePolicy( MethodFromCallable( "get_repo", __repoFromUser ) )
Organization._addAttributePolicy( MethodFromCallable( "get_repo", __repoFromUser ) )
AuthenticatedUser._addAttributePolicy( ObjectGetter( "repo", Repository, lambda user, name: { "name": name, "owner": { "login": user.login } } ) )
NamedUser._addAttributePolicy( ObjectGetter( "repo", Repository, lambda user, name: { "name": name, "owner": { "login": user.login } } ) )
Organization._addAttributePolicy( ObjectGetter( "repo", Repository, lambda organization, name: { "name": name, "owner": { "login": organization.login } } ) )
AuthenticatedUser._addAttributePolicy( ListOfReferences( "watched", Repository, addable = True, removable = True, hasable = True ) )
NamedUser._addAttributePolicy( ListOfReferences( "watched", Repository ) )