예제 #1
0
 def test_in_list_mismatched_name(self):
     with self.assertRaises(exemel.MismatchedElementNameError):
         exemel.build({
             'mismatched-name': [
                 'foo',
                 self.existing_element,
                 'bar'
             ]
         })
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #8
0
    def test_empty_list(self):
        actual_xml = exemel.build({
            'myList': []
        })

        expected_xml = '<root/>'

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

        expected_xml = '<root/>'

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

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #11
0
    def test_boolean_value(self):
        actual_xml = exemel.build({
            '@test': True
        })

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #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)
예제 #13
0
    def test_int_value(self):
        actual_xml = exemel.build({
            '@test': 0
        })

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #22
0
    def test_none_value(self):
        actual_xml = exemel.build({
            'alpha': None,
        })

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #23
0
    def test_none_value(self):
        actual_xml = exemel.build({
            'alpha': None,
        })

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #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)
예제 #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)
예제 #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)
예제 #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
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #45
0
    def test_root_is_empty_dict(self):
        actual_xml = exemel.build({})

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #46
0
    def test_int_value(self):
        actual_xml = exemel.build({'@test': 0})

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #47
0
    def test_root_is_empty_dict(self):
        actual_xml = exemel.build({})

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #48
0
    def test_empty_list(self):
        actual_xml = exemel.build({'myList': []})

        expected_xml = '<root/>'

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

        expected_xml = '<root/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #50
0
    def test_custom_root(self):
        actual_xml = exemel.build({}, root='custom')

        expected_xml = '<custom/>'

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #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)
예제 #52
0
 def test_in_dict_mismatched_name(self):
     with self.assertRaises(exemel.MismatchedElementNameError):
         exemel.build({'mismatched-name': self.existing_element})
예제 #53
0
    def test_custom_root(self):
        actual_xml = exemel.build({}, root='custom')

        expected_xml = '<custom/>'

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

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #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)
예제 #57
0
    def test_boolean_value(self):
        actual_xml = exemel.build({'@test': True})

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

        self.assertXmlEquivalentOutputs(actual_xml, expected_xml)
예제 #58
0
 def test_in_dict_mismatched_name(self):
     with self.assertRaises(exemel.MismatchedElementNameError):
         exemel.build({
             'mismatched-name': self.existing_element
         })
예제 #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)