mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 11:51:10 +00:00
On the way to edit-able objects
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
import MockMockMock
|
||||
|
||||
from GithubObject import BadGithubObjectException, GithubObject, SimpleScalarAttributes
|
||||
from GithubObject import BadGithubObjectException, GithubObject, SimpleScalarAttributes, Editable
|
||||
|
||||
class GithubObjectTestCase( unittest.TestCase ):
|
||||
def testDuplicatedAttribute( self ):
|
||||
@@ -23,14 +23,15 @@ class TestCaseWithGithubTestObject( unittest.TestCase ):
|
||||
def expectGet( self, url ):
|
||||
return self.g.expect.rawRequest( "GET", url )
|
||||
|
||||
class GithubObjectWithOnlySimpleAttributes( TestCaseWithGithubTestObject ):
|
||||
def expectPatch( self, url, data ):
|
||||
return self.g.expect.rawRequest( "PATCH", url, data )
|
||||
|
||||
class GithubObjectWithOnlySimpleScalarAttributes( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
SimpleScalarAttributes( "a1", "a2", "a3", "a4" )
|
||||
)
|
||||
|
||||
def testConstruction( self ):
|
||||
pass # Everything is done in setUp/tearDown
|
||||
|
||||
def testCompletion( self ):
|
||||
# A GithubObject:
|
||||
@@ -47,11 +48,6 @@ 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
|
||||
@@ -66,4 +62,15 @@ class GithubObjectWithOnlySimpleAttributes( TestCaseWithGithubTestObject ):
|
||||
self.assertEqual( o.a3, 3 )
|
||||
self.assertEqual( o.a4, None )
|
||||
|
||||
class EditableGithubObject( TestCaseWithGithubTestObject ):
|
||||
GithubTestObject = GithubObject(
|
||||
"GithubTestObject",
|
||||
SimpleScalarAttributes( "a1", "a2", "a3", "a4" ),
|
||||
Editable( [ "a1" ], [ "a2", "a4" ] ),
|
||||
)
|
||||
|
||||
def testEdit( self ):
|
||||
self.expectPatch( "/test", { "a1": 11, "a2": 22 } ).andReturn( {} )
|
||||
self.o.edit( a1 = 11, a2 = 22 )
|
||||
|
||||
unittest.main()
|
||||
|
||||
@@ -26,6 +26,34 @@ class SimpleScalarAttributes:
|
||||
for attributeName in self.__attributeNames
|
||||
]
|
||||
|
||||
class Editable:
|
||||
class Editor:
|
||||
def __init__( self, obj, mandatoryParamters, optionalParameters ):
|
||||
self.__obj = obj
|
||||
self.__mandatoryParamters = mandatoryParamters
|
||||
self.__optionalParameters = optionalParameters
|
||||
|
||||
def __call__( self, *args, **kwds ):
|
||||
self.__obj._github.rawRequest( "PATCH", "/test", kwds )
|
||||
|
||||
class AttributeDefinition:
|
||||
def __init__( self, mandatoryParamters, optionalParameters ):
|
||||
self.__mandatoryParamters = mandatoryParamters
|
||||
self.__optionalParameters = optionalParameters
|
||||
|
||||
def getValueFromRawValue( self, obj, rawValue ):
|
||||
return rawValue
|
||||
|
||||
def fetchRawValues( self, obj ):
|
||||
return { "edit": Editable.Editor( obj, self.__mandatoryParamters, self.__optionalParameters ) }
|
||||
|
||||
def __init__( self, mandatoryParamters, optionalParameters ):
|
||||
self.__mandatoryParamters = mandatoryParamters
|
||||
self.__optionalParameters = optionalParameters
|
||||
|
||||
def getAttributeDefinitions( self ):
|
||||
yield "edit", Editable.AttributeDefinition( self.__mandatoryParamters, self.__optionalParameters )
|
||||
|
||||
def GithubObject( className, *attributePolicies ):
|
||||
attributeDefinitions = dict()
|
||||
for attributePolicy in attributePolicies:
|
||||
|
||||
Reference in New Issue
Block a user