diff --git a/Reference.md b/Reference.md index 777faddd..aca5a98d 100644 --- a/Reference.md +++ b/Reference.md @@ -33,7 +33,7 @@ Class `AuthenticatedUser` ### Repositories - - `get_repos()`: list of `Repository` (TODO SOON: add type parameter) + - `get_repos()`: list of `Repository`: see [API](http://developer.github.com/v3/repos/#list-your-repositories) for `type` parameter - `get_repo( name )`: `Repository` - `create_repo( ... )`: `Repository`: see [API](http://developer.github.com/v3/repos/#create) for parameters - `create_fork( repo )`: `Repository` @@ -64,7 +64,7 @@ Class `NamedUser` ### Repositories - - `get_repos()`: list of `Repository` (TODO SOON: add type parameter) + - `get_repos()`: list of `Repository`: see [API](http://developer.github.com/v3/repos/#list-user-repositories) for `type` parameter - `get_repo( name )`: `Repository` ### Watching @@ -88,7 +88,7 @@ Class `Organization` ### Repositories - - `get_repos()`: list of `Repository` (TODO SOON: add type parameter) + - `get_repos()`: list of `Repository`: see [API](http://developer.github.com/v3/repos/#list-organization-repositories) for `type` parameter - `get_repo( name )`: `Repository` - `create_repo( ... )`: `Repository`: see [API](http://developer.github.com/v3/repos/#create) for parameters - `create_fork( repo )`: `Repository` @@ -224,7 +224,7 @@ API `/orgs/:org/public_members/:user` API `/orgs/:org/repos` ---------------------- - - GET: `Organization.get_repos()`: list of `Repository` (TODO: add type parameter) + - GET: `Organization.get_repos()`: list of `Repository` - POST: `Organization.create_repo( ... )`: `Repository` API `/orgs/:org/teams` @@ -561,7 +561,7 @@ API `/user/orgs` API `/user/repos` ----------------- - - GET: `AuthenticatedUser.get_repos()`: list of `Repository` (TODO: add type parameter) + - GET: `AuthenticatedUser.get_repos()`: list of `Repository` - POST: `AuthenticatedUser.create_repo( ... )`: `Repository` API `/user/watched` @@ -616,7 +616,7 @@ API `/users/:user/received_events/public` API `/users/:user/repos` ------------------------ - - GET: `NamedUser.get_repos()`: list of `Repository` (TODO: add type parameter) + - GET: `NamedUser.get_repos()`: list of `Repository` API `/users/:user/watched` -------------------------- diff --git a/github/GithubObject.UnitTest.py b/github/GithubObject.UnitTest.py index 50244c5e..d33ed079 100644 --- a/github/GithubObject.UnitTest.py +++ b/github/GithubObject.UnitTest.py @@ -22,8 +22,8 @@ class TestCaseWithGithubTestObject( unittest.TestCase ): self.g.tearDown() unittest.TestCase.tearDown( self ) - def expectDataGet( self, url ): - return self.g.expect._dataRequest( "GET", url, None, None ) + def expectDataGet( self, url, arguments = None ): + return self.g.expect._dataRequest( "GET", url, arguments, None ) def expectStatusPut( self, url ): return self.g.expect._statusRequest( "PUT", url, None, None ) @@ -197,17 +197,22 @@ class GithubObjectWithListOfReferences( TestCaseWithGithubTestObject ): "GithubTestObject", BaseUrl( lambda obj: "/test" ), BasicAttributes( "a1", "a2" ), - ListOfReferences( "a3s", ContainedObject ) + ListOfReferences( "a3s", ContainedObject, getParameters = [ "type" ] ) ) def testGetList( self ): - self.expectDataGet( "/test/a3s" ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] ) + self.expectDataGet( "/test/a3s", {} ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] ) a3s = self.o.get_a3s() self.assertEqual( len( a3s ), 3 ) self.assertEqual( a3s[ 0 ].id, "id1" ) self.expectDataGet( "/test/a3s/id1" ).andReturn( { "name": "name1" } ) self.assertEqual( a3s[ 0 ].name, "name1" ) + def testGetListWithType( self ): + self.expectDataGet( "/test/a3s", { "type": "foobar" } ).andReturn( [ { "id": "id1" }, { "id": "id2" }, { "id": "id3" } ] ) + a3s = self.o.get_a3s( "foobar" ) + self.assertEqual( len( a3s ), 3 ) + class GithubObjectWithListOfObjects( TestCaseWithGithubTestObject ): ContainedObject = GithubObject( "ContainedObject", diff --git a/github/GithubObject.py b/github/GithubObject.py index 061e6265..9b244f5b 100644 --- a/github/GithubObject.py +++ b/github/GithubObject.py @@ -82,10 +82,11 @@ class Identity( AttributeFromCallable ): AttributeFromCallable.__init__( self, "_identity", identity ) class ListOfReferences: - def __init__( self, attributeName, type, addable = False, removable = False, hasable = False ): + def __init__( self, attributeName, type, addable = False, removable = False, hasable = False, getParameters = None ): self.__attributeName = attributeName self.__type = type self.__getName = "get_" + attributeName + self.__getParameters = getParameters if addable: self.__addName = "add_to_" + attributeName else: @@ -108,10 +109,12 @@ class ListOfReferences: if self.__hasName is not None: cls._addMethod( self.__hasName, self.__executeHas ) - def __executeGet( self, obj ): + def __executeGet( self, obj, *args, **kwds ): + for arg, argumentName in itertools.izip( args, self.__getParameters ): + kwds[ argumentName ] = arg return [ self.__type( obj._github, attributes, lazy = True ) - for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName, None, None ) + for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName, kwds, None ) ] def __executeAdd( self, obj, toBeAdded ):