Implement extended scalar attribute

This commit is contained in:
Vincent Jacques
2012-02-12 19:36:55 +01:00
parent d01740c0d8
commit 0c6570b6a4
2 changed files with 45 additions and 0 deletions
+21
View File
@@ -156,6 +156,27 @@ class DeletableGithubObject( TestCaseWithGithubTestObject ):
self.expectDelete( "/test" )
self.o.delete()
class GithubObjectWithExtendedScalarAttribute( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
SimpleScalarAttributes( "id", "name", "desc" )
)
GithubTestObject = GithubObject(
"GithubTestObject",
BaseUrl( lambda obj: "/test" ),
SimpleScalarAttributes( "a1", "a2" ),
ExtendedScalarAttribute( "a3", ContainedObject )
)
def testCompletion( self ):
self.expectGet( "/test" ).andReturn( { "a3": { "id": "id1", "name": "name1" } } )
self.assertEqual( self.o.a3.id, "id1" )
self.assertEqual( self.o.a3.name, "name1" )
self.expectGet( "/test/a3s/id1" ).andReturn( { "desc": "desc1" } )
self.assertEqual( self.o.a3.desc, "desc1" )
class GithubObjectWithExtendedListAttribute( TestCaseWithGithubTestObject ):
ContainedObject = GithubObject(
"ContainedObject",
+24
View File
@@ -59,6 +59,30 @@ class ExtendedListAttribute:
def getAttributeDefinitions( self ):
yield "get_" + self.__pluralName, ExtendedListAttribute.AttributeDefinition( self.__pluralName, self.__type )
class ExtendedScalarAttribute:
class AttributeDefinition:
def __init__( self, attributeName, type ):
self.__attributeName = attributeName
self.__type = type
def getValueFromRawValue( self, obj, rawValue ):
return self.__type( obj._github, rawValue, lazy = True )
def updateAttributes( self, obj ):
attributes = obj._github._rawRequest( "GET", obj._baseUrl )
# for attributeName in self.__attributeNames:
# if attributeName not in attributes:
# attributes[ attributeName ] = None
obj._updateAttributes( attributes )
def __init__( self, attributeName, type ):
self.__attributeName = attributeName
self.__type = type
def getAttributeDefinitions( self ):
print ">>>", self.__attributeName
yield self.__attributeName, ExtendedScalarAttribute.AttributeDefinition( self.__attributeName, self.__type )
class Editable:
class Editor:
def __init__( self, obj, mandatoryParameters, optionalParameters ):