Example #1
0
    def test_should_return_list(self):

        element = XmlElement(
            {'elements': [{
                'name': 'John'
            }, {
                'name': 'Mary'
            }]})

        child1, child2 = element.get_list('/elements')

        self.assertIsInstance(child1, XmlElement)
        self.assertIsInstance(child2, XmlElement)

        self.assertDictEqual({'name': 'John'}, child1.value)
        self.assertDictEqual({'name': 'Mary'}, child2.value)
Example #2
0
    def test_should_return_list_of_elements(self):

        element = XmlElement(
            {'root': {
                'child': [{
                    'name': 'John'
                }, {
                    'name': 'Mary'
                }]
            }})

        child1, child2 = element.get('/root/child')

        self.assertIsInstance(child1, XmlElement)
        self.assertIsInstance(child2, XmlElement)

        self.assertDictEqual({'name': 'John'}, child1.value)
        self.assertDictEqual({'name': 'Mary'}, child2.value)
Example #3
0
 def test_should_wrap_single_element(self):
     element = XmlElement({'element': 'value'})
     self.assertEqual('value', element.get('/element'))
     self.assertListEqual(['value'], element.get_list('/element'))
Example #4
0
 def test_should_return_empty_list(self):
     element = XmlElement({'element': 'value'})
     self.assertListEqual([], element.get_list('/no/such/element'))
Example #5
0
 def test_should_return_none_on_wrong_xpath(self):
     element = XmlElement({'root': {'child': {'child': 'value'}}})
     self.assertIsNone(element.get('/no/such/@element'))
Example #6
0
 def test_should_ignore_leading_and_trailing_slash(self):
     element = XmlElement({'root': {'child': {'child': 'value'}}})
     self.assertEqual('value', element.get('root/child/child/'))
Example #7
0
 def test_should_get_child_recursively(self):
     element = XmlElement({'root': {'child': {'child': 'value'}}})
     self.assertEqual('value', element.get('/root/child/child'))
Example #8
0
 def test_should_repr_elements_value(self):
     element = XmlElement({'child': 'value'})
     self.assertEqual("Element({'child': 'value'})", repr(element))
Example #9
0
 def test_should_check_child_presence(self):
     element = XmlElement({'child1': 'lorem ipsum', 'child2': 'dolor sit'})
     self.assertTrue('child1' in element)
     self.assertTrue('child2' in element)
     self.assertFalse('child3' in element)
Example #10
0
 def test_should_return_element_keys(self):
     element = XmlElement({'child1': 'lorem ipsum', 'child2': 'dolor sit'})
     self.assertListEqual(sorted(['child1', 'child2']),
                          sorted(element.keys()))