Esempio n. 1
0
    def test_coroutine_function_ok(self):
        """
        Remlote Coroutine Call RCC
        """
        from aioxmlrpc.server import SimpleXMLRPCServer
        @asyncio.coroutine
        def info():
            yield from asyncio.sleep(1)
            return 'ok_return_from_info_coroutine'

        server = SimpleXMLRPCServer()
        server.register_function(info)

        handler = server.request_handler()

        class Mock:
            def __init__(self):
                self.data = b''

            def write(self, data):
                self.data += data

            @asyncio.coroutine
            def drain(self, *args, **kwargs):
                pass

        handler.writer = Mock()
        asyncio.get_event_loop().run_until_complete(asyncio.gather(
            handler.handle_request(**request_info())
        ))

        self.assertTrue(b"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><string>ok_return_from_info_coroutine</string></value>\n</param>\n</params>\n</methodResponse>\n" in handler.writer.data)
Esempio n. 2
0
    def test_dispatcher_coroutines(self):
        from aioxmlrpc.server import SimpleXMLRPCServer
        class Api:
            @asyncio.coroutine
            def _dispatch(self, name, *args):
                yield from asyncio.sleep(1)
                return 'ok_return_from_dispatcher_%s' % name

        server = SimpleXMLRPCServer()
        server.register_instance(Api())

        handler = server.request_handler()

        class Mock:
            def __init__(self):
                self.data = b''

            def write(self, data):
                self.data += data

            @asyncio.coroutine
            def drain(self, *args, **kwargs):
                pass

        handler.writer = Mock()
        asyncio.get_event_loop().run_until_complete(asyncio.gather(
            handler.handle_request(**request_info())
        ))

        self.assertTrue(
            b"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><string>ok_return_from_dispatcher_info</string></value>\n</param>\n</params>\n</methodResponse>\n" in handler.writer.data)
Esempio n. 3
0
    def test_unknown_function_ok(self):
        """
        test error case
        """
        from aioxmlrpc.server import SimpleXMLRPCServer
        def not_info():
            return 'ok_return_from_info'

        server = SimpleXMLRPCServer()
        server.register_function(not_info)

        handler = server.request_handler()
        class Mock:
            def __init__(self):
                self.data = b''
            def write(self, data):
                self.data += data
            @asyncio.coroutine
            def drain(self, *args, **kwargs):
                pass

        handler.writer = Mock()
        asyncio.get_event_loop().run_until_complete(asyncio.gather(
           handler.handle_request(**request_info())
        ))

        self.assertTrue(b"method \"info\" is not supported" in handler.writer.data)
Esempio n. 4
0
    def test_instance(self):
        """
        Use an object to keep context
        """
        from aioxmlrpc.server import SimpleXMLRPCServer
        class Api:
            def info(self):
                return 'ok_return_from_api_instance'

        server = SimpleXMLRPCServer()
        server.register_instance(Api())

        handler = server.request_handler()

        class Mock:
            def __init__(self):
                self.data = b''

            def write(self, data):
                self.data += data

            @asyncio.coroutine
            def drain(self, *args, **kwargs):
                pass

        handler.writer = Mock()
        asyncio.get_event_loop().run_until_complete(asyncio.gather(
            handler.handle_request(**request_info())
        ))

        self.assertTrue(
            b"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><string>ok_return_from_api_instance</string></value>\n</param>\n</params>\n</methodResponse>\n" in handler.writer.data)