def test_simple_type_strings(): type_element = elements.type("example", [elements.field("name", "Bob"), elements.field("age", "27")]) assert "example" == type_element.tag assert 2 == len(type_element) assert "name" == type_element[0].tag assert "Bob" == type_element[0].text assert "age" == type_element[1].tag assert "27" == type_element[1].text
def test_simple_type_strings(): type_element = elements.type("example", [ elements.field('name', 'Bob'), elements.field('age', '27') ]) assert 'example' == type_element.tag assert 2 == len(type_element) assert 'name' == type_element[0].tag assert 'Bob' == type_element[0].text assert 'age' == type_element[1].tag assert '27' == type_element[1].text
def test_simple_type_strings(): type_element = elements.type( "example", [elements.field('name', 'Bob'), elements.field('age', '27')]) assert 'example' == type_element.tag assert 2 == len(type_element) assert 'name' == type_element[0].tag assert 'Bob' == type_element[0].text assert 'age' == type_element[1].tag assert '27' == type_element[1].text
def test_simple_request(): body = elements.field("foo", "bar") request_element = elements.request("client.list", [body]) assert 'request' == request_element.tag assert {'method': 'client.list'} == request_element.attrib assert 1 == len(request_element) assert body == request_element[0]
def encode_as_simple(name, value): """Creates an etree element following the simple field convention. Values are assumed to be strs, unicodes, ints, floats, or Decimals: >>> element = encode_as_simple('foo', '5') >>> element.tag == 'foo' True >>> element.text == '5' True >>> element = encode_as_simple('bar', 8) >>> element.tag == 'bar' True >>> element.text == '8' True """ if isinstance(value, objectify.ObjectifiedDataElement): return encode_as_simple(name, unicode(value)) if type(value) in _stringable_types: value = str(value) return elements.field(name, value)
def test_field(): field_element = elements.field("example", "A Test Value Here") assert b"<example>A Test Value Here</example>" == etree.tostring( field_element )
def test_field(): field_element = elements.field("example", "A Test Value Here") assert "<example>A Test Value Here</example>" == etree.tostring( field_element)