mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Lists with ElementGetable capacity
This commit is contained in:
@@ -287,7 +287,7 @@ class GithubObjectWithModifiableListOfObjects( TestCaseWithGithubTestObject ):
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
BasicAttributes( "a1", "a2" ),
|
||||
ListOfObjects( "a3s", ContainedObject, Creatable( "a3", [ "name" ], [ "p1", "p2" ] ) )
|
||||
ListOfObjects( "a3s", ContainedObject, ElementCreatable( "a3", [ "name" ], [ "p1", "p2" ] ) )
|
||||
)
|
||||
|
||||
def testCreate( self ):
|
||||
@@ -332,6 +332,24 @@ class GithubObjectWithObjectGetter( TestCaseWithGithubTestObject ):
|
||||
self.expectDataGet( "/test/a3s/idGet" ).andReturn( { "id": "idGet" } )
|
||||
self.assertEqual( self.o.get_a3( "idGet" ).id, "idGet" )
|
||||
|
||||
class GithubObjectWithElementGetableList( TestCaseWithGithubTestObject ):
|
||||
ContainedObject = GithubObject(
|
||||
"ContainedObject",
|
||||
BaseUrl( lambda obj: "/test/a3s/" + obj.id ),
|
||||
BasicAttributes( "id", "name" )
|
||||
)
|
||||
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
BaseUrl( lambda obj: "/test" ),
|
||||
BasicAttributes( "a1", "a2" ),
|
||||
ListOfObjects( "a3s", ContainedObject, ElementGetable( "a3" ) )
|
||||
)
|
||||
|
||||
def testGetList( self ):
|
||||
self.expectDataGet( "/test/a3s/idGet" ).andReturn( { "id": "idGet" } )
|
||||
self.assertEqual( self.o.get_a3( "idGet" ).id, "idGet" )
|
||||
|
||||
def myCallable( obj, mock, arg ):
|
||||
return mock.call( arg )
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import itertools
|
||||
|
||||
import ArgumentsChecker
|
||||
from ObjectCapacities.Basic import AttributeFromCallable, MethodFromCallable
|
||||
from ObjectCapacities.List import ListOfObjects, ListOfReferences, ListGetable, Creatable
|
||||
from ObjectCapacities.List import ListOfObjects, ListOfReferences, ListGetable, ElementCreatable, ElementGetable
|
||||
|
||||
class BadGithubObjectException( Exception ):
|
||||
pass
|
||||
|
||||
@@ -80,7 +80,7 @@ Repository._addAttributePolicy( ComplexAttribute( "parent", Repository ) )
|
||||
Repository._addAttributePolicy( ComplexAttribute( "source", Repository ) )
|
||||
Repository._addAttributePolicy( ListOfReferences( "forks", Repository ) )
|
||||
|
||||
__repoCreatable = Creatable( "repo", [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] )
|
||||
__repoCreatable = ElementCreatable( "repo", [ "name" ], [ "description", "homepage", "private", "has_issues", "has_wiki", "has_downloads", "team_id", ] )
|
||||
AuthenticatedUser._addAttributePolicy( ListOfObjects( "repos", Repository, __repoCreatable ) )
|
||||
NamedUser._addAttributePolicy( ListOfObjects( "repos", Repository ) )
|
||||
Organization._addAttributePolicy( ListOfObjects( "repos", Repository, __repoCreatable ) )
|
||||
|
||||
@@ -51,7 +51,7 @@ class ListOfReferences:
|
||||
assert isinstance( toBeQueried, self.__type )
|
||||
return obj._github._statusRequest( "GET", obj._baseUrl + "/" + self.__attributeName + "/" + toBeQueried._identity, None, None ) == 204
|
||||
|
||||
class Creatable:
|
||||
class ElementCreatable:
|
||||
def __init__( self, singularName, mandatoryParameters, optionalParameters ):
|
||||
self.__argumentsChecker = ArgumentsChecker.ArgumentsChecker( mandatoryParameters, optionalParameters )
|
||||
self.__createName = "create_" + singularName
|
||||
@@ -77,8 +77,18 @@ class ListGetable:
|
||||
for attributes in obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName, None, None )
|
||||
]
|
||||
|
||||
### @todo Merge ObjectGetter in ListOfObjects, with a SingleGettable similar to Creatable
|
||||
### @todo Add a ListGetable that couls be False for non-getable lists (repo/git/commits for example)
|
||||
class ElementGetable:
|
||||
def __init__( self, singularName ):
|
||||
self.__getName = "get_" + singularName
|
||||
|
||||
def apply( self, list, cls ):
|
||||
self.__type = list.type
|
||||
self.__attributeName = list.attributeName
|
||||
cls._addMethod( self.__getName, self.__execute )
|
||||
|
||||
def __execute( self, obj, identity ):
|
||||
return self.__type( obj._github, obj._github._dataRequest( "GET", obj._baseUrl + "/" + self.__attributeName + "/" + identity, None, None ), lazy = True )
|
||||
|
||||
class ListOfObjects:
|
||||
def __init__( self, attributeName, type, *capacities ):
|
||||
self.attributeName = attributeName
|
||||
|
||||
Reference in New Issue
Block a user