예제 #1
0
    def test_timeout(self):
        """ Google doesn't offer any services on our crazy ports """
        addr = 'http://google.com:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1, connectTimeout=0.1)
        d = proxy.callRemote('sleep', 5)

        def finished(result):
            self.assertTrue(isinstance(result.value, TimeoutError))

        d.addErrback(finished)
        return d
예제 #2
0
    def test_timeout(self):
        """ Google doesn't offer any services on our crazy ports """
        addr = 'http://google.com:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1, connectTimeout=0.1)
        d = proxy.callRemote('sleep', 5)

        def finished(result):
            self.assertTrue(isinstance(result.value, TimeoutError))

        d.addErrback(finished)
        return d
예제 #3
0
    def test_anonymousError(self):
        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, credentials=Anonymous())
        d = proxy.callRemote('echo', '')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            self.assertEquals(result.strerror, 'Unauthorized')
            self.assertEquals(result.errno, jsonrpc.INVALID_REQUEST)

        e.addCallback(finished)
        return d
예제 #4
0
    def test_keywordsV2(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_2)
        d = proxy.callRemote('echo', data=data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #5
0
    def test_bodyFromResponseProtocolBody(self):
        data = 'some random string'

        proxy = Proxy('', '')
        response = DummyResponse(data)
        d = proxy.bodyFromResponse(response)

        def finished(_):
            self.assertEquals(response.protocol.body, data)

        d.addCallback(finished)
        return d
예제 #6
0
    def test_bodyFromResponseDeferred(self):
        data = 'some random string'

        proxy = Proxy('', '')
        response = DummyResponse(data)
        d = proxy.bodyFromResponse(response)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #7
0
    def test_bodyFromResponseProtocolBody(self):
        data = 'some random string'

        proxy = Proxy('', '')
        response = DummyResponse(data)
        d = proxy.bodyFromResponse(response)

        def finished(_):
            self.assertEquals(response.protocol.body, data)

        d.addCallback(finished)
        return d
예제 #8
0
    def test_bodyFromResponseDeferred(self):
        data = 'some random string'

        proxy = Proxy('', '')
        response = DummyResponse(data)
        d = proxy.bodyFromResponse(response)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #9
0
    def test_keywordsV2(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_2)
        d = proxy.callRemote('echo', data=data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #10
0
    def test_anonymousLogin(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1, credentials=Anonymous())
        d = proxy.callRemote('echo', data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #11
0
    def test_anonymousLogin(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1, credentials=Anonymous())
        d = proxy.callRemote('echo', data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #12
0
    def test_anonymousError(self):
        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, credentials=Anonymous())
        d = proxy.callRemote('echo', '')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            self.assertEquals(result.strerror, 'Unauthorized')
            self.assertEquals(result.errno, jsonrpc.INVALID_REQUEST)

        e.addCallback(finished)
        return d
예제 #13
0
    def test_callRemoteV1NoMethod(self):
        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1)
        d = proxy.callRemote('nosuchmethod')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            self.assertEquals(result.strerror, 'Method nosuchmethod not found')
            self.assertEquals(result.errno, jsonrpc.METHOD_NOT_FOUND)
            self.assertEquals(result.version, jsonrpc.VERSION_1)

        e.addCallback(finished)
        return e
예제 #14
0
    def test_loginOk(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        credentials = UsernamePassword('user', 'password')
        proxy = Proxy(addr, credentials=credentials)
        d = proxy.callRemote('echo', data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #15
0
    def test_loginOk(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        credentials = UsernamePassword('user', 'password')
        proxy = Proxy(addr, credentials=credentials)
        d = proxy.callRemote('echo', data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #16
0
    def test_loginWrongUser(self):
        addr = 'http://localhost:%s' % self.portNumber
        credentials = UsernamePassword('wrong user', 'password1')
        proxy = Proxy(addr, credentials=credentials)
        d = proxy.callRemote('echo', '')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            self.assertEquals(result.strerror, 'Unauthorized')
            self.assertEquals(result.errno, jsonrpc.INVALID_REQUEST)

        e.addCallback(finished)
        return d
예제 #17
0
    def test_loginWrongUser(self):
        addr = 'http://localhost:%s' % self.portNumber
        credentials = UsernamePassword('wrong user', 'password1')
        proxy = Proxy(addr, credentials=credentials)
        d = proxy.callRemote('echo', '')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            self.assertEquals(result.strerror, 'Unauthorized')
            self.assertEquals(result.errno, jsonrpc.INVALID_REQUEST)

        e.addCallback(finished)
        return d
예제 #18
0
    def test_callRemoteV1NoMethod(self):
        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1)
        d = proxy.callRemote('nosuchmethod')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            self.assertEquals(result.strerror, 'Method nosuchmethod not found')
            self.assertEquals(result.errno, jsonrpc.METHOD_NOT_FOUND)
            self.assertEquals(result.version, jsonrpc.VERSION_1)

        e.addCallback(finished)
        return e
예제 #19
0
    def test_callRemoteV2InvalidParams(self):
        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_2)
        d = proxy.callRemote('echo', 'abc', 'def')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            msg = 'jsonrpc_echo() takes exactly 2 arguments (3 given)'
            self.assertEquals(result.strerror, msg)
            self.assertEquals(result.errno, jsonrpc.INVALID_PARAMS)
            self.assertEquals(result.version, unicode(jsonrpc.VERSION_2))

        e.addCallback(finished)
        return e
예제 #20
0
    def test_callRemoteV2InvalidParams(self):
        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_2)
        d = proxy.callRemote('echo', 'abc', 'def')
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            msg = 'jsonrpc_echo() takes exactly 2 arguments (3 given)'
            self.assertEquals(result.strerror, msg)
            self.assertEquals(result.errno, jsonrpc.INVALID_PARAMS)
            self.assertEquals(result.version, unicode(jsonrpc.VERSION_2))

        e.addCallback(finished)
        return e
예제 #21
0
    def test_keywordsUnexpected(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1)
        d = proxy.callRemote('echo', wrongname=data)
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            msg = 'jsonrpc_echo() got an unexpected keyword argument ' + \
                  '\'wrongname\''
            self.assertEquals(result.strerror, msg)
            self.assertEquals(result.errno, jsonrpc.INVALID_PARAMS)

        e.addCallback(finished)
        return d
예제 #22
0
    def test_init(self):
        url = 'https://example.org/abcdef'
        version = '2.0'

        proxy = Proxy(url, version, contextFactory=WebClientContextFactory())
        self.assertEquals(proxy.url, url)
        self.assertEquals(proxy.version, version)
예제 #23
0
    def test_keywordsUnexpected(self):
        data = 'some random string'

        addr = 'http://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1)
        d = proxy.callRemote('echo', wrongname=data)
        e = self.assertFailure(d, jsonrpc.JSONRPCError)

        def finished(result):
            msg = 'jsonrpc_echo() got an unexpected keyword argument ' + \
                  '\'wrongname\''
            self.assertEquals(result.strerror, msg)
            self.assertEquals(result.errno, jsonrpc.INVALID_PARAMS)

        e.addCallback(finished)
        return d
예제 #24
0
    def test_init(self):
        url = 'http://example.org/abcdef'
        version = '2.0'

        proxy = Proxy(url, version)
        self.assertEquals(proxy.url, url)
        self.assertEquals(proxy.version, version)
예제 #25
0
    def test_init(self):
        url = 'http://example.org/abcdef'
        version = '2.0'

        proxy = Proxy(url, version)
        self.assertEquals(proxy.url, url)
        self.assertEquals(proxy.version, version)
        self.assertTrue(isinstance(proxy.credentials, Anonymous))
예제 #26
0
    def test_callRemote(self):
        """
        The test itself passes, but trial raises "Reactor was unclean" after
        tearDown.. Might be related to
        http://twistedmatrix.com/trac/ticket/5118
        """
        data = 'some random string'

        addr = 'https://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1,
                      contextFactory=WebClientContextFactory())
        d = proxy.callRemote('echo', data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #27
0
    def test_callRemote(self):
        """
        The test itself passes, but trial raises "Reactor was unclean" after
        tearDown.. Might be related to
        http://twistedmatrix.com/trac/ticket/5118
        """
        data = 'some random string'

        addr = 'https://localhost:%s' % self.portNumber
        proxy = Proxy(addr, jsonrpc.VERSION_1,
                      contextFactory=WebClientContextFactory())
        d = proxy.callRemote('echo', data)

        def finished(result):
            self.assertEquals(result, data)

        d.addCallback(finished)
        return d
예제 #28
0
    print "Result: %s" % str(value)


def printError(error):
    print 'error', error.value


def shutDown(data):
    print "Shutting down reactor..."
    reactor.stop()


address = 'http://localhost:8999'

credentials = UsernamePassword('user123', 'password456')
proxy = Proxy(address, credentials=credentials)
ds = []

d = proxy.callRemote('echo', ['ajajaj', 'bjbjbj'])
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('add', 14, 15)
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('mysql_first_user')
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('none')
예제 #29
0
    def test_poolPassing(self):
        pool = HTTPConnectionPool(reactor)
        proxy = Proxy('', pool=pool)

        self.assertEqual(id(proxy.agent._pool), id(pool))
예제 #30
0
def printValue(value):
    print "Result: %s" % str(value)


def printError(error):
    print 'error', error.value


def shutDown(data):
    print "Shutting down reactor..."
    reactor.stop()

address = 'https://localhost:8999'

proxy = Proxy(address, contextFactory=WebClientContextFactory())
ds = []

d = proxy.callRemote('echo', ['ajajaj', 'bjbjbj'])
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('add', 14, 15)
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('mysql_first_user')
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('none')
예제 #31
0
def printValue(value):
    print "Result: %s" % str(value)


def printError(error):
    print 'error', error.value


def shutDown(data):
    print "Shutting down reactor..."
    reactor.stop()

address = 'http://localhost:8999'

credentials=UsernamePassword('user123', 'password456')
proxy = Proxy(address, credentials=credentials)
ds = []

d = proxy.callRemote('echo', ['ajajaj', 'bjbjbj'])
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('add', 14, 15)
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('mysql_first_user')
d.addCallbacks(printValue, printError)
ds.append(d)

d = proxy.callRemote('none')
예제 #32
0
 def test_init_agent(self):
     proxy = Proxy('', '', contextFactory=WebClientContextFactory())
     self.assertTrue(isinstance(proxy.agent, Agent))
     self.assertTrue(
         isinstance(proxy.agent._contextFactory, ssl.ClientContextFactory))
예제 #33
0
    def test_init_agent(self):
        proxy = Proxy('', '')

        self.assertTrue(isinstance(proxy.agent, Agent))