Exemplo n.º 1
0
    def test_element_text_is_stripped(self, record_obj):
        tree = etree.fromstring(
            """<root>
                <element>     1     </element>
            </root>
            """
        )

        chain = ['element']

        assert record_obj.value is None
        presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
        assert record_obj.value == '1'
Exemplo n.º 2
0
    def test_chain_is_name_of_element(self, record_obj):
        tree = etree.fromstring(
            """<root>
                <element>1</element>
            </root>
            """
        )

        chain = 'element'

        assert record_obj.value is None
        presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
        assert record_obj.value == '1'
Exemplo n.º 3
0
    def test_attribute_not_set_when_element_value_is_none(self, record_obj):
        tree = etree.fromstring(
            """<root>
                <element/>
            </root>
            """
        )

        chain = ['element']

        record_obj.value = 10
        presentation.doSimpleXMLAssignment(record_obj, 'd', tree, chain)
        assert record_obj.value == 10
Exemplo n.º 4
0
    def test_with_one_nested_element(self, record_obj):
        tree = etree.fromstring(
            """<root>
                <element>
                    <subelement>1</subelement>
                </element>
            </root>
            """
        )

        chain = ['element', 'subelement']

        assert record_obj.value is None
        presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
        assert record_obj.value == '1'
Exemplo n.º 5
0
    def test_without_nested_elements(self, record_obj):
        tree = etree.fromstring(
            """<root>
                <element>1</element>
            </root>
            """
        )

        chain = ['element']

        # Since the function mutates the object, we will verify that the
        # attribute is the expected value before the function call.
        assert record_obj.value is None
        presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
        assert record_obj.value == '1'