From f50dbffc288184e110899351c108446f4599642c Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sun, 12 Feb 2012 14:44:56 +0100 Subject: [PATCH] Test non-lazy construction --- github/GithubObject.UnitTest.py | 18 ++++++++++++++++++ github/GithubObject.py | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 6c1d9d89..36f1add8 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -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() diff --git a/github/GithubObject.py b/github/GithubObject.py index 266718eb..9d4afd68 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -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: