Exemple #1
0
 def test_get_diff_on_children_when_sub_element_same(self):
     actual = Block._get_diff_on_children(
         etree.fromstring('<vrId><name>1</name></vrId>'),
         etree.fromstring('<vrId><name>1</name></vrId>'))
     self.assertEqual(actual.tag, 'vrId')
     actual_as_string = etree.tostring(actual).decode('utf-8')
     self.assertTrue('<same><name>1</name></same>' in actual_as_string,
                     actual_as_string)
Exemple #2
0
 def test_get_diff_on_children_when_single_child_changed(self):
     actual = Block._get_diff_on_children(
         etree.fromstring('<vrId><name>2</name></vrId>'),
         etree.fromstring('<vrId><name>1</name></vrId>'))
     self.assertEqual(actual.tag, 'vrId')
     actual_as_string = etree.tostring(actual).decode('utf-8')
     self.assertTrue(
         '<removed><name>2</name></removed>' in actual_as_string)
     self.assertTrue('<added><name>1</name></added>' in actual_as_string)
Exemple #3
0
 def test_get_diff_on_children_when_candidate_child_not_present(self):
     actual = Block._get_diff_on_children(
         etree.fromstring('<vrId><name>2</name><foo>text</foo></vrId>'),
         etree.fromstring('<vrId><name>2</name></vrId>'))
     self.assertEqual(actual.tag, 'vrId')
     actual_as_string = etree.tostring(actual).decode('utf-8')
     self.assertTrue('<same><name>2</name></same>' in actual_as_string)
     self.assertTrue(
         '<removed><foo>text</foo></removed>' in actual_as_string)
Exemple #4
0
 def test_get_diff_on_children_when_candidate_has_extract_elements(self):
     actual = Block._get_diff_on_children(
         etree.fromstring('<vrId><name>2</name></vrId>'),
         etree.fromstring('<vrId><name>2</name><foo>text</foo></vrId>'))
     self.assertEqual(actual.tag, 'vrId')
     actual_as_string = etree.tostring(actual).decode('utf-8')
     self.assertTrue('<same><name>2</name></same>' in actual_as_string,
                     actual_as_string)
     self.assertTrue('<added><foo>text</foo></added>' in actual_as_string,
                     actual_as_string)
Exemple #5
0
 def test_get_diff_on_children_when_running_has_extract_elements(self):
     actual = Block._get_diff_on_children(
         etree.fromstring(
             '<vrfT><dns><ser>1233</ser><ser>1244</ser><ser>1245</ser></dns></vrfT>'
         ),
         etree.fromstring('<vrfT><dns><ser>2</ser></dns></vrfT>'),
     )
     self.assertEqual(actual.tag, 'vrfT')
     actual_as_string = etree.tostring(actual).decode('utf-8')
     self.assertTrue(
         '<removed><ser>1244</ser></removed>' in actual_as_string,
         actual_as_string)
     self.assertTrue(
         '<removed><ser>1233</ser></removed>' in actual_as_string,
         actual_as_string)
     self.assertTrue('<added><ser>2</ser></added>' in actual_as_string,
                     actual_as_string)
Exemple #6
0
    def test_get_diff_on_children_when_many_sub_elements_changed(self):
        running_xml_str = ('<interface>'
                           '<ifName>lo.management</ifName>'
                           '<vrfName>management</vrfName>'
                           '<ipAddr>127.0.0.1/9</ipAddr>'
                           '<mtu>1501</mtu>'
                           '<ipv6Addr><ipv6Addr>::1/128</ipv6Addr></ipv6Addr>'
                           '</interface>')
        actual = Block._get_diff_on_children(
            etree.fromstring(running_xml_str),
            etree.fromstring(
                running_xml_str.replace('127.0.0.1/9', '127.0.0.1/16').replace(
                    '::1/128', '::1/127')))
        self.assertEqual(actual.tag, 'interface')
        actual_as_string = etree.tostring(actual).decode('utf-8')
        self.assertTrue(
            '<same><ifName>lo.management</ifName></same>' in actual_as_string,
            actual_as_string)
        self.assertTrue(
            '<same><vrfName>management</vrfName></same>' in actual_as_string,
            actual_as_string)

        self.assertTrue(
            '<removed><ipAddr>127.0.0.1/9</ipAddr></removed>'
            in actual_as_string, actual_as_string)
        self.assertTrue(
            '<added><ipAddr>127.0.0.1/16</ipAddr></added>' in actual_as_string,
            actual_as_string)

        self.assertTrue('<same><mtu>1501</mtu></same>' in actual_as_string,
                        actual_as_string)

        self.assertTrue(
            '<removed><ipv6Addr>::1/128</ipv6Addr></removed>'
            in actual_as_string, actual_as_string)
        self.assertTrue(
            '<added><ipv6Addr>::1/127</ipv6Addr></added>' in actual_as_string,
            actual_as_string)