Exemplo n.º 1
0
    def test_callRemoteV2Ok(self):
        string = 'some rubbish'

        proxy = Proxy(self.addr, '2.0')
        d = proxy.callRemote('echo', string)
        d.addCallback(self.assertEquals, string)
        return d
Exemplo n.º 2
0
    def test_callRemoteV2Ok(self):
        string = 'some rubbish'

        proxy = Proxy(self.addr, '2.0')
        d = proxy.callRemote('echo', string)
        d.addCallback(self.assertEquals, string)
        return d
Exemplo n.º 3
0
    def test_keywordsV1(self):
        data = 'some random string'

        proxy = Proxy(self.addr, jsonrpc.VERSION_1)
        d = proxy.callRemote('echo', data=data)

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

        d.addCallback(finished)
        return d
Exemplo n.º 4
0
    def test_keywordsV1(self):
        data = 'some random string'

        proxy = Proxy(self.addr, jsonrpc.VERSION_1)
        d = proxy.callRemote('echo', data=data)

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

        d.addCallback(finished)
        return d
Exemplo n.º 5
0
    def test_callRemoteNoMethod(self):
        proxy = Proxy(self.addr)
        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
Exemplo n.º 6
0
    def test_callRemoteNoMethod(self):
        proxy = Proxy(self.addr)
        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
Exemplo n.º 7
0
    def test_callRemoteV2InvalidParams(self):
        proxy = Proxy(self.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, jsonrpc.VERSION_2)

        e.addCallback(finished)
        return e
Exemplo n.º 8
0
    def test_callRemoteV2InvalidParams(self):
        proxy = Proxy(self.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
Exemplo n.º 9
0
    def test_keywordsUnexpected(self):
        data = 'some random string'

        proxy = Proxy(self.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
Exemplo n.º 10
0
    def test_keywordsUnexpected(self):
        data = 'some random string'

        proxy = Proxy(self.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
Exemplo n.º 11
0
    def test_init(self):
        hostname = 'example.com'
        port = 8111
        url = '%s:%s' % (hostname, port)
        version = '2.0'
        timeout = 40
        verbose = True

        proxy = Proxy(url, version, timeout, verbose)
        self.assertEquals(proxy.hostname, hostname)
        self.assertEquals(proxy.port, port)
        self.assertEquals(proxy.version, version)
        self.assertEquals(proxy.timeout, timeout)
        self.assertEquals(proxy.verbose, verbose)
Exemplo n.º 12
0
    print "Result: %s" % str(value)


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


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


log.startLogging(sys.stdout)

dl = []
proxy = Proxy('127.0.0.1:8999', verbose=True)

d = proxy.callRemote('none')
d.addCallbacks(printValue, printError)
dl.append(d)

d = proxy.callRemote('none')
d.addCallbacks(printValue, printError)
dl.append(d)

d = proxy.callRemote('echo', 123)
d.addCallbacks(printValue, printError)
dl.append(d)

dl = defer.DeferredList(dl)
dl.addCallback(shutDown)