Esempio n. 1
0
    def test_string_array(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
            out_protocol=HtmlRowTable(field_name_attr=None,
                                                     field_type_name_attr=None))
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')) )
        show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array')
        assert out_string.decode('utf8') == \
            '<div>' \
              '<table class="some_callResponse">' \
                '<tr>' \
                  '<th>string</th>' \
                  '<td>' \
                    '<table>' \
                      '<tr>' \
                        '<td>1</td>' \
                      '</tr>' \
                      '<tr>' \
                        '<td>2</td>' \
                      '</tr>' \
                    '</table>' \
                  '</td>' \
                '</tr>' \
              '</table>' \
            '</div>'
Esempio n. 2
0
    def test_string_array(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService],
                          'tns',
                          in_protocol=HttpRpc(),
                          out_protocol=HtmlRowTable(field_name_attr=None,
                                                    field_type_name_attr=None))
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')))
        show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array')
        assert out_string.decode('utf8') == \
            '<div>' \
              '<table class="some_callResponse">' \
                '<tr>' \
                  '<th>string</th>' \
                  '<td>' \
                    '<table>' \
                      '<tr>' \
                        '<td>1</td>' \
                      '</tr>' \
                      '<tr>' \
                        '<td>2</td>' \
                      '</tr>' \
                    '</table>' \
                  '</td>' \
                '</tr>' \
              '</table>' \
            '</div>'
Esempio n. 3
0
    def test_string_array_no_header(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs="unbounded"), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService], "tns", in_protocol=HttpRpc(), out_protocol=HtmlRowTable(header=False))
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(("s", "1"), ("s", "2")))
        # FIXME: Needs a proper test with xpaths and all.
        show(html.fromstring(out_string), "TestHtmlRowTable.test_string_array_no_header")
        assert (
            out_string == "<div>"
            '<table class="some_callResponse">'
            "<tr>"
            "<td>"
            "<table>"
            "<tr>"
            "<td>1</td>"
            "</tr>"
            "<tr>"
            "<td>2</td>"
            "</tr>"
            "</table>"
            "</td>"
            "</tr>"
            "</table>"
            "</div>"
        )
Esempio n. 4
0
def _test_type(cls, inst):
    from spyne.util import appreg
    appreg._applications.clear()

    class SomeService(ServiceBase):
        @rpc(_returns=cls, _body_style='bare')
        def some_call(ctx):
            return inst

    prot = HtmlForm(cloth=T_TEST)
    app = Application([SomeService], 'some_ns', out_protocol=prot)

    null = NullServer(app, ostr=True)

    ret = ''.join(null.service.some_call())
    try:
        elt = html.fromstring(ret)
    except:
        print(ret)
        raise

    show(elt, stdout=False)
    elt = elt.xpath('//*[@spyne]')[0][
        0]  # get the form tag inside the body tag
    elt = strip_ns(elt)  # get rid of namespaces to simplify xpaths in tests

    print(etree.tostring(elt, pretty_print=True))

    return elt
Esempio n. 5
0
def _test_type(cls, inst, prot_cls=HtmlFormTable):
    from spyne.util import appreg; appreg._applications.clear()

    class SomeService(ServiceBase):
        @rpc(_returns=cls, _body_style='bare')
        def some_call(ctx):
            return inst

    prot = prot_cls(cloth=T_TEST, doctype='<!DOCTYPE html>')
    app = Application([SomeService], 'some_ns', out_protocol=prot)

    null = NullServer(app, ostr=True)

    ret = ''.join(null.service.some_call())
    try:
        elt = html.fromstring(ret)
    except:
        print(ret)
        raise

    show(elt)
    elt = elt.xpath('//form')[0]
    elt = strip_ns(elt)  # get rid of namespaces to simplify xpaths in tests

    print(R("========== fragment =========="))
    print(etree.tostring(elt, pretty_print=True))
    print(R("========== fragment =========="))

    return elt
Esempio n. 6
0
    def test_string_array_no_header(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
                out_protocol=HtmlRowTable(produce_header=False))
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')) )
        #FIXME: Needs a proper test with xpaths and all.
        show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array_no_header')
        assert out_string == \
            '<div>' \
              '<table class="some_callResponse">' \
                '<tr>' \
                  '<td>' \
                    '<table>' \
                      '<tr>' \
                        '<td>1</td>' \
                      '</tr>' \
                      '<tr>' \
                        '<td>2</td>' \
                      '</tr>' \
                    '</table>' \
                  '</td>' \
                '</tr>' \
              '</table>' \
            '</div>'
Esempio n. 7
0
    def test_complex_array(self):
        class CM(ComplexModel):
            i = Integer
            s = String

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

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

        app = Application([SomeService],
                          'tns',
                          in_protocol=HttpRpc(hier_delim='_'),
                          out_protocol=HtmlMicroFormat())
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server,
                                          ccm_c_s='abc',
                                          ccm_c_i=123,
                                          ccm_i=456,
                                          ccm_s='def')

        #
        # Here's what this is supposed to return:
        #
        # <div class="some_callResponse"><div class="some_callResult">
        #     <div class="CCM">
        #         <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 class="CCM">
        #         <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></div>
        #

        print(out_string)
        elt = html.fromstring(''.join(out_string))
        show(elt, "TestHtmlMicroFormat.test_complex_array")

        resp = elt.find_class('some_callResponse')
        assert len(resp) == 1
        res = resp[0].find_class('some_callResult')
        assert len(res) == 1

        assert len(res[0].find_class("CCM")) == 2
Esempio n. 8
0
def _test_type(cls, inst):
    # silence bogus warnings
    from spyne.util import appreg; appreg.applications.clear()

    class SomeService(ServiceBase):
        @rpc(_returns=cls, _body_style='bare')
        def some_call(ctx):
            return inst

    prot = HtmlForm(cloth=T_TEST)
    app = Application([SomeService], 'some_ns', out_protocol=prot)

    null = NullServer(app, ostr=True)

    ret = ''.join(null.service.some_call())
    try:
        elt = html.fromstring(ret)
    except:
        print(ret)
        raise

    show(elt, stdout=False)
    elt = elt.xpath('//form')[0]  # get the form tag inside the body tag
    elt = strip_ns(elt)  # get rid of namespaces to simplify xpaths in tests

    print(etree.tostring(elt, pretty_print=True))

    return elt
    def test_string_array_no_header(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService],
                          'tns',
                          in_protocol=HttpRpc(),
                          out_protocol=HtmlRowTable(header=False))
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')))
        #FIXME: Needs a proper test with xpaths and all.
        show(html.fromstring(out_string),
             'TestHtmlRowTable.test_string_array_no_header')
        assert out_string == \
            '<div>' \
              '<table class="some_callResponse">' \
                '<tr>' \
                  '<td>' \
                    '<table>' \
                      '<tr>' \
                        '<td>1</td>' \
                      '</tr>' \
                      '<tr>' \
                        '<td>2</td>' \
                      '</tr>' \
                    '</table>' \
                  '</td>' \
                '</tr>' \
              '</table>' \
            '</div>'
Esempio n. 10
0
    def test_string_array(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
                                                    out_protocol=HtmlRowTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')) )
        show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array')
        assert out_string == \
            '<div xmlns="http://www.w3.org/1999/xhtml">' \
              '<table xmlns="http://www.w3.org/1999/xhtml" class="some_callResponse">' \
                '<tr>' \
                  '<th>string</th>' \
                  '<td>' \
                    '<table>' \
                      '<tr>' \
                        '<td>1</td>' \
                      '</tr>' \
                      '<tr>' \
                        '<td>2</td>' \
                      '</tr>' \
                    '</table>' \
                  '</td>' \
                '</tr>' \
              '</table>' \
            '</div>'
Esempio n. 11
0
    def test_string_array(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService],
                          'tns',
                          in_protocol=HttpRpc(),
                          out_protocol=HtmlRowTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')))
        show(html.fromstring(out_string), 'TestHtmlRowTable.test_string_array')
        assert out_string == \
            '<div xmlns="http://www.w3.org/1999/xhtml">' \
              '<table xmlns="http://www.w3.org/1999/xhtml" class="some_callResponse">' \
                '<tr>' \
                  '<th>string</th>' \
                  '<td>' \
                    '<table>' \
                      '<tr>' \
                        '<td>1</td>' \
                      '</tr>' \
                      '<tr>' \
                        '<td>2</td>' \
                      '</tr>' \
                    '</table>' \
                  '</td>' \
                '</tr>' \
              '</table>' \
            '</div>'
Esempio n. 12
0
    def test_complex_array(self):
        class CM(ComplexModel):
            i = Integer
            s = String

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

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

        app = Application([SomeService], 'tns',
                                            in_protocol=HttpRpc(hier_delim='_'),
                                            out_protocol=HtmlMicroFormat())
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server,
                             ccm_c_s='abc', ccm_c_i=123, ccm_i=456, ccm_s='def')

        #
        # Here's what this is supposed to return:
        #
        # <div class="some_callResponse"><div class="some_callResult">
        #     <div class="CCM">
        #         <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 class="CCM">
        #         <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></div>
        #

        print(out_string)
        elt = html.fromstring(out_string)
        show(elt, "TestHtmlMicroFormat.test_complex_array")

        resp = elt.find_class('some_callResponse')
        assert len(resp) == 1
        res = resp[0].find_class('some_callResult')
        assert len(res) == 1

        assert len(res[0].find_class("CCM")) == 2
Esempio n. 13
0
    def test_complex_array(self):
        class SomeService(ServiceBase):
            @srpc(CCM, _returns=Array(CCM))
            def some_call(ccm):
                return [ccm] * 5

        app = Application(
            [SomeService],
            'tns',
            in_protocol=HttpRpc(),
            out_protocol=HtmlColumnTable(field_name_attr='class'))
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(
            server,
            ccm_i='456',
            ccm_s='def',
            ccm_c_i='123',
            ccm_c_s='abc',
        )

        elt = etree.fromstring(out_string)
        show(elt, 'TestHtmlColumnTable.test_complex_array')

        elt = html.fromstring(out_string)

        row, = elt[0]  # thead
        cell = row.findall('th[@class="i"]')
        assert len(cell) == 1
        assert cell[0].text == 'i'

        cell = row.findall('th[@class="s"]')
        assert len(cell) == 1
        assert cell[0].text == 's'

        for row in elt[1]:  # tbody
            cell = row.xpath('td[@class="i"]')
            assert len(cell) == 1
            assert cell[0].text == '456'

            cell = row.xpath('td[@class="c"]//td[@class="i"]')
            assert len(cell) == 1
            assert cell[0].text == '123'

            cell = row.xpath('td[@class="c"]//td[@class="s"]')
            assert len(cell) == 1
            assert cell[0].text == 'abc'

            cell = row.xpath('td[@class="s"]')
            assert len(cell) == 1
            assert cell[0].text == 'def'
Esempio n. 14
0
def _test_type_no_root_cloth(cls, inst):
    from spyne.util import appreg; appreg.applications.clear()

    class SomeService(ServiceBase):
        @rpc(_returns=cls, _body_style='bare')
        def some_call(ctx):
            return inst

    prot = HtmlForm()
    app = Application([SomeService], 'some_ns', out_protocol=prot)

    null = NullServer(app, ostr=True)
    elt = etree.fromstring(''.join(null.service.some_call()))
    show(elt)

    return elt
Esempio n. 15
0
    def test_complex_array(self):
        class SomeService(ServiceBase):
            @srpc(CCM, _returns=Array(CCM))
            def some_call(ccm):
                return [ccm] * 5

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
                        out_protocol=HtmlColumnTable(field_name_attr='class'))
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server,
                ccm_i='456',
                ccm_s='def',
                ccm_c_i='123',
                ccm_c_s='abc',
            )

        elt = etree.fromstring(out_string)
        show(elt, 'TestHtmlColumnTable.test_complex_array')

        elt = html.fromstring(out_string)

        row, = elt[0] # thead
        cell = row.findall('th[@class="i"]')
        assert len(cell) == 1
        assert cell[0].text == 'i'

        cell = row.findall('th[@class="s"]')
        assert len(cell) == 1
        assert cell[0].text == 's'

        for row in elt[1]: # tbody
            cell = row.xpath('td[@class="i"]')
            assert len(cell) == 1
            assert cell[0].text == '456'

            cell = row.xpath('td[@class="c"]//td[@class="i"]')
            assert len(cell) == 1
            assert cell[0].text == '123'

            cell = row.xpath('td[@class="c"]//td[@class="s"]')
            assert len(cell) == 1
            assert cell[0].text == 'abc'

            cell = row.xpath('td[@class="s"]')
            assert len(cell) == 1
            assert cell[0].text == 'def'
Esempio n. 16
0
def _test_type_no_root_cloth(cls, inst):
    from spyne.util import appreg
    appreg._applications.clear()

    class SomeService(ServiceBase):
        @rpc(_returns=cls, _body_style='bare')
        def some_call(ctx):
            return inst

    prot = HtmlForm()
    app = Application([SomeService], 'some_ns', out_protocol=prot)

    null = NullServer(app, ostr=True)
    elt = etree.fromstring(''.join(null.service.some_call()))
    show(elt)

    return elt
Esempio n. 17
0
    def test_string_array(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs="unbounded"), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService], "tns", in_protocol=HttpRpc(), out_protocol=HtmlColumnTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(("s", "1"), ("s", "2")))
        elt = etree.fromstring(out_string)
        show(elt, "TestHtmlColumnTable.test_string_array")
        assert (
            out_string == '<table class="string">'
            '<thead><tr><th class="some_callResponse">some_callResponse</th></tr></thead>'
            "<tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody>"
            "</table>"
        )
Esempio n. 18
0
    def test_string_array(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
                                               out_protocol=HtmlColumnTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')))
        elt = etree.fromstring(out_string)
        show(elt, "TestHtmlColumnTable.test_string_array")
        assert out_string == \
            '<table xmlns="http://www.w3.org/1999/xhtml" class="string">' \
                '<thead><tr><th class="some_callResponse">some_callResponse</th></tr></thead>' \
                '<tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody>' \
            '</table>'
Esempio n. 19
0
    def test_string_array(self):
        class SomeService(ServiceBase):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService],
                          'tns',
                          in_protocol=HttpRpc(),
                          out_protocol=HtmlColumnTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')))
        elt = etree.fromstring(out_string)
        show(elt, "TestHtmlColumnTable.test_string_array")
        assert out_string == \
            '<table class="string">' \
                '<thead><tr><th class="some_callResponse">some_callResponse</th></tr></thead>' \
                '<tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody>' \
            '</table>'
Esempio n. 20
0
def _test_type(cls, inst):
    from spyne.util import appreg; appreg._applications.clear()

    class SomeService(ServiceBase):
        @rpc(_returns=cls, _body_style='bare')
        def some_call(ctx):
            return inst

    prot = HtmlFormTable(cloth=T_TEST)
    app = Application([SomeService], 'some_ns', out_protocol=prot)

    null = NullServer(app, ostr=True)

    elt = etree.fromstring(''.join(null.service.some_call()))
    show(elt, stdout=False)
    elt = elt.xpath('//*[@spyne]')[0]
    elt = strip_ns(elt)  # get rid of namespaces to simplify xpaths in tests

    print(etree.tostring(elt, pretty_print=True))

    return elt
Esempio n. 21
0
    def test_anyuri_string(self):
        _link = "http://arskom.com.tr/"

        class C(ComplexModel):
            c = AnyUri

        class SomeService(ServiceBase):
            @srpc(_returns=Array(C))
            def some_call():
                return [C(c=_link)]

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
                 out_protocol=HtmlColumnTable(field_name_attr='class'))
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server)

        elt = html.fromstring(out_string)
        show(elt, "TestHtmlColumnTable.test_anyuri_string")
        assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a'
        assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link
Esempio n. 22
0
    def test_anyuri_string(self):
        _link = "http://arskom.com.tr/"

        class C(ComplexModel):
            c = AnyUri

        class SomeService(ServiceBase):
            @srpc(_returns=Array(C))
            def some_call():
                return [C(c=_link)]

        app = Application(
            [SomeService],
            'tns',
            in_protocol=HttpRpc(),
            out_protocol=HtmlColumnTable(field_name_attr='class'))
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server)

        elt = html.fromstring(out_string)
        show(elt, "TestHtmlColumnTable.test_anyuri_string")
        assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a'
        assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link
Esempio n. 23
0
    def test_string_array(self):
        class SomeService(Service):
            @srpc(String(max_occurs='unbounded'), _returns=Array(String))
            def some_call(s):
                return s

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
                        out_protocol=HtmlColumnTable(
                            field_name_attr=None, field_type_name_attr=None))
        server = WsgiApplication(app)

        out_string = call_wsgi_app(server, body_pairs=(('s', '1'), ('s', '2')))
        elt = etree.fromstring(out_string)
        show(elt, "TestHtmlColumnTable.test_string_array")
        assert out_string.decode('utf8') == \
          '<table class="string">' \
            '<thead>' \
              '<tr><th>some_callResponse</th></tr>' \
            '</thead>' \
            '<tbody>' \
              '<tr><td>1</td></tr>' \
              '<tr><td>2</td></tr>' \
            '</tbody>' \
          '</table>'
Esempio n. 24
0
    def test_complex_array(self):
        v = [
            CM(i=1, s='a'),
            CM(i=2, s='b'),
            CM(i=3, s='c'),
            CM(i=4, s='d'),
        ]

        class SomeService(ServiceBase):
            @srpc(_returns=Array(CM))
            def some_call():
                return v

        app = Application([SomeService],
                          'tns',
                          in_protocol=HttpRpc(),
                          out_protocol=HtmlRowTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server)
        show(html.fromstring(out_string),
             'TestHtmlRowTable.test_complex_array')
        #FIXME: Needs a proper test with xpaths and all.
        assert out_string == \
            '<div>' \
              '<table class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">1</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">a</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
              '<table class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">2</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">b</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
              '<table class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">3</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">c</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
              '<table class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">4</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">d</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
            '</div>'
Esempio n. 25
0
    def test_complex_array(self):
        v = [
            CM(i=1, s='a'),
            CM(i=2, s='b'),
            CM(i=3, s='c'),
            CM(i=4, s='d'),
        ]
        class SomeService(ServiceBase):
            @srpc(_returns=Array(CM))
            def some_call():
                return v

        app = Application([SomeService], 'tns', in_protocol=HttpRpc(),
                out_protocol=HtmlRowTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server)
        show(html.fromstring(out_string), 'TestHtmlRowTable.test_complex_array')
        #FIXME: Needs a proper test with xpaths and all.
        assert out_string == \
            '<div xmlns="http://www.w3.org/1999/xhtml">' \
              '<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">1</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">a</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
              '<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">2</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">b</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
              '<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">3</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">c</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
              '<table xmlns="http://www.w3.org/1999/xhtml" class="CM">' \
                '<tbody>' \
                  '<tr>' \
                    '<th class="i">i</th>' \
                    '<td class="i">4</td>' \
                  '</tr>' \
                  '<tr>' \
                    '<th class="s">s</th>' \
                    '<td class="s">d</td>' \
                  '</tr>' \
                '</tbody>' \
              '</table>' \
            '</div>'
Esempio n. 26
0
    def test_complex(self):
        class SomeService(ServiceBase):
            @srpc(CCM, _returns=CCM)
            def some_call(ccm):
                return ccm

        app = Application([SomeService],
                          'tns',
                          in_protocol=HttpRpc(hier_delim="_"),
                          out_protocol=HtmlRowTable(field_name_attr='class'))
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server,
                                          'some_call',
                                          ccm_c_s='abc',
                                          ccm_c_i='123',
                                          ccm_i='456',
                                          ccm_s='def')

        elt = html.fromstring(out_string)
        show(elt, "TestHtmlRowTable.test_complex")

        # Here's what this is supposed to return
        """
        <table class="CCM">
          <tbody>
            <tr>
              <th class="i">i</th>
              <td class="i">456</td>
            </tr>
            <tr class="c">
              <th class="c">c</th>
              <td class="c">
                <table class="c">
                  <tbody>
                    <tr>
                      <th class="i">i</th>
                      <td class="i">123</td>
                    </tr>
                    <tr>
                      <th class="s">s</th>
                      <td class="s">abc</td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
            <tr>
              <th class="s">s</th>
              <td class="s">def</td>
            </tr>
          </tbody>
        </table>
        """

        print(html.tostring(elt, pretty_print=True))
        resp = elt.find_class('CCM')
        assert len(resp) == 1

        assert elt.xpath('tbody/tr/th[@class="i"]/text()')[0] == 'i'
        assert elt.xpath('tbody/tr/td[@class="i"]/text()')[0] == '456'

        assert elt.xpath(
            'tbody/tr/td[@class="c"]//th[@class="i"]/text()')[0] == 'i'
        assert elt.xpath(
            'tbody/tr/td[@class="c"]//td[@class="i"]/text()')[0] == '123'

        assert elt.xpath(
            'tbody/tr/td[@class="c"]//th[@class="s"]/text()')[0] == 's'
        assert elt.xpath(
            'tbody/tr/td[@class="c"]//td[@class="s"]/text()')[0] == 'abc'

        assert elt.xpath('tbody/tr/th[@class="s"]/text()')[0] == 's'
        assert elt.xpath('tbody/tr/td[@class="s"]/text()')[0] == 'def'
Esempio n. 27
0
    def test_complex(self):
        class SomeService(ServiceBase):
            @srpc(CCM, _returns=CCM)
            def some_call(ccm):
                return ccm

        app = Application(
            [SomeService],
            "tns",
            in_protocol=HttpRpc(hier_delim="_"),
            out_protocol=HtmlRowTable(field_name_attr="class"),
        )
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server, "some_call", ccm_c_s="abc", ccm_c_i="123", ccm_i="456", ccm_s="def")

        elt = html.fromstring(out_string)
        show(elt, "TestHtmlRowTable.test_complex")

        # Here's what this is supposed to return
        """
        <table class="CCM">
          <tbody>
            <tr>
              <th class="i">i</th>
              <td class="i">456</td>
            </tr>
            <tr class="c">
              <th class="c">c</th>
              <td class="c">
                <table class="c">
                  <tbody>
                    <tr>
                      <th class="i">i</th>
                      <td class="i">123</td>
                    </tr>
                    <tr>
                      <th class="s">s</th>
                      <td class="s">abc</td>
                    </tr>
                  </tbody>
                </table>
              </td>
            </tr>
            <tr>
              <th class="s">s</th>
              <td class="s">def</td>
            </tr>
          </tbody>
        </table>
        """

        print(html.tostring(elt, pretty_print=True))
        resp = elt.find_class("CCM")
        assert len(resp) == 1

        assert elt.xpath('tbody/tr/th[@class="i"]/text()')[0] == "i"
        assert elt.xpath('tbody/tr/td[@class="i"]/text()')[0] == "456"

        assert elt.xpath('tbody/tr/td[@class="c"]//th[@class="i"]/text()')[0] == "i"
        assert elt.xpath('tbody/tr/td[@class="c"]//td[@class="i"]/text()')[0] == "123"

        assert elt.xpath('tbody/tr/td[@class="c"]//th[@class="s"]/text()')[0] == "s"
        assert elt.xpath('tbody/tr/td[@class="c"]//td[@class="s"]/text()')[0] == "abc"

        assert elt.xpath('tbody/tr/th[@class="s"]/text()')[0] == "s"
        assert elt.xpath('tbody/tr/td[@class="s"]/text()')[0] == "def"
Esempio n. 28
0
    def test_complex_array(self):
        v = [CM(i=1, s="a"), CM(i=2, s="b"), CM(i=3, s="c"), CM(i=4, s="d")]

        class SomeService(ServiceBase):
            @srpc(_returns=Array(CM))
            def some_call():
                return v

        app = Application([SomeService], "tns", in_protocol=HttpRpc(), out_protocol=HtmlRowTable())
        server = WsgiApplication(app)

        out_string = call_wsgi_app_kwargs(server)
        show(html.fromstring(out_string), "TestHtmlRowTable.test_complex_array")
        # FIXME: Needs a proper test with xpaths and all.
        assert (
            out_string == "<div>"
            '<table class="CM">'
            "<tbody>"
            "<tr>"
            '<th class="i">i</th>'
            '<td class="i">1</td>'
            "</tr>"
            "<tr>"
            '<th class="s">s</th>'
            '<td class="s">a</td>'
            "</tr>"
            "</tbody>"
            "</table>"
            '<table class="CM">'
            "<tbody>"
            "<tr>"
            '<th class="i">i</th>'
            '<td class="i">2</td>'
            "</tr>"
            "<tr>"
            '<th class="s">s</th>'
            '<td class="s">b</td>'
            "</tr>"
            "</tbody>"
            "</table>"
            '<table class="CM">'
            "<tbody>"
            "<tr>"
            '<th class="i">i</th>'
            '<td class="i">3</td>'
            "</tr>"
            "<tr>"
            '<th class="s">s</th>'
            '<td class="s">c</td>'
            "</tr>"
            "</tbody>"
            "</table>"
            '<table class="CM">'
            "<tbody>"
            "<tr>"
            '<th class="i">i</th>'
            '<td class="i">4</td>'
            "</tr>"
            "<tr>"
            '<th class="s">s</th>'
            '<td class="s">d</td>'
            "</tr>"
            "</tbody>"
            "</table>"
            "</div>"
        )