示例#1
0
def test_xmlrpc_handler_size_limit(monkeypatch):
    app = pretend.stub()

    request = pretend.stub(headers={"Content-Type": "text/xml", "Content-Length": str(10 * 1024 * 1024 + 1)})

    with pytest.raises(BadRequest):
        xmlrpc.handler(app, request)
示例#2
0
def test_xmlrpc_handler_size_limit(monkeypatch):
    app = pretend.stub()

    request = pretend.stub(headers={
        'Content-Type': 'text/xml',
        'Content-Length': str(10 * 1024 * 1024 + 1)
    }, )

    with pytest.raises(BadRequest):
        xmlrpc.handler(app, request)
示例#3
0
def test_xmlrpc_handler(monkeypatch):
    Response = pretend.call_recorder(lambda *a, **k: 'response')
    monkeypatch.setattr(xmlrpc, "Response", Response)

    # I'm aware that list_packages shouldn't return data with unicode strings
    # but for the purposes of this test I'm just ensuring that unicode data is
    # handled sanely
    interface = pretend.stub(list_packages=pretend.call_recorder(
        lambda *a, **k: ['one', 'unicod€']))
    Interface = lambda a, r: interface
    monkeypatch.setattr(xmlrpc, "Interface", Interface)

    app = pretend.stub()

    xml_request = '''<?xml version="1.0"?><methodCall>
        <methodName>list_packages</methodName></methodCall>'''

    request = pretend.stub(
        headers={
            'Content-Type': 'text/xml',
            'Content-Length': str(len(xml_request)),
        },
        get_data=lambda **k: xml_request,
    )

    assert xmlrpc.handler(app, request) == 'response'

    assert interface.list_packages.calls == [pretend.call()]

    response_xml = Response.calls[0].args[0]
    assert response_xml == b'''<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><array><data>
<value><string>one</string></value>
<value><string>unicod\xe2\x82\xac</string></value>
</data></array></value>
</param>
</params>
</methodResponse>
'''

    assert Response.calls[0].kwargs == dict(mimetype='text/xml; charset=utf-8')
示例#4
0
def test_xmlrpc_handler(monkeypatch):
    Response = pretend.call_recorder(lambda *a, **k: "response")
    monkeypatch.setattr(xmlrpc, "Response", Response)

    # I'm aware that list_packages shouldn't return data with unicode strings
    # but for the purposes of this test I'm just ensuring that unicode data is
    # handled sanely
    interface = pretend.stub(list_packages=pretend.call_recorder(lambda *a, **k: ["one", "unicod€"]))
    Interface = lambda a, r: interface
    monkeypatch.setattr(xmlrpc, "Interface", Interface)

    app = pretend.stub()

    xml_request = """<?xml version="1.0"?><methodCall>
        <methodName>list_packages</methodName></methodCall>"""

    request = pretend.stub(
        headers={"Content-Type": "text/xml", "Content-Length": str(len(xml_request))}, get_data=lambda **k: xml_request
    )

    assert xmlrpc.handler(app, request) == "response"

    assert interface.list_packages.calls == [pretend.call()]

    response_xml = Response.calls[0].args[0]
    assert (
        response_xml
        == b"""<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><array><data>
<value><string>one</string></value>
<value><string>unicod\xe2\x82\xac</string></value>
</data></array></value>
</param>
</params>
</methodResponse>
"""
    )

    assert Response.calls[0].kwargs == dict(mimetype="text/xml; charset=utf-8")