Beispiel #1
0
def test_read_integer_with_valid_value():
    """
    Test given valid value returns that value.
    """
    io_buffer = make_buffer('<value>0</value>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_integer(xml_reader), 0)
Beispiel #2
0
def test_read_integers_with_two_values():
    """
    Test given two values returns list containing two values.
    """
    io_buffer = make_buffer('<list><value>0</value><value>1</value></list>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_integers(xml_reader), [0, 1])
Beispiel #3
0
def test_read_boolean_1():
    """
    Test given '1' return True.
    """
    io_buffer = make_buffer('<value>1</value>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_boolean(xml_reader), True)
Beispiel #4
0
def test_read_booleans_with_one_value():
    """
    Test given one value returns list containing one value.
    """
    io_buffer = make_buffer('<list><value>false</value></list>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_booleans(xml_reader), [False])
Beispiel #5
0
def test_read_decimals_with_one_value():
    """
    Test given one value returns list containing one value.
    """
    io_buffer = make_buffer('<list><value>1.1</value></list>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_decimals(xml_reader), [1.1])
Beispiel #6
0
def test_read_decimal_with_valid_value():
    """
    Test given valid value returns that value.
    """
    io_buffer = make_buffer('<value>1.1</value>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_decimal(xml_reader), 1.1)
Beispiel #7
0
def test_read_boolean_invalid_value():
    """
    Test given 'ugly' raises error.
    """
    io_buffer = make_buffer('<value>ugly</value>')
    xml_reader = XmlReader(io_buffer)
    Reader.read_boolean(xml_reader)
Beispiel #8
0
def test_read_date_with_invalid_value():
    """
    Test given invalid value raises error.
    """
    io_buffer = make_buffer('<value>ugly</value>')
    xml_reader = XmlReader(io_buffer)
    Reader.read_date(xml_reader)
Beispiel #9
0
def test_read_dates_empty_list_without_close_tag():
    """
    Test given no values without close tag returns empty list.
    """
    io_buffer = make_buffer('<list/>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_dates(xml_reader), [])
Beispiel #10
0
def make_reader(text):
    """
    Creates an IO objec that reads from the given text.
    """
    if six.PY3:
        text = text.encode('utf-8')
    return XmlReader(BytesIO(text))
Beispiel #11
0
def test_read_with_xml_reader():
    """
    Test if read method accepts xml reader.
    """
    cursor = XmlReader(make_buffer('<vm/>'))
    Reader.read(cursor)
    cursor.close()
Beispiel #12
0
def test_read_boolean_0():
    """
    Test given '0' return False.
    """
    io_buffer = make_buffer('<value>0</value>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_boolean(xml_reader), False)
Beispiel #13
0
def test_read_integers_empty_list_with_close_tag():
    """
    Test given no values with close tag returns empty list.
    """
    io_buffer = make_buffer('<list></list>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_integers(xml_reader), [])
Beispiel #14
0
def test_read_decimals_with_two_values():
    """
    Test given two values returns list containing two values.
    """
    io_buffer = make_buffer(
        '<list><value>1.1</value><value>2.2</value></list>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_decimals(xml_reader), [1.1, 2.2])
Beispiel #15
0
def test_read_date_with_valid_value():
    """
    Test given valid value returns that value.
    """
    io_buffer = make_buffer('<value>2015-12-10T22:00:30+01:00</value>')
    xml_reader = XmlReader(io_buffer)
    date = datetime(2015, 12, 10, 22, 0, 30, tzinfo=TZ(60, None))
    assert_equals(Reader.read_date(xml_reader), date)
Beispiel #16
0
def test_read_given_two_different_objects():
    """
    Test if given given an empty document, read returns None.
    """
    cursor = XmlReader(make_buffer('<root/>'))
    cursor.read()
    object = Reader.read(cursor)
    assert_is_none(object)
Beispiel #17
0
def test_read_booleans_with_two_values():
    """
    Test given two values returns list containing two values.
    """
    io_buffer = make_buffer(
        '<list><value>false</value><value>true</value></list>')
    xml_reader = XmlReader(io_buffer)
    assert_equals(Reader.read_booleans(xml_reader), [False, True])
Beispiel #18
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_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 #20
0
def test_read_dates_with_one_value():
    """
    Test given one value returns list containing one value.
    """
    io_buffer = make_buffer(
        '<list><value>2015-12-10T22:00:30+01:00</value></list>')
    xml_reader = XmlReader(io_buffer)
    date = datetime(2015, 12, 10, 22, 0, 30, tzinfo=TZ(60, None))
    assert_equals(Reader.read_dates(xml_reader), [date])
Beispiel #21
0
def test_read_unknonw_tag():
    """
    Test that when an unknonw tag is received an exception with a
    message is generated.
    """
    cursor = XmlReader(make_buffer('<html>blah<html>'))
    cursor.read()
    with assert_raises(Error) as context:
        Reader.read(cursor)
    assert_equals(str(context.exception), "Can't find a reader for tag 'html'")
Beispiel #22
0
def test_read_given_two_different_objects():
    """
    Test if given two different consecutive objects, they can be read with two calls.
    """
    cursor = XmlReader(make_buffer('<root><vm/><disk/></root>'))
    cursor.read()
    vm = Reader.read(cursor)
    disk = Reader.read(cursor)
    assert_true(isinstance(vm, types.Vm))
    assert_true(isinstance(disk, types.Disk))
Beispiel #23
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_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 #25
0
def test_read_dates_with_two_values():
    """
    Test given two values returns list containing two values.
    """
    io_buffer = make_buffer('<list>'
                            '<value>2015-12-10T22:00:30+01:00</value>'
                            '<value>2016-12-10T22:00:30+01:00</value>'
                            '</list>')
    xml_reader = XmlReader(io_buffer)
    date1 = datetime(2015, 12, 10, 22, 0, 30, tzinfo=TZ(60, None))
    date2 = datetime(2016, 12, 10, 22, 0, 30, tzinfo=TZ(60, None))
    assert_equals(Reader.read_dates(xml_reader), [date1, date2])
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)
Beispiel #28
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_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)