Exemplo n.º 1
0
 def test_in_list_mismatched_name(self):
     with self.assertRaises(exemel.MismatchedElementNameError):
         exemel.build({
             'mismatched-name': [
                 'foo',
                 self.existing_element,
                 'bar'
             ]
         })
Exemplo n.º 2
0
    def test_default_encoding(self):
        actual_xml = exemel.build({})

        if _is_python2():
            assert isinstance(actual_xml, basestring)
        else:
            assert isinstance(actual_xml, bytes)
Exemplo n.º 3
0
    def test_unicode_encoding(self):
        actual_xml = exemel.build({}, encoding='unicode')

        if _is_python2():
            assert isinstance(actual_xml, unicode)
        else:
            assert isinstance(actual_xml, str)
Exemplo n.º 4
0
    def test_dict_items(self):
        item1 = collections.OrderedDict()
        item1['alpha'] = 0
        item1['bravo'] = 1

        item2 = collections.OrderedDict()
        item2['alpha'] = 2
        item2['bravo'] = 3

        actual_xml = exemel.build({
            'myList': [item1, item2]
        })

        expected_xml = """
            <root>
                <myList>
                    <alpha>0</alpha>
                    <bravo>1</bravo>
                </myList>
                <myList>
                    <alpha>2</alpha>
                    <bravo>3</bravo>
                </myList>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 5
0
    def test_unicode_encoding(self):
        actual_xml = exemel.build({}, encoding='unicode')

        if _is_python2():
            assert isinstance(actual_xml, unicode)
        else:
            assert isinstance(actual_xml, str)
Exemplo n.º 6
0
    def test_dict_items(self):
        item1 = collections.OrderedDict()
        item1['alpha'] = 0
        item1['bravo'] = 1

        item2 = collections.OrderedDict()
        item2['alpha'] = 2
        item2['bravo'] = 3

        actual_xml = exemel.build({'myList': [item1, item2]})

        expected_xml = """
            <root>
                <myList>
                    <alpha>0</alpha>
                    <bravo>1</bravo>
                </myList>
                <myList>
                    <alpha>2</alpha>
                    <bravo>3</bravo>
                </myList>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 7
0
    def test_default_encoding(self):
        actual_xml = exemel.build({})

        if _is_python2():
            assert isinstance(actual_xml, basestring)
        else:
            assert isinstance(actual_xml, bytes)
Exemplo n.º 8
0
    def test_empty_list(self):
        actual_xml = exemel.build({
            'myList': []
        })

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 9
0
    def test_none_value(self):
        actual_xml = exemel.build({
            '#text': None
        })

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 10
0
    def test_on_root(self):
        actual_xml = exemel.build({
            '#text': 'foo'
        })

        expected_xml = '<root>foo</root>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 11
0
    def test_boolean_value(self):
        actual_xml = exemel.build({
            '@test': True
        })

        expected_xml = '<root test="true"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 12
0
    def test_on_root(self):
        actual_xml = exemel.build({
            '#ns': 'fake:ns'
        })

        expected_xml = '<root xmlns="fake:ns"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 13
0
    def test_int_value(self):
        actual_xml = exemel.build({
            '@test': 0
        })

        expected_xml = '<root test="0"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 14
0
    def test_float_value(self):
        actual_xml = exemel.build({
            '#text': 1.1
        })

        expected_xml = '<root>1.1</root>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 15
0
    def test_on_root(self):
        actual_xml = exemel.build({
            '@alpha': 'a',
            '@bravo': 'b'
        })

        expected_xml = '<root alpha="a" bravo="b"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 16
0
    def test_sub_element_is_empty_dict(self):
        actual_xml = exemel.build({'alpha': {}})

        expected_xml = """
            <root>
                <alpha/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 17
0
    def test_on_sub_element(self):
        actual_xml = exemel.build({'child': {'#text': 'foo'}})

        expected_xml = """
            <root>
                <child>foo</child>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 18
0
    def test_on_sub_element(self):
        actual_xml = exemel.build({'child': {'@alpha': 'a', '@bravo': 'b'}})

        expected_xml = """
            <root>
                <child alpha="a" bravo="b"/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 19
0
    def test_not_inherited(self):
        actual_xml = exemel.build({'#ns': 'fake:ns', 'child': {'#ns': None}})

        expected_xml = """
            <f:root xmlns:f="fake:ns">
                <child/>
            </f:root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 20
0
    def test_on_sub_element(self):
        actual_xml = exemel.build({'child': {'#ns': 'fake:ns'}})

        expected_xml = """
            <root>
                <child xmlns="fake:ns"/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 21
0
    def test_in_dict_matching_name(self):

        actual_xml = exemel.build({'existing-element': self.existing_element})

        expected_xml = """
            <root>
                <existing-element xmlns="test:ns">test-value</existing-element>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 22
0
    def test_none_value(self):
        actual_xml = exemel.build({
            'alpha': None,
        })

        expected_xml = """
            <root>
                <alpha/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 23
0
    def test_none_value(self):
        actual_xml = exemel.build({
            'alpha': None,
        })

        expected_xml = """
            <root>
                <alpha/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 24
0
    def test_float_value(self):
        actual_xml = exemel.build({
            'alpha': 1.1,
        })

        expected_xml = """
            <root>
                <alpha>1.1</alpha>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 25
0
    def test_sub_element_is_empty_dict(self):
        actual_xml = exemel.build({
            'alpha': {}
        })

        expected_xml = """
            <root>
                <alpha/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 26
0
    def test_float_value(self):
        actual_xml = exemel.build({
            'alpha': 1.1,
        })

        expected_xml = """
            <root>
                <alpha>1.1</alpha>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 27
0
def create_netconf_rpc_request(command, namespace, **args):
    """
    Creates a Netconf RPC request.  Command specifies the tag name of the
    command to be issued and namspace specifies the namespace.  Additional
    arguments can be specified optionally by args.
    """

    args_dict = {'#ns': namespace}
    args_dict.update(args)
    command_ele = etree.fromstring(exemel.build(args_dict, root=command))

    return command_ele
Exemplo n.º 28
0
    def test_in_dict_matching_name(self):

        actual_xml = exemel.build({
            'existing-element': self.existing_element
        })

        expected_xml = """
            <root>
                <existing-element xmlns="test:ns">test-value</existing-element>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 29
0
    def test_inherited(self):
        actual_xml = exemel.build({
            '#ns': 'fake:ns',
            'child': None
        })

        expected_xml = """
            <f:root xmlns:f="fake:ns">
                <f:child/>
            </f:root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 30
0
    def test_on_sub_element(self):
        actual_xml = exemel.build({
            'child': {
                '#text': 'foo'
            }
        })

        expected_xml = """
            <root>
                <child>foo</child>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 31
0
    def test_on_sub_element(self):
        actual_xml = exemel.build({
            'child': {
                '#ns': 'fake:ns'
            }
        })

        expected_xml = """
            <root>
                <child xmlns="fake:ns"/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 32
0
    def test_on_sub_element(self):
        actual_xml = exemel.build({
            'child': {
                '@alpha': 'a',
                '@bravo': 'b'
            }
        })

        expected_xml = """
            <root>
                <child alpha="a" bravo="b"/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 33
0
    def test_keys_become_sub_elements(self):
        dictionary = collections.OrderedDict()
        dictionary['alpha'] = 'a'
        dictionary['bravo'] = 'b'

        actual_xml = exemel.build(dictionary)

        expected_xml = """
            <root>
                <alpha>a</alpha>
                <bravo>b</bravo>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 34
0
    def test_boolean_values(self):
        dictionary = collections.OrderedDict()
        dictionary['alpha'] = True
        dictionary['bravo'] = False

        actual_xml = exemel.build(dictionary)

        expected_xml = """
            <root>
                <alpha>true</alpha>
                <bravo>false</bravo>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 35
0
    def test_boolean_values(self):
        dictionary = collections.OrderedDict()
        dictionary['alpha'] = True
        dictionary['bravo'] = False

        actual_xml = exemel.build(dictionary)

        expected_xml = """
            <root>
                <alpha>true</alpha>
                <bravo>false</bravo>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 36
0
    def test_keys_become_sub_elements(self):
        dictionary = collections.OrderedDict()
        dictionary['alpha'] = 'a'
        dictionary['bravo'] = 'b'

        actual_xml = exemel.build(dictionary)

        expected_xml = """
            <root>
                <alpha>a</alpha>
                <bravo>b</bravo>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 37
0
    def test_value_items(self):
        actual_xml = exemel.build(
            {'myList': ['foo', 0, 1.1, True, False, None]})

        expected_xml = """
            <root>
                <myList>foo</myList>
                <myList>0</myList>
                <myList>1.1</myList>
                <myList>true</myList>
                <myList>false</myList>
                <myList/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 38
0
    def test_list_items_different_namespaces(self):
        actual_xml = exemel.build(
            {'myList': [{
                '#ns': 'first:ns'
            }, {
                '#ns': 'second:ns'
            }]})

        expected_xml = """
            <root>
                <myList xmlns="first:ns"/>
                <myList xmlns="second:ns"/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 39
0
    def test_boolean_values(self):
        actual_xml = exemel.build(
            {'child': [{
                '#text': True
            }, {
                '#text': False
            }]})

        expected_xml = """
            <root>
                <child>true</child>
                <child>false</child>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 40
0
    def test_value_items(self):
        actual_xml = exemel.build({
            'myList': ['foo', 0, 1.1, True, False, None]
        })

        expected_xml = """
            <root>
                <myList>foo</myList>
                <myList>0</myList>
                <myList>1.1</myList>
                <myList>true</myList>
                <myList>false</myList>
                <myList/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 41
0
    def test_text_and_sub_elements(self):
        dictionary = collections.OrderedDict()
        dictionary['alpha'] = None
        dictionary['#text'] = 'foo'
        dictionary['bravo'] = None

        actual_xml = exemel.build(dictionary)

        expected_xml = """
            <root>
                foo
                <alpha/>
                <bravo/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 42
0
    def test_text_and_sub_elements(self):
        dictionary = collections.OrderedDict()
        dictionary['alpha'] = None
        dictionary['#text'] = 'foo'
        dictionary['bravo'] = None

        actual_xml = exemel.build(dictionary)

        expected_xml = """
            <root>
                foo
                <alpha/>
                <bravo/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 43
0
    def test_list_items_different_namespaces(self):
        actual_xml = exemel.build({
            'myList': [
                {
                    '#ns': 'first:ns'
                },
                {
                    '#ns': 'second:ns'
                }
            ]
        })

        expected_xml = """
            <root>
                <myList xmlns="first:ns"/>
                <myList xmlns="second:ns"/>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 44
0
    def test_boolean_values(self):
        actual_xml = exemel.build({
            'child': [
                {
                    '#text': True
                },
                {
                    '#text': False
                }
            ]
        })

        expected_xml = """
            <root>
                <child>true</child>
                <child>false</child>
            </root>
            """

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 45
0
    def test_root_is_empty_dict(self):
        actual_xml = exemel.build({})

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 46
0
    def test_int_value(self):
        actual_xml = exemel.build({'@test': 0})

        expected_xml = '<root test="0"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 47
0
    def test_root_is_empty_dict(self):
        actual_xml = exemel.build({})

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 48
0
    def test_empty_list(self):
        actual_xml = exemel.build({'myList': []})

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 49
0
    def test_none_value(self):
        actual_xml = exemel.build({'#text': None})

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 50
0
    def test_custom_root(self):
        actual_xml = exemel.build({}, root='custom')

        expected_xml = '<custom/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 51
0
    def test_float_value(self):
        actual_xml = exemel.build({'#text': 1.1})

        expected_xml = '<root>1.1</root>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 52
0
 def test_in_dict_mismatched_name(self):
     with self.assertRaises(exemel.MismatchedElementNameError):
         exemel.build({'mismatched-name': self.existing_element})
Exemplo n.º 53
0
    def test_custom_root(self):
        actual_xml = exemel.build({}, root='custom')

        expected_xml = '<custom/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 54
0
 def test_in_list_mismatched_name(self):
     with self.assertRaises(exemel.MismatchedElementNameError):
         exemel.build(
             {'mismatched-name': ['foo', self.existing_element, 'bar']})
Exemplo n.º 55
0
    def test_on_root(self):
        actual_xml = exemel.build({'#text': 'foo'})

        expected_xml = '<root>foo</root>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 56
0
    def test_on_root(self):
        actual_xml = exemel.build({'@alpha': 'a', '@bravo': 'b'})

        expected_xml = '<root alpha="a" bravo="b"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 57
0
    def test_boolean_value(self):
        actual_xml = exemel.build({'@test': True})

        expected_xml = '<root test="true"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
Exemplo n.º 58
0
 def test_in_dict_mismatched_name(self):
     with self.assertRaises(exemel.MismatchedElementNameError):
         exemel.build({
             'mismatched-name': self.existing_element
         })
Exemplo n.º 59
0
    def test_on_root(self):
        actual_xml = exemel.build({'#ns': 'fake:ns'})

        expected_xml = '<root xmlns="fake:ns"/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)