From 80ec0bde33e0941eeb791a408355d6e6058f267e Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sun, 12 Feb 2012 14:37:33 +0100 Subject: [PATCH] Remember that some values are not fetchable --- github/GithubObject.UnitTest.py | 2 ++ github/GithubObject.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index f6d6cb44..6c1d9d89 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -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: diff --git a/github/GithubObject.py b/github/GithubObject.py index 902fd5ae..266718eb 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -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 ]