def test_request_xml_dict_params():
    xml = adapters.xml_request(
        'client.get',
        id="5",
        monkey=dict(name="butter")
    )
    
    # test that xml looks roughly like either
    # <request method="client.get">
    #     <id>5</id>
    #     <monkey><name>butter</name></monkey>
    # </request>
    # or
    # <request method="client.get">
    #     <id>5</id>
    #     <monkey><name>butter</name></monkey>
    # </request>
    #
    # (We don't actually care which.)
    request_document = etree.fromstring(xml)
    assert 'request' == request_document.tag
    assert {'method': 'client.get'} == request_document.attrib
    assert 2 == len(request_document)
    assert any(
        parameter.tag == 'id' and parameter.text == '5'
        for parameter in request_document
    )
    assert any(
        parameter.tag == 'monkey' 
        and len(parameter) == 1
        and parameter[0].tag == 'name'
        and parameter[0].text == 'butter'
        for parameter in request_document
    )
Beispiel #2
0
def test_request_xml_list_params():
    xml = adapters.xml_request('client.get',
                               id="5",
                               monkeys=[('monkey', dict(name="butter"))])

    # test that xml looks roughly like either
    # <request method="client.get">
    #     <id>5</id>
    #     <monkeys>
    #         <monkey><name>butter</name></monkey>
    #     </monkeys>
    # </request>
    # or
    # <request method="client.get">
    #     <monkeys>
    #         <monkey><name>butter</name></monkey>
    #     </monkeys>
    #     <id>5</id>
    # </request>
    #
    # (We don't actually care which.)
    request_document = etree.fromstring(xml)
    assert 'request' == request_document.tag
    assert {'method': 'client.get'} == request_document.attrib
    assert 2 == len(request_document)
    assert any(parameter.tag == 'id' and parameter.text == '5'
               for parameter in request_document)
    assert any(
        parameter.tag == 'monkeys' and len(parameter) == 1
        and parameter[0].tag == 'monkey' and len(parameter[0]) == 1
        and parameter[0][0].tag == 'name' and parameter[0][0].text == 'butter'
        for parameter in request_document)
def test_request_xml_simple():
    xml = adapters.xml_request('client.list')
    
    # test that xml looks roughly like <request method="client.list"/>
    request_document = etree.fromstring(xml)
    assert 'request' == request_document.tag
    assert {'method': 'client.list'} == request_document.attrib
    assert 0 == len(request_document)
Beispiel #4
0
def test_request_xml_simple():
    xml = adapters.xml_request('client.list')

    # test that xml looks roughly like <request method="client.list"/>
    request_document = etree.fromstring(xml)
    assert 'request' == request_document.tag
    assert {'method': 'client.list'} == request_document.attrib
    assert 0 == len(request_document)
Beispiel #5
0
def test_request_xml_simple_params():
    xml = adapters.xml_request('client.get', id="5", monkey="butter")

    # test that xml looks roughly like either
    # <request method="client.get"><id>5</id><monkey>butter</monkey></request>
    # or
    # <request method="client.get"><monkey>butter</monkey><id>5</id></request>
    #
    # (We don't actually care which.)
    request_document = etree.fromstring(xml)
    assert 'request' == request_document.tag
    assert {'method': 'client.get'} == request_document.attrib
    assert 2 == len(request_document)
    assert any(parameter.tag == 'id' and parameter.text == '5'
               for parameter in request_document)
    assert any(parameter.tag == 'monkey' and parameter.text == 'butter'
               for parameter in request_document)
Beispiel #6
0
def default_request_encoder(*args, **kwargs):
    """
    request_encoder returns a tuple:
        (entity, *headers_factory)
    """
    method = args[0]

    # look for anything that looks like
    # a file resource in the argument.
    files = _collect_file_resources(kwargs)

    # the envelope is always sent as xml
    envelope = adapters.xml_request(method, **kwargs)

    if len(files) == 0:
        # Regular request, no files to upload.
        # No extra headers are added
        return envelope, []
    else:
        return _encode_multipart_request(
            envelope,
            files,
            boundary=uuid.uuid4().hex)
Beispiel #7
0
def default_request_encoder(request):
    return adapters.xml_request(request)