mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Remember that some values are not fetchable
This commit is contained in:
@@ -41,6 +41,8 @@ class GithubObjectWithOnlySimpleAttributes( TestCaseWithGithubTestObject ):
|
||||
self.assertEqual( self.o.a1, 1 )
|
||||
# - acknowledges updates of attributes
|
||||
self.assertEqual( self.o.a2, 22 )
|
||||
# - remembers that some attributes are absent even after an update
|
||||
self.assertEqual( self.o.a4, None )
|
||||
|
||||
def testUnknownAttribute( self ):
|
||||
# A GithubObject:
|
||||
|
||||
+15
-3
@@ -3,18 +3,26 @@ class BadGithubObjectException( Exception ):
|
||||
|
||||
class SimpleScalarAttributes:
|
||||
class AttributeDefinition:
|
||||
def __init__( self, attributeNames ):
|
||||
self.__attributeNames = attributeNames
|
||||
|
||||
def getValueFromRawValue( self, obj, rawValue ):
|
||||
return rawValue
|
||||
|
||||
def fetchRawValues( self, obj ):
|
||||
return obj._github.rawRequest( "GET", "/test" )
|
||||
attributes = obj._github.rawRequest( "GET", "/test" )
|
||||
for attributeName in self.__attributeNames:
|
||||
if attributeName not in attributes:
|
||||
attributes[ attributeName ] = None
|
||||
return attributes
|
||||
|
||||
def __init__( self, *attributeNames ):
|
||||
self.__attributeNames = attributeNames
|
||||
|
||||
def getAttributeDefinitions( self ):
|
||||
commonDefinition = SimpleScalarAttributes.AttributeDefinition( self.__attributeNames )
|
||||
return [
|
||||
( attributeName, SimpleScalarAttributes.AttributeDefinition() )
|
||||
( attributeName, commonDefinition )
|
||||
for attributeName in self.__attributeNames
|
||||
]
|
||||
|
||||
@@ -44,7 +52,11 @@ def GithubObject( className, *attributePolicies ):
|
||||
def __updateAttributes( self, attributes ):
|
||||
for attributeName, attributeValue in attributes.iteritems():
|
||||
attributeDefinition = attributeDefinitions[ attributeName ]
|
||||
self.__attributes[ attributeName ] = attributeDefinition.getValueFromRawValue( self, attributeValue )
|
||||
if attributeValue is None:
|
||||
if attributeName not in self.__attributes:
|
||||
self.__attributes[ attributeName ] = None
|
||||
else:
|
||||
self.__attributes[ attributeName ] = attributeDefinition.getValueFromRawValue( self, attributeValue )
|
||||
|
||||
def __fetchAttribute( self, attributeName ):
|
||||
attributeDefinition = attributeDefinitions[ attributeName ]
|
||||
|
||||
Reference in New Issue
Block a user