Beispiel #1
0
def test_read_with_xml_reader():
    """
    Test if read method accepts xml reader.
    """
    cursor = XmlReader(make_buffer('<vm/>'))
    Reader.read(cursor)
    cursor.close()
def test_read_with_xml_reader():
    """
    Test if read method accepts xml reader.
    """
    cursor = XmlReader(make_buffer('<vm/>'))
    Reader.read(cursor)
    cursor.close()
def test_network_with_no_usages():
    """
    Test given network with no usages element, the usages attribute is None.
    """
    reader = XmlReader(make_buffer('<network/>'))
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_is_none(result.usages)
def test_network_with_no_usages():
    """
    Test given network with no usages element, the usages attribute is None.
    """
    reader = XmlReader(make_buffer('<network/>'))
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_is_none(result.usages)
Beispiel #5
0
def test_read_leaves_position():
    """
    Test if read method leaves it positioned in the next element.
    """
    cursor = XmlReader(make_buffer('<root><vm/><next/></root>'))
    cursor.read()
    Reader.read(cursor)
    assert_equals(cursor.node_name(), 'next')
    cursor.close()
def test_read_leaves_position():
    """
    Test if read method leaves it positioned in the next element.
    """
    cursor = XmlReader(make_buffer('<root><vm/><next/></root>'))
    cursor.read()
    Reader.read(cursor)
    assert_equals(cursor.node_name(), 'next')
    cursor.close()
def test_network_with_empty_usages():
    """
    Test given network with empty usages element, the usages attribute is empty list.
    """
    reader = XmlReader(make_buffer('<network><usages/></network>'))
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result.usages, list))
    assert_equals(len(result.usages), 0)
def test_network_with_empty_usages():
    """
    Test given network with empty usages element, the usages attribute is empty list.
    """
    reader = XmlReader(make_buffer('<network><usages/></network>'))
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result.usages, list))
    assert_equals(len(result.usages), 0)
Beispiel #9
0
def test_reading_name_with_accents():
    """
    Test that reading a VM that has a name with accents works correctly.
    """
    reader = XmlReader(make_buffer('<vm>' '<name>áéíóúÁÉÍÓÚ</name>' '</vm>'))
    result = VmReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Vm))
    assert_equals(result.name, 'áéíóúÁÉÍÓÚ')
def test_network_with_one_usages():
    """
    Test given network with no usages element, the usages attribute is None.
    """
    reader = XmlReader(
        make_buffer('<network><usages><usage>vm</usage></usages></network>'))
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result.usages, list))
    assert_equals(len(result.usages), 1)
    assert_equals(result.usages[0], types.NetworkUsage.VM)
def test_unsupported_switch_type_dont_raise_exception():
    """
    Test when given switch type is unsupported, it don't raise exception.
    """
    reader = XmlReader(
        make_buffer('<cluster>'
                    '<switch_type>ugly</switch_type>'
                    '</cluster>'))
    result = ClusterReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Cluster))
    assert_is_none(result.switch_type)
def test_reading_name_with_accents():
    """
    Test that reading a VM that has a name with accents works correctly.
    """
    reader = XmlReader(make_buffer(
        '<vm>'
        '<name>áéíóúÁÉÍÓÚ</name>'
        '</vm>'
    ))
    result = VmReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Vm))
    assert_equals(result.name, 'áéíóúÁÉÍÓÚ')
Beispiel #13
0
def test_reading_of_INHERITABLE_BOOLEAN_unsupported_value():
    """
    Test reading the InheritableBoolean enum unsupported value return None.
    """
    reader = XmlReader(
        make_buffer('<vm>'
                    '<migration>'
                    '<auto_converge>ugly</auto_converge>'
                    '</migration>'
                    '</vm>'))
    result = VmReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Vm))
    assert_equals(result.migration.auto_converge, None)
def test_network_with_one_usages():
    """
    Test given network with no usages element, the usages attribute is None.
    """
    reader = XmlReader(
        make_buffer(
            '<network><usages><usage>vm</usage></usages></network>'
        )
    )
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result.usages, list))
    assert_equals(len(result.usages), 1)
    assert_equals(result.usages[0], types.NetworkUsage.VM)
def test_unsupported_usage_dont_raise_exception():
    """
    Test when given network with unsupported usage element,
    it don't raise exception.
    """
    reader = XmlReader(
        make_buffer('<network>' + '<usages>' + '<usage>ugly</usage>' +
                    '<usage>display</usage>' + '</usages>' + '</network>'))
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result.usages, list))
    assert_equals(len(result.usages), 2)
    assert_is_none(result.usages[0])
    assert_equals(result.usages[1], types.NetworkUsage.DISPLAY)
def test_cluster_with_no_rng_sources_and_switch_type():
    """
    Test that reading the 'switch_type' enum when it appears after an
    empty list works correctly.
    """
    reader = XmlReader(
        make_buffer('<cluster>'
                    '<required_rng_sources/>'
                    '<switch_type>legacy</switch_type>'
                    '</cluster>'))
    result = ClusterReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Cluster))
    assert_equals(result.required_rng_sources, [])
    assert_equals(result.switch_type, types.SwitchType.LEGACY)
def test_reading_of_INHERITABLE_BOOLEAN_unsupported_value():
    """
    Test reading the InheritableBoolean enum unsupported value return None.
    """
    reader = XmlReader(make_buffer(
        '<vm>'
        '<migration>'
        '<auto_converge>ugly</auto_converge>'
        '</migration>'
        '</vm>'
    ))
    result = VmReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Vm))
    assert_equals(result.migration.auto_converge, None)
Beispiel #18
0
def test_reading_of_INHERITABLE_BOOLEAN_INHERIT():
    """
    Test reading the InheritableBoolean enum inherit value.
    """
    reader = XmlReader(
        make_buffer('<vm>'
                    '<migration>'
                    '<auto_converge>inherit</auto_converge>'
                    '</migration>'
                    '</vm>'))
    result = VmReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Vm))
    assert_equals(result.migration.auto_converge,
                  types.InheritableBoolean.INHERIT)
def test_reading_of_INHERITABLE_BOOLEAN_INHERIT():
    """
    Test reading the InheritableBoolean enum inherit value.
    """
    reader = XmlReader(make_buffer(
        '<vm>'
        '<migration>'
        '<auto_converge>inherit</auto_converge>'
        '</migration>'
        '</vm>'
    ))
    result = VmReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Vm))
    assert_equals(result.migration.auto_converge, types.InheritableBoolean.INHERIT)
Beispiel #20
0
def test_cluster_with_no_rng_sources_and_switch_type():
    """
    Test that reading the 'switch_type' enum when it appears after an
    empty list works correctly.
    """
    reader = XmlReader(make_buffer(
      '<cluster>'
        '<required_rng_sources/>'
        '<switch_type>legacy</switch_type>'
      '</cluster>'
    ))
    result = ClusterReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.Cluster))
    assert_equals(result.required_rng_sources, [])
    assert_equals(result.switch_type, types.SwitchType.LEGACY)
def test_affinity_group_reader_with_assigned_vms():
    """
    Test that reading of `vms` attribute of affinity group reads the `href`
    of the link as well as content of the `vms` element.
    """
    reader = XmlReader(make_buffer(
        '<affinity_group>'
        '<link href="/ovirt-engine/api/clusters/123/affinitygroups/456/vms" rel="vms"/>'
        '<vms><vm id="123"/></vms>'
        '</affinity_group>'
    ))
    result = AffinityGroupReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result, types.AffinityGroup))
    assert_true(len(result.vms) > 0)
    assert_equals(
        result.vms.href,
        '/ovirt-engine/api/clusters/123/affinitygroups/456/vms'
    )
    assert_equals(result.vms[0].id, '123')
def test_unsupported_usage_dont_raise_exception():
    """
    Test when given network with unsupported usage element,
    it don't raise exception.
    """
    reader = XmlReader(
        make_buffer(
            '<network>' +
            '<usages>' +
            '<usage>ugly</usage>' +
            '<usage>display</usage>' +
            '</usages>' +
            '</network>'
        )
    )
    result = NetworkReader.read_one(reader)
    reader.close()

    assert_true(isinstance(result.usages, list))
    assert_equals(len(result.usages), 2)
    assert_is_none(result.usages[0])
    assert_equals(result.usages[1], types.NetworkUsage.DISPLAY)