mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Implement extended scalar attribute
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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 ):
|
||||
|
||||
Reference in New Issue
Block a user