當前位置: 首頁>>代碼示例>>Python>>正文


Python Requester.dataRequest方法代碼示例

本文整理匯總了Python中Requester.Requester.dataRequest方法的典型用法代碼示例。如果您正苦於以下問題:Python Requester.dataRequest方法的具體用法?Python Requester.dataRequest怎麽用?Python Requester.dataRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Requester.Requester的用法示例。


在下文中一共展示了Requester.dataRequest方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from Requester import Requester [as 別名]
# 或者: from Requester.Requester import dataRequest [as 別名]
class Github:
    def __init__( self, login=None, password=None ):
        self.__requester = Requester( login=login, password=password )

    def _dataRequest( self, verb, url, parameters, data ):
        return self.__requester.dataRequest( verb, url, parameters, data )

    def _statusRequest( self, verb, url, parameters, data ):
        return self.__requester.statusRequest( verb, url, parameters, data )

    def get_user( self, login = None ):
        if login is None:
            return AuthenticatedUser( self, {}, lazy = True )
        else:
            return NamedUser( self, { "login": login }, lazy = False )

    def get_organization( self, login ):
        return Organization( self, { "login": login }, lazy = False )

    def get_gist( self, id ):
        return Gist( self, { "id": id }, lazy = False )

    def get_gists( self ):
        return [
            Gist( self, attributes, lazy = True )
            for attributes
            in self._dataRequest( "GET", "/gists/public", None, None )
        ]
開發者ID:abersager,項目名稱:PyGithub,代碼行數:30,代碼來源:Github.py

示例2: TestCase

# 需要導入模塊: from Requester import Requester [as 別名]
# 或者: from Requester.Requester import dataRequest [as 別名]
class TestCase( unittest.TestCase ):
    def setUp( self ):
        unittest.TestCase.setUp( self )

        self.r = Requester( "login", "password" )
        self.b64_userpass = base64.b64encode( "login:password" )
        self.b64_userpass = self.b64_userpass.replace( '\n', '' )

        self.connectionFactory = MockMockMock.Mock( "httplib.HTTPSConnection" )
        self.connection = MockMockMock.Mock( "connection", self.connectionFactory )
        self.response = MockMockMock.Mock( "response", self.connectionFactory )

        httplib.HTTPSConnection = self.connectionFactory.object

    def tearDown( self ):
        self.connectionFactory.tearDown()
        unittest.TestCase.tearDown( self )

    def expect( self, verb, url, input, status, responseHeaders, output ):
        self.connectionFactory.expect( "api.github.com", strict = True ).andReturn( self.connection.object )
        self.connection.expect.request( verb, url, input, { "Authorization" : "Basic " + self.b64_userpass } )
        self.connection.expect.getresponse().andReturn( self.response.object )
        self.response.expect.status.andReturn( status )
        self.response.expect.getheaders().andReturn( responseHeaders )
        self.response.expect.read().andReturn( output )
        self.connection.expect.close()

    def testSimpleStatus( self ):
        self.expect( "GET", "/test", "null", 200, [], "" )
        self.assertEqual( self.r.statusRequest( "GET", "/test", None, None ), 200 )

    def testSimpleData( self ):
        self.expect( "GET", "/test", "null", 200, [], '{ "foo": "bar" }' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", None, None ), { "foo" : "bar" } )

    def testDataOnBadStatus( self ):
        self.expect( "GET", "/test", "null", 404, [], '{ "foo": "bar" }' )
        with self.assertRaises( UnknownGithubObject ):
            self.r.dataRequest( "GET", "/test", None, None )

    def testDataWithParametersAndData( self ):
        self.expect( "GET", "/test?tata=tutu&toto=titi", '{"xxx": 42}', 200, [], '{ "foo": "bar" }' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", { "toto" : "titi", "tata" : "tutu" }, { "xxx" : 42 } ), { "foo" : "bar" } )

    def testPagination( self ):
        self.expect( "GET", "/test", 'null', 200, [ ( "link", "<xxx?page=2>; next, xxx; last" ) ], '[ 1, 2 ]' )
        self.expect( "GET", "/test?page=2", 'null', 200, [ ( "link", "xxx; prev, xxx; first, <xxx?page=3>; next, xxx; last" ) ], '[ 3, 4 ]' )
        self.expect( "GET", "/test?page=3", 'null', 200, [ ( "link", "xxx; prev, xxx; first" ) ], '[ 5, 6 ]' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", None, None ), [ 1, 2, 3, 4, 5, 6 ] )

    def testPaginationObviouslyFinished( self ):
        self.expect( "GET", "/test", 'null', 200, [ ( "link", "<xxx?page=2>; next, xxx; last" ) ], '[ 1, 2 ]' )
        self.expect( "GET", "/test?page=2", 'null', 200, [ ( "link", "xxx; prev, xxx; first, <xxx?page=3>; next, xxx; last" ) ], '[ 3, 4 ]' )
        self.expect( "GET", "/test?page=3", 'null', 200, [ ( "link", "xxx; prev, xxx; first" ) ], '[]' )
        self.assertEqual( self.r.dataRequest( "GET", "/test", None, None ), [ 1, 2, 3, 4 ] )
開發者ID:abersager,項目名稱:PyGithub,代碼行數:57,代碼來源:Requester.UnitTest.py


注:本文中的Requester.Requester.dataRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。