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>'
def test_anyuri_uri_value(self): _link = "http://arskom.com.tr/" _text = "Arskom" class C(ComplexModel): c = AnyUri class SomeService(ServiceBase): @srpc(_returns=C) def some_call(): return C(c=AnyUri.Value(_link, text=_text)) app = Application([SomeService], 'tns', in_protocol=HttpRpc(), out_protocol=HtmlRowTable(field_name_attr='class')) server = WsgiApplication(app) out_string = call_wsgi_app_kwargs(server) elt = html.fromstring(out_string) print(html.tostring(elt, pretty_print=True)) assert elt.xpath('//td[@class="c"]')[0][0].tag == 'a' assert elt.xpath('//td[@class="c"]')[0][0].text == _text assert elt.xpath('//td[@class="c"]')[0][0].attrib['href'] == _link
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>'
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>'
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>'
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'