Ejemplo n.º 1
0
 def test_value(self):
     ret = Return('ALLOW')
     self.assertEqual('ALLOW', ret.get_value())
     ret.set_value('DENY')
     self.assertEqual('DENY', ret.get_value())
     ret.set_value(None)
     self.assertEqual(None, ret.get_value())
     ret = Return(value = 'ALLOW')
     self.assertEqual('ALLOW', ret.get_value())
Ejemplo n.º 2
0
    def test_from_lxml_full(self):
        text = '''
<CONDITION name="name" value="value" not="yes" regex="yes">
  <PERMISSION />
  <RETURN />
</CONDITION>'''
        condition = Condition.from_lxml_element(etree.XML(text))
        right = Condition('name', 'value', True, True,
                          [Permission(), Return()])
        self.assertEqual(condition, right)
Ejemplo n.º 3
0
    def return_test(self):
        text = '''
<RETURN custom="unknown">
  <UNKNOWN>
    <CUSTOM />
  </UNKNOWN>
</RETURN>'''
        ret = Return.from_string(text)
        tree = ret.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.º 4
0
    def return_test(self):
        text = '''
<RETURN custom="unknown">
  <UNKNOWN>
    <CUSTOM />
  </UNKNOWN>
</RETURN>'''
        ret = Return.from_string(text)
        tree = ret.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.º 5
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.º 6
0
 def test_sub_elements(self):
     element_0 = Condition()
     element_1 = Return()
     condition = Condition()
     self.assertEqual(0, len(condition.get_sub_elements()))
     condition.add_sub_element(element_0)
     self.assertEqual(1, len(condition.get_sub_elements()))
     self.assertEqual(element_0, condition.get_sub_element(0))
     condition.add_sub_element(element_1)
     self.assertEqual(2, len(condition.get_sub_elements()))
     self.assertEqual(element_0, condition.get_sub_element(0))
     self.assertEqual(element_1, condition.get_sub_element(1))
     condition.remove_sub_element(0)
     self.assertEqual(1, len(condition.get_sub_elements()))
     self.assertEqual(element_1, condition.get_sub_element(0))
     condition.add_sub_element(element_0, 0)
     self.assertEqual(2, len(condition.get_sub_elements()))
     self.assertEqual(element_0, condition.get_sub_element(0))
     self.assertEqual(element_1, condition.get_sub_element(1))
     self.assertRaises(IndexError, condition.get_sub_element, 2)
     condition = Condition(sub_elements=[element_0, element_1])
     self.assertEqual(2, len(condition.get_sub_elements()))
     self.assertEqual(element_0, condition.get_sub_element(0))
     self.assertEqual(element_1, condition.get_sub_element(1))
Ejemplo n.º 7
0
 def test_creation(self):
     slist = SecurityList()
     slist = SecurityList([Permission(), Return()])
Ejemplo n.º 8
0
 def test_to_lxml_value(self):
     ret = Return(value='ALLOW')
     copy = Return.from_lxml_element(ret.to_lxml_element())
     self.assertEqual(ret, copy)
Ejemplo n.º 9
0
 def test_from_lxml_sub_elements(self):
     text = '<CONDITION><PERMISSION /><RETURN /></CONDITION>'
     condition = Condition.from_lxml_element(etree.XML(text))
     right = Condition(sub_elements=[Permission(), Return()])
     self.assertEqual(condition, right)
Ejemplo n.º 10
0
 def test_to_lxml(self):
     ret = Return()
     copy = Return.from_lxml_element(ret.to_lxml_element())
     self.assertEqual(ret, copy)
Ejemplo n.º 11
0
 def test_to_string_full(self):
     condition = Condition('name', 'value', True, True,
                           [Permission(), Return()])
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Ejemplo n.º 12
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.º 13
0
 def test_from_string_value(self):
     text = '<RETURN value="ALLOW" />'
     ret = Return.from_string(text)
     right = Return(value='ALLOW')
     self.assertEqual(ret, right)
Ejemplo n.º 14
0
 def test_from_string(self):
     text = '<RETURN />'
     ret = Return.from_string(text)
     right = Return()
     self.assertEqual(ret, right)
Ejemplo n.º 15
0
 def test_equality(self):
     self.assertEqual(Return('ALLOW'), Return('ALLOW'))
     self.assertNotEqual(Return('ALLOW'), Return('DENY'))
     self.assertNotEqual(Return(), 'another type')
Ejemplo n.º 16
0
 def test_value(self):
     ret = Return('ALLOW')
     self.assertEqual('ALLOW', ret.get_value())
     ret.set_value('DENY')
     self.assertEqual('DENY', ret.get_value())
     ret.set_value(None)
     self.assertEqual(None, ret.get_value())
     ret = Return(value='ALLOW')
     self.assertEqual('ALLOW', ret.get_value())
Ejemplo n.º 17
0
 def test_creation(self):
     ret = Return()
     ret = Return('ALLOW')
Ejemplo n.º 18
0
 def test_to_lxml_full(self):
     condition = Condition('name', 'value', True, True,
                           [Permission(), Return()])
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Ejemplo n.º 19
0
 def test_to_lxml_sub_elements(self):
     condition = Condition(sub_elements=[Permission(), Return()])
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Ejemplo n.º 20
0
 def test_from_string(self):
     text = '<RETURN />'
     ret = Return.from_string(text)
     right = Return()
     self.assertEqual(ret, right)
Ejemplo n.º 21
0
 def test_from_lxml(self):
     text = '<RETURN />'
     ret = Return.from_lxml_element(etree.XML(text))
     right = Return()
     self.assertEqual(ret, right)
Ejemplo n.º 22
0
 def test_to_string_elements(self):
     slist = SecurityList([Condition(), Return()])
     copy = SecurityList.from_string(str(slist))
     self.assertEqual(slist, copy)
Ejemplo n.º 23
0
 def test_to_string(self):
     ret = Return()
     copy = Return.from_string(str(ret))
     self.assertEqual(ret, copy)
Ejemplo n.º 24
0
 def test_from_lxml(self):
     text = '<RETURN />'
     ret = Return.from_lxml_element(etree.XML(text))
     right = Return()
     self.assertEqual(ret, right)
Ejemplo n.º 25
0
 def test_to_string_sub_elements(self):
     condition = Condition(sub_elements=[Permission(), Return()])
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Ejemplo n.º 26
0
 def test_from_string_value(self):
     text = '<RETURN value="ALLOW" />'
     ret = Return.from_string(text)
     right = Return(value = 'ALLOW')
     self.assertEqual(ret, right)
Ejemplo n.º 27
0
 def test_from_lxml_value(self):
     text = '<RETURN value="ALLOW" />'
     ret = Return.from_lxml_element(etree.XML(text))
     right = Return(value='ALLOW')
     self.assertEqual(ret, right)
Ejemplo n.º 28
0
 def test_from_lxml_value(self):
     text = '<RETURN value="ALLOW" />'
     ret = Return.from_lxml_element(etree.XML(text))
     right = Return(value = 'ALLOW')
     self.assertEqual(ret, right)
Ejemplo n.º 29
0
 def test_to_string(self):
     ret = Return()
     copy = Return.from_string(str(ret))
     self.assertEqual(ret, copy)
Ejemplo n.º 30
0
 def test_to_string_value(self):
     ret = Return(value = 'ALLOW')
     copy = Return.from_string(str(ret))
     self.assertEqual(ret, copy)
Ejemplo n.º 31
0
 def test_to_string_value(self):
     ret = Return(value='ALLOW')
     copy = Return.from_string(str(ret))
     self.assertEqual(ret, copy)
Ejemplo n.º 32
0
 def test_to_lxml_value(self):
     ret = Return(value = 'ALLOW')
     copy = Return.from_lxml_element(ret.to_lxml_element())
     self.assertEqual(ret, copy)
Ejemplo n.º 33
0
 def test_to_lxml(self):
     ret = Return()
     copy = Return.from_lxml_element(ret.to_lxml_element())
     self.assertEqual(ret, copy)