Exemplo n.º 1
0
def test_write_boolean_false():
    """
    Checks that given the value `False` the `write_boolean` method generates
    the expected XML text.
    """
    io_buffer = make_buffer()
    xml_writer = XmlWriter(io_buffer)
    Writer.write_boolean(xml_writer, 'value', False)
    xml_writer.flush()
    assert_equals(decode_buffer(io_buffer), '<value>false</value>')
Exemplo n.º 2
0
def test_write_integer_1():
    """
    Checks that given the value `0` the `write_integer` method generates
    the expected XML text.
    """
    io_buffer = make_buffer()
    xml_writer = XmlWriter(io_buffer)
    Writer.write_integer(xml_writer, 'value', 1)
    xml_writer.flush()
    assert_equals(decode_buffer(io_buffer), '<value>1</value>')
Exemplo n.º 3
0
def test_write_boolean_false():
    """
    Checks that given the value `False` the `write_boolean` method generates
    the expected XML text.
    """
    io_buffer = make_buffer()
    xml_writer = XmlWriter(io_buffer)
    Writer.write_boolean(xml_writer, 'value', False)
    xml_writer.flush()
    assert_equals(decode_buffer(io_buffer), '<value>false</value>')
Exemplo n.º 4
0
def test_write_integer_1():
    """
    Checks that given the value `0` the `write_integer` method generates
    the expected XML text.
    """
    io_buffer = make_buffer()
    xml_writer = XmlWriter(io_buffer)
    Writer.write_integer(xml_writer, 'value', 1)
    xml_writer.flush()
    assert_equals(decode_buffer(io_buffer), '<value>1</value>')
Exemplo n.º 5
0
def test_write_string():
    """
    Checks that given an name and a value the `write_string` method
    generates the expected XML text.
    """
    io_buffer = make_buffer()
    xml_writer = XmlWriter(io_buffer)
    Writer.write_string(xml_writer, 'value', 'myvalue')
    xml_writer.flush()
    assert_equals(decode_buffer(io_buffer), '<value>myvalue</value>')
Exemplo n.º 6
0
def test_write_string():
    """
    Checks that given an name and a value the `write_string` method
    generates the expected XML text.
    """
    io_buffer = make_buffer()
    xml_writer = XmlWriter(io_buffer)
    Writer.write_string(xml_writer, 'value', 'myvalue')
    xml_writer.flush()
    assert_equals(decode_buffer(io_buffer), '<value>myvalue</value>')
def test_write_network_with_no_usages():
    """
    Test given network with usages attribute set to None,
    the usages isn't written to output xml
    """
    network = types.Network()
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    NetworkWriter.write_one(network, writer)
    writer.flush()
    assert_equals(decode_buffer(buf), '<network/>\n')
Exemplo n.º 8
0
def test_write_network_with_no_usages():
    """
    Test given network with usages attribute set to None,
    the usages isn't written to output xml
    """
    network = types.Network()
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    NetworkWriter.write_one(network, writer)
    writer.flush()
    assert_equals(decode_buffer(buf), '<network/>\n')
Exemplo n.º 9
0
def test_write_accepts_xml_writer():
    """
    Checks that the generic `write` method accepts an XML writer as
    parameter.
    """
    vm = types.Vm()
    writer = XmlWriter(None)
    result = Writer.write(vm, target=writer)
    text = writer.string()
    writer.close()
    assert_is_none(result)
    assert_equals(text, '<vm/>')
Exemplo n.º 10
0
def test_write_accepts_xml_writer():
    """
    Checks that the generic `write` method accepts an XML writer as
    parameter.
    """
    vm = types.Vm()
    writer = XmlWriter(None)
    result = Writer.write(vm, target=writer)
    text = writer.string()
    writer.close()
    assert_is_none(result)
    assert_equals(text, '<vm/>')
Exemplo n.º 11
0
def test_write_network_with_empty_usages():
    """
    Test given network with usages attribute set empty list,
    the usages empty element is written to output xml
    """
    network = types.Network(usages=[], )
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    NetworkWriter.write_one(network, writer)
    writer.flush()
    assert_equals(decode_buffer(buf),
                  '<network>\n' + '  <usages/>\n' + '</network>\n')
Exemplo n.º 12
0
def test_sso_method_id_is_attribute():
    """
    Test that writing an SSL object with one method writes the method
    identifier as the 'id' attribute.
    """
    sso = types.Sso(methods=[types.Method(id=types.SsoMethod.GUEST_AGENT)])
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    SsoWriter.write_one(sso, writer)
    writer.flush()
    assert_equals(
        decode_buffer(buf), '<sso>\n' + '  <methods>\n' +
        '    <method id="guest_agent"/>\n' + '  </methods>\n' + '</sso>\n')
Exemplo n.º 13
0
def test_write_network_with_one_usages():
    """
    Test given network with usages attribute set list with one value,
    the usages element with one value is written to output xml
    """
    network = types.Network(usages=[types.NetworkUsage.VM], )
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    NetworkWriter.write_one(network, writer)
    writer.flush()
    assert_equals(
        decode_buffer(buf), '<network>\n' + '  <usages>\n' +
        '    <usage>vm</usage>\n' + '  </usages>\n' + '</network>\n')
def test_write_network_with_empty_usages():
    """
    Test given network with usages attribute set empty list,
    the usages empty element is written to output xml
    """
    network = types.Network(
        usages=[],
    )
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    NetworkWriter.write_one(network, writer)
    writer.flush()
    assert_equals(
        decode_buffer(buf),
        '<network>\n' +
        '  <usages/>\n' +
        '</network>\n'
    )
def test_write_network_with_one_usages():
    """
    Test given network with usages attribute set list with one value,
    the usages element with one value is written to output xml
    """
    network = types.Network(
        usages=[
            types.NetworkUsage.VM
        ],
    )
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    NetworkWriter.write_one(network, writer)
    writer.flush()
    assert_equals(
        decode_buffer(buf),
        '<network>\n' +
        '  <usages>\n' +
        '    <usage>vm</usage>\n' +
        '  </usages>\n' +
        '</network>\n'
    )
def test_sso_method_id_is_attribute():
    """
    Test that writing an SSL object with one method writes the method
    identifier as the 'id' attribute.
    """
    sso = types.Sso(
        methods=[
            types.Method(
                id=types.SsoMethod.GUEST_AGENT
            )
        ]
    )
    buf = make_buffer()
    writer = XmlWriter(buf, indent=True)
    SsoWriter.write_one(sso, writer)
    writer.flush()
    assert_equals(
        decode_buffer(buf),
        '<sso>\n' +
        '  <methods>\n' +
        '    <method id="guest_agent"/>\n' +
        '  </methods>\n' +
        '</sso>\n'
    )
Exemplo n.º 17
0
def test_write_string():
    """
    Checks that given an name and a value the `write_string` method
    generates the expected XML text.
    """
    buf = make_buffer()
    writer = XmlWriter(buf)
    writer.write_element('value', 'myvalue')
    writer.flush()
    assert_equals(decode_buffer(buf), '<value>myvalue</value>')