Ejemplo n.º 1
0
    def security_list_test(self):
        text = '''
<SECURITY custom="unknown">
  <CONDITION />
  <RETURN />
  <UNKNOWN>
    <CUSTOM />
  </UNKNOWN>
</SECURITY>'''
        slist = SecurityList.from_string(text)
        tree = slist.to_lxml_element()
        self.assertEqual('unknown', tree.get('custom'))
        unknown = tree.findall('UNKNOWN')
        self.assertEqual(1, len(unknown))
        unknown = unknown[0]
        custom = list(unknown)
        self.assertEqual(1, len(custom))
        custom = custom[0]
        self.assertEqual('CUSTOM', custom.tag)
Ejemplo n.º 2
0
    def security_list_test(self):
        text = '''
<SECURITY custom="unknown">
  <CONDITION />
  <RETURN />
  <UNKNOWN>
    <CUSTOM />
  </UNKNOWN>
</SECURITY>'''
        slist = SecurityList.from_string(text)
        tree = slist.to_lxml_element()
        self.assertEqual('unknown', tree.get('custom'))
        unknown = tree.findall('UNKNOWN')
        self.assertEqual(1, len(unknown))
        unknown = unknown[0]
        custom = list(unknown)
        self.assertEqual(1, len(custom))
        custom = custom[0]
        self.assertEqual('CUSTOM', custom.tag)
Ejemplo n.º 3
0
 def test_from_string(self):
     text = '<SECURITY />'
     slist = SecurityList.from_string(text)
     right = SecurityList()
     self.assertEqual(slist, right)
Ejemplo n.º 4
0
 def test_elements(self):
     element_0 = Condition()
     element_1 = Return()
     slist = SecurityList()
     self.assertEqual(0, len(slist.get_elements()))
     slist.add_element(element_0)
     self.assertEqual(1, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     slist.add_element(element_1)
     self.assertEqual(2, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     self.assertEqual(element_1, slist.get_element(1))
     slist.remove_element(0)
     self.assertEqual(1, len(slist.get_elements()))
     self.assertEqual(element_1, slist.get_element(0))
     slist.add_element(element_0, 0)
     self.assertEqual(2, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     self.assertEqual(element_1, slist.get_element(1))
     self.assertRaises(IndexError, slist.get_element, 2)
     slist = SecurityList(elements = [element_0, element_1])
     self.assertEqual(2, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     self.assertEqual(element_1, slist.get_element(1))
Ejemplo n.º 5
0
 def test_to_string_elements(self):
     slist = SecurityList([Condition(), Return()])
     copy = SecurityList.from_lxml_element(slist.to_lxml_element())
     self.assertEqual(slist, copy)
Ejemplo n.º 6
0
 def test_to_lxml(self):
     slist = SecurityList()
     copy = SecurityList.from_lxml_element(slist.to_lxml_element())
     self.assertEqual(slist, copy)
Ejemplo n.º 7
0
 def test_to_string(self):
     slist = SecurityList()
     copy = SecurityList.from_string(str(slist))
     self.assertEqual(slist, copy)
Ejemplo n.º 8
0
 def test_from_lxml_elements(self):
     text = '<SECURITY><CONDITION /><RETURN /></SECURITY>'
     slist = SecurityList.from_lxml_element(etree.XML(text))
     right = SecurityList([Condition(), Return()])
     self.assertEqual(slist, right)
Ejemplo n.º 9
0
 def test_to_string(self):
     slist = SecurityList()
     copy = SecurityList.from_string(str(slist))
     self.assertEqual(slist, copy)
Ejemplo n.º 10
0
 def test_from_string(self):
     text = '<SECURITY />'
     slist = SecurityList.from_string(text)
     right = SecurityList()
     self.assertEqual(slist, right)
Ejemplo n.º 11
0
 def test_from_lxml(self):
     text = '<SECURITY />'
     slist = SecurityList.from_lxml_element(etree.XML(text))
     right = SecurityList()
     self.assertEqual(slist, right)
Ejemplo n.º 12
0
 def test_equality(self):
     self.assertEqual(SecurityList([Condition()]),
                      SecurityList([Condition()]))
     self.assertNotEqual(SecurityList([Condition()]), SecurityList([]))
     self.assertNotEqual(SecurityList(), 'another type')
Ejemplo n.º 13
0
 def test_elements(self):
     element_0 = Condition()
     element_1 = Return()
     slist = SecurityList()
     self.assertEqual(0, len(slist.get_elements()))
     slist.add_element(element_0)
     self.assertEqual(1, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     slist.add_element(element_1)
     self.assertEqual(2, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     self.assertEqual(element_1, slist.get_element(1))
     slist.remove_element(0)
     self.assertEqual(1, len(slist.get_elements()))
     self.assertEqual(element_1, slist.get_element(0))
     slist.add_element(element_0, 0)
     self.assertEqual(2, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     self.assertEqual(element_1, slist.get_element(1))
     self.assertRaises(IndexError, slist.get_element, 2)
     slist = SecurityList(elements=[element_0, element_1])
     self.assertEqual(2, len(slist.get_elements()))
     self.assertEqual(element_0, slist.get_element(0))
     self.assertEqual(element_1, slist.get_element(1))
Ejemplo n.º 14
0
 def test_creation(self):
     slist = SecurityList()
     slist = SecurityList([Permission(), Return()])
Ejemplo n.º 15
0
 def test_from_lxml(self):
     text = '<SECURITY />'
     slist = SecurityList.from_lxml_element(etree.XML(text))
     right = SecurityList()
     self.assertEqual(slist, right)
Ejemplo n.º 16
0
 def test_to_string_elements(self):
     slist = SecurityList([Condition(), Return()])
     copy = SecurityList.from_string(str(slist))
     self.assertEqual(slist, copy)
Ejemplo n.º 17
0
 def test_from_lxml_elements(self):
     text = '<SECURITY><CONDITION /><RETURN /></SECURITY>'
     slist = SecurityList.from_lxml_element(etree.XML(text))
     right = SecurityList([Condition(), Return()])
     self.assertEqual(slist, right)
Ejemplo n.º 18
0
 def test_to_lxml(self):
     slist = SecurityList()
     copy = SecurityList.from_lxml_element(slist.to_lxml_element())
     self.assertEqual(slist, copy)