Esempio n. 1
0
    def test_multiple_return_sd_0(self):
        class SomeService(ServiceBase):
            @srpc(_returns=Iterable(Integer))
            def some_call():
                return 1, 2

        app = Application([SomeService], 'tns', JsonObject(), JsonObject(),
                                                                       Wsdl11())

        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call":{}}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"integer": [1, 2]}}}' ]

        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call":[]}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"integer": [1, 2]}}}']
Esempio n. 2
0
    def test_multiple_return(self):
        class SomeNotSoComplexModel(ComplexModel):
            s = String

        class SomeService(ServiceBase):
            @srpc(_returns=[Integer, String])
            def some_call():
                return 1, 's'

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': '',
            'PATH_INFO': '/some_call',
            'QUERY_STRING': '?s=a',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        try:
            ctx, = server.generate_contexts(initial_ctx)
            server.get_in_object(ctx)
            server.get_out_object(ctx)
            server.get_out_string(ctx)
        except ValueError:
            pass
        else:
            raise Exception("Must fail with: HttpRpc does not support complex "
                "return types.")
Esempio n. 3
0
    def test_complex(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=CCM)
            def some_call(ccm):
                return CCM(c=ccm.c, i=ccm.i, s=ccm.s)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': '',
            'PATH_INFO': '/some_call',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)
Esempio n. 4
0
    def test_complex(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=CCM)
            def some_call(ccm):
                return CCM(c=ccm.c,i=ccm.i, s=ccm.s)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': '',
            'PATH_INFO': '/some_call',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)
Esempio n. 5
0
    def test_multiple_return(self):
        class SomeNotSoComplexModel(ComplexModel):
            s = String

        class SomeService(ServiceBase):
            @srpc(_returns=[Integer, String])
            def some_call():
                return 1, 's'

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': '',
            'PATH_INFO': '/some_call',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        try:
            ctx, = server.generate_contexts(initial_ctx)
            server.get_in_object(ctx)
            server.get_out_object(ctx)
            server.get_out_string(ctx)
        except ValueError:
            pass
        else:
            raise Exception("Must Fail")
Esempio n. 6
0
    def test_complex(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=CCM)
            def some_call(ccm):
                return CCM(c=ccm.c, i=ccm.i, s=ccm.s)

        app = Application([SomeService], 'tns', JsonObject(), JsonObject(),
                                                                       Wsdl11())
        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call":{"ccm": {"c":{"i":3, "s": "3x"}, "i":4, "s": "4x"}}}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        ret = json.loads(''.join(ctx.out_string))
        print ret

        assert ret['some_callResponse']['some_callResult']['i'] == 4
        assert ret['some_callResponse']['some_callResult']['s'] == '4x'
        assert ret['some_callResponse']['some_callResult']['c']['i'] == 3
        assert ret['some_callResponse']['some_callResult']['c']['s'] == '3x'
Esempio n. 7
0
    def test_multiple(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=String)
            def some_call(s):
                return '\n'.join(s)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': 's=1&s=2',
            'PATH_INFO': '/some_call',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert ctx.out_string == ['1\n2']
Esempio n. 8
0
    def test_primitive_only(self):
        class SomeComplexModel(ComplexModel):
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(SomeComplexModel, _returns=SomeComplexModel)
            def some_call(scm):
                return SomeComplexModel(i=5, s='5x')

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': '',
            'PATH_INFO': '/some_call',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        print "!", ctx.in_object
        server.get_out_object(ctx)

        try:
            server.get_out_string(ctx)
        except:
            pass
        else:
            raise Exception("Must Fail")
Esempio n. 9
0
    def test_multiple_return(self):
        class SomeNotSoComplexModel(ComplexModel):
            s = String

        class SomeService(ServiceBase):
            @srpc(_returns=[Integer, String])
            def some_call():
                return 1, 's'

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HtmlMicroFormat())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': '',
            'PATH_INFO': '/some_call',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert ''.join(ctx.out_string) == '<div class="some_callResponse"><div class="some_callResult0">1</div><div class="some_callResult1">s</div></div>'
Esempio n. 10
0
    def test_simple(self):
        class SomeService(ServiceBase):
            @srpc(String, _returns=String)
            def some_call(s):
                return s

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HtmlMicroFormat())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': 's=s',
            'PATH_INFO': '/some_call',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)
        assert ctx.in_error is None

        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert ''.join(ctx.out_string) == '<div class="some_callResponse"><div class="some_callResult">s</div></div>'
Esempio n. 11
0
    def test_primitive_only(self):
        class SomeComplexModel(ComplexModel):
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(SomeComplexModel, _returns=SomeComplexModel)
            def some_call(scm):
                return SomeComplexModel(i=5, s='5x')

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': '',
            'PATH_INFO': '/some_call',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        print "!", ctx.in_object
        server.get_out_object(ctx)

        try:
            server.get_out_string(ctx)
        except:
            pass
        else:
            raise Exception("Must Fail")
Esempio n. 12
0
    def test_invalid_input(self):
        class SomeService(ServiceBase):
            @srpc()
            def yay():
                pass

        app = Application([SomeService], 'tns', JsonObject(), JsonObject(), Wsdl11())
        server = ServerBase(app)

        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call": {"yay": ]}}']
        ctx, = server.generate_contexts(initial_ctx)
        assert ctx.in_error.faultcode == 'Client.JsonDecodeError'
Esempio n. 13
0
    def test_invalid_request(self):
        class SomeService(ServiceBase):
            @srpc(Integer, String, DateTime)
            def yay(i,s,d):
                print i,s,d
                pass

        app = Application([SomeService], 'tns', JsonObject(validator='soft'), JsonObject(), Wsdl11())
        server = ServerBase(app)

        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call": {"yay": []}}']
        ctx, = server.generate_contexts(initial_ctx)
        print ctx.in_error
        assert ctx.in_error.faultcode == 'Client.ResourceNotFound'
        print
Esempio n. 14
0
    def test_invalid_number(self):
        class SomeService(ServiceBase):
            @srpc(Integer, String, DateTime)
            def yay(i,s,d):
                print i,s,d
                pass

        app = Application([SomeService], 'tns', JsonObject(validator='soft'),
                                                         JsonObject(), Wsdl11())
        server = ServerBase(app)

        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"yay": ["s", "B"]}']
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)

        assert ctx.in_error.faultcode == 'Client.ValidationError'
Esempio n. 15
0
    def test_multiple_dict_array(self):
        class SomeService(ServiceBase):
            @srpc(Iterable(String), _returns=Iterable(String))
            def some_call(s):
                return s

        app = Application([SomeService], 'tns', JsonObject(), JsonObject(), Wsdl11())
        server = ServerBase(app)

        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call":{"s":["a","b"]}}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"string": ["a", "b"]}}}']
Esempio n. 16
0
    def test_missing_value(self):
        class SomeService(ServiceBase):
            @srpc(Integer, String, Mandatory.DateTime)
            def yay(i,s,d):
                print i,s,d
                pass

        app = Application([SomeService], 'tns', JsonObject(validator='soft'),
                                                         JsonObject(), Wsdl11())
        server = ServerBase(app)

        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"yay": [1, "B"]}']
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)

        print ctx.in_error.faultstring
        assert ctx.in_error.faultcode == 'Client.ValidationError'
        assert ctx.in_error.faultstring.endswith("frequency constraints.")
Esempio n. 17
0
    def test_multiple_dict_complex_array(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        class ECM(CCM):
            d = DateTime

        class SomeService(ServiceBase):
            @srpc(Iterable(ECM), _returns=Iterable(ECM))
            def some_call(ecm):
                return ecm

        app = Application([SomeService], 'tns', JsonObject(), JsonObject(), Wsdl11())
        server = ServerBase(app)

        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call": {"ecm": [{"c": {"i":3, "s": "3x"}, "i":4, "s": "4x", "d": "2011-12-13T14:15:16Z"}]}}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        print ctx.in_object
        server.get_out_string(ctx)

        ret = json.loads(''.join(ctx.out_string))
        print ret
        assert ret['some_callResponse']
        assert ret['some_callResponse']['some_callResult']
        assert ret['some_callResponse']['some_callResult']['ECM']
        assert ret['some_callResponse']['some_callResult']['ECM'][0]
        assert ret['some_callResponse']['some_callResult']['ECM'][0]["c"]
        assert ret['some_callResponse']['some_callResult']['ECM'][0]["c"]["i"] == 3
        assert ret['some_callResponse']['some_callResult']['ECM'][0]["c"]["s"] == "3x"
        assert ret['some_callResponse']['some_callResult']['ECM'][0]["i"] == 4
        assert ret['some_callResponse']['some_callResult']['ECM'][0]["s"] == "4x"
        assert ret['some_callResponse']['some_callResult']['ECM'][0]["d"] == "2011-12-13T14:15:16+00:00"
Esempio n. 18
0
    def test_nested_flatten(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=String)
            def some_call(ccm):
                return repr(ccm)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': 'ccm_i=1&ccm_s=s&ccm_c_i=3&ccm_c_s=cs',
            'PATH_INFO': '/some_call',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)

        server.get_in_object(ctx)
        assert ctx.in_error is None

        server.get_out_object(ctx)
        assert ctx.out_error is None

        server.get_out_string(ctx)

        print ctx.out_string
        assert ctx.out_string == ["CCM(i=1, c=CM(i=3, s='cs'), s='s')"]
Esempio n. 19
0
    def test_nested_flatten(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=String)
            def some_call(ccm):
                return repr(ccm)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(
            app, {
                'QUERY_STRING': 'ccm_i=1&ccm_s=s&ccm_c_i=3&ccm_c_s=cs',
                'PATH_INFO': '/some_call',
            }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)

        server.get_in_object(ctx)
        assert ctx.in_error is None

        server.get_out_object(ctx)
        assert ctx.out_error is None

        server.get_out_string(ctx)

        print ctx.out_string
        assert ctx.out_string == ["CCM(i=1, c=CM(i=3, s='cs'), s='s')"]
Esempio n. 20
0
    def test_nested_flatten_with_multiple_values_2(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM.customize(max_occurs=2)
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=String)
            def some_call(ccm):
                return repr(ccm)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(
            app, {
                'QUERY_STRING': 'ccm_i=1&ccm_s=s&ccm_c_i=3&ccm_c_s=cs',
                'PATH_INFO': '/some_call',
            }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)

        try:
            server.get_in_object(ctx)
        except:
            pass
        else:
            raise Exception(
                "Must fail with: Exception: HttpRpc deserializer "
                "does not support non-primitives with max_occurs > 1")
Esempio n. 21
0
    def test_primitive_only(self):
        class SomeComplexModel(ComplexModel):
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(SomeComplexModel, _returns=SomeComplexModel)
            def some_call(scm):
                return SomeComplexModel(i=5, s='5x')

        app = Application([SomeService], 'tns', JsonObject(), JsonObject(),
                                                                       Wsdl11())

        server = ServerBase(app)
        initial_ctx = MethodContext(server)
        initial_ctx.in_string = ['{"some_call":[]}']

        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert list(ctx.out_string) == ['{"some_callResponse": {"some_callResult": {"i": 5, "s": "5x"}}}']
Esempio n. 22
0
    def test_nested_flatten_with_multiple_values_2(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM.customize(max_occurs=2)
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=String)
            def some_call(ccm):
                return repr(ccm)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': 'ccm_i=1&ccm_s=s&ccm_c_i=3&ccm_c_s=cs',
            'PATH_INFO': '/some_call',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)

        try:
            server.get_in_object(ctx)
        except:
            pass
        else:
            raise Exception("Must fail with: Exception: HttpRpc deserializer "
                        "does not support non-primitives with max_occurs > 1")
Esempio n. 23
0
    def test_multiple(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=String)
            def some_call(s):
                return '\n'.join(s)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HttpRpc())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': 's=1&s=2',
            'PATH_INFO': '/some_call',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        assert ctx.out_string == ['1\n2']
Esempio n. 24
0
    def test_complex(self):
        class CM(ComplexModel):
            i = Integer
            s = String

        class CCM(ComplexModel):
            c = CM
            i = Integer
            s = String

        class SomeService(ServiceBase):
            @srpc(CCM, _returns=CCM)
            def some_call(ccm):
                return CCM(c=ccm.c,i=ccm.i, s=ccm.s)

        app = Application([SomeService], 'tns', Wsdl11(), HttpRpc(), HtmlMicroFormat())

        from rpclib.server.wsgi import WsgiMethodContext

        initial_ctx = WsgiMethodContext(app, {
            'QUERY_STRING': 'ccm_c_s=abc&ccm_c_i=123&ccm_i=456&ccm_s=def',
            'PATH_INFO': '/some_call',
            'REQUEST_METHOD': 'GET',
        }, 'some-content-type')

        from rpclib.server import ServerBase

        server = ServerBase(app)
        ctx, = server.generate_contexts(initial_ctx)
        server.get_in_object(ctx)
        server.get_out_object(ctx)
        server.get_out_string(ctx)

        #
        # Here's what this is supposed to return:
        #
        # <div class="some_callResponse">
        #   <div class="some_callResult">
        #     <div class="i">456</div>
        #     <div class="c">
        #       <div class="i">123</div>
        #       <div class="s">abc</div>
        #     </div>
        #     <div class="s">def</div>
        #   </div>
        # </div>
        #

        elt = html.fromstring(''.join(ctx.out_string))
        resp = elt.find_class('some_callResponse')
        assert len(resp) == 1
        res = resp[0].find_class('some_callResult')
        assert len(res) == 1

        i = res[0].findall('div[@class="i"]')
        assert len(i) == 1
        assert i[0].text == '456'

        c = res[0].findall('div[@class="c"]')
        assert len(c) == 1

        c_i = c[0].findall('div[@class="i"]')
        assert len(c_i) == 1
        assert c_i[0].text == '123'

        c_s = c[0].findall('div[@class="s"]')
        assert len(c_s) == 1
        assert c_s[0].text == 'abc'

        s = res[0].findall('div[@class="s"]')
        assert len(s) == 1
        assert s[0].text == 'def'