Remove default ListGetable capacity from lists

This commit is contained in:
Vincent Jacques
2012-02-22 19:41:01 +00:00
parent df2c351cc4
commit f2bc0ea942
5 changed files with 14 additions and 17 deletions
+4 -4
View File
@@ -221,7 +221,7 @@ class GithubObjectWithListOfReferences( TestCaseWithGithubTestObject ):
a3s = self.o.get_a3s( "foobar" )
self.assertEqual( len( a3s ), 3 )
class GithubObjectWithListOfObjects( TestCaseWithGithubTestObject ):
class GithubObjectWithListGetableList( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
@@ -232,7 +232,7 @@ class GithubObjectWithListOfObjects( TestCaseWithGithubTestObject ):
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
BasicAttributes( "a1", "a2" ),
ListOfObjects( "a3s", ContainedObject )
ListOfObjects( "a3s", ContainedObject, ListGetable() )
)
def testGetList( self ):
@@ -275,7 +275,7 @@ class GithubObjectWithModifiableListOfReferences( TestCaseWithGithubTestObject )
self.expectStatusGet( "/test/a3s/idQuery" ).andReturn( 404 )
self.assertFalse( self.o.has_in_a3s( a3ToQuery ) )
class GithubObjectWithModifiableListOfObjects( TestCaseWithGithubTestObject ):
class GithubObjectWithElementCreatableList( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
@@ -343,7 +343,7 @@ class GithubObjectWithElementGetableList( TestCaseWithGithubTestObject ):
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
BasicAttributes( "a1", "a2" ),
ListOfObjects( "a3s", ContainedObject, ElementGetable( "a3" ) )
ListOfObjects( "a3s", ContainedObject, ElementGetable( "a3", lambda obj, id: { "id": id } ) )
)
def testGetList( self ):
+1 -1
View File
@@ -1,6 +1,6 @@
import itertools
import ArgumentsChecker
import ObjectCapacities.ArgumentsChecker as ArgumentsChecker
from ObjectCapacities.Basic import AttributeFromCallable, MethodFromCallable
from ObjectCapacities.List import ListOfObjects, ListOfReferences, ListGetable, ElementCreatable, ElementGetable
+4 -7
View File
@@ -81,13 +81,10 @@ Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) )
Repository._addAttributePolicy( ListOfReferences( "forks", Repository ) )
__repoCreatable = ElementCreatable( "repo", [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] )
AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, __repoCreatable ) )
NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository ) )
Organization._addAttributePolicy( ListOfObjects( "repos", Repository, __repoCreatable ) )
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 } } ) )
__repoElementGetable = ElementGetable( "repo", lambda obj, name: { "owner": { "login": obj.login }, "name": name } )
AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, ListGetable(), __repoElementGetable, __repoCreatable ) )
NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository, ListGetable(), __repoElementGetable ) )
Organization._addAttributePolicy( ListOfObjects( "repos", Repository, ListGetable(), __repoElementGetable, __repoCreatable ) )
AuthenticatedUser._addAttributePolicy( ListOfReferences( "watched", Repository, addable = True, removable = True, hasable = True ) )
NamedUser._addAttributePolicy( ListOfReferences( "watched", Repository ) )
+5 -5
View File
@@ -78,24 +78,24 @@ class ListGetable:
]
class ElementGetable:
def __init__( self, singularName ):
def __init__( self, singularName, attributes ):
self.__getName = "get_" + singularName
self.__attributes = attributes
def apply( self, list, cls ):
self.__type = list.type
self.__attributeName = list.attributeName
cls._addMethod( self.__getName, self.__execute )
def __execute( self, obj, identity ):
return self.__type( obj._github, obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName + "/" + identity, None, None ), lazy = True )
def __execute( self, obj, *args, **kwds ):
return self.__type( obj._github, self.__attributes( obj, *args, **kwds ), lazy = False )
class ListOfObjects:
def __init__( self, attributeName, type, *capacities ):
self.attributeName = attributeName
self.type = type
self.__getName = "get_" + attributeName
self.__capacities = list( capacities )
self.__capacities.append( ListGetable() )
self.__capacities = capacities
def apply( self, cls ):
for capacity in self.__capacities: