Esempio 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>')
Esempio 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>')
Esempio 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>')
Esempio 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>')
Esempio 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>')
Esempio 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')
Esempio 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')
Esempio 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/>')
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/>')
Esempio 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')
Esempio 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')
Esempio 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'
    )
Esempio 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>')