Test non-lazy construction

This commit is contained in:
Vincent Jacques
2012-02-12 14:44:56 +01:00
parent 80ec0bde33
commit f50dbffc28
2 changed files with 22 additions and 0 deletions
+18
View File
@@ -20,6 +20,9 @@ class TestCaseWithGithubTestObject( unittest.TestCase ):
self.g.tearDown()
unittest.TestCase.tearDown( self )
def expectGet( self, url ):
return self.g.expect.rawRequest( "GET", url )
class GithubObjectWithOnlySimpleAttributes( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
@@ -44,8 +47,23 @@ class GithubObjectWithOnlySimpleAttributes( TestCaseWithGithubTestObject ):
# - remembers that some attributes are absent even after an update
self.assertEqual( self.o.a4, None )
def testEdit( self ):
# A GithubObject:
# - does not have an 'edit' method
self.assertRaises( AttributeError, lambda: self.o.edit )
def testUnknownAttribute( self ):
# A GithubObject:
# - does not have silly attributes
self.assertRaises( AttributeError, lambda: self.o.foobar )
def testNonLazyConstruction( self ):
self.expectGet( "/test" ).andReturn( { "a2": 2, "a3": 3 } )
o = self.GithubTestObject( self.g.object, {}, lazy = False )
self.g.tearDown()
self.assertEqual( o.a1, None )
self.assertEqual( o.a2, 2 )
self.assertEqual( o.a3, 3 )
self.assertEqual( o.a4, None )
unittest.main()
+4
View File
@@ -40,6 +40,10 @@ def GithubObject( className, *attributePolicies ):
self._github = github
self.__attributes = dict()
self.__updateAttributes( attributes )
if not lazy:
for attributeName in attributeDefinitions:
if attributeName not in self.__attributes:
self.__fetchAttribute( attributeName )
def __getattr__( self, attributeName ):
if attributeName in attributeDefinitions: