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())
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)
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)
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))
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))
def test_creation(self): slist = SecurityList() slist = SecurityList([Permission(), Return()])
def test_to_lxml_value(self): ret = Return(value='ALLOW') copy = Return.from_lxml_element(ret.to_lxml_element()) self.assertEqual(ret, copy)
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)
def test_to_lxml(self): ret = Return() copy = Return.from_lxml_element(ret.to_lxml_element()) self.assertEqual(ret, copy)
def test_to_string_full(self): condition = Condition('name', 'value', True, True, [Permission(), Return()]) copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
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)
def test_from_string_value(self): text = '<RETURN value="ALLOW" />' ret = Return.from_string(text) right = Return(value='ALLOW') self.assertEqual(ret, right)
def test_from_string(self): text = '<RETURN />' ret = Return.from_string(text) right = Return() self.assertEqual(ret, right)
def test_equality(self): self.assertEqual(Return('ALLOW'), Return('ALLOW')) self.assertNotEqual(Return('ALLOW'), Return('DENY')) self.assertNotEqual(Return(), 'another type')
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())
def test_creation(self): ret = Return() ret = Return('ALLOW')
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)
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)
def test_from_lxml(self): text = '<RETURN />' ret = Return.from_lxml_element(etree.XML(text)) right = Return() self.assertEqual(ret, right)
def test_to_string_elements(self): slist = SecurityList([Condition(), Return()]) copy = SecurityList.from_string(str(slist)) self.assertEqual(slist, copy)
def test_to_string(self): ret = Return() copy = Return.from_string(str(ret)) self.assertEqual(ret, copy)
def test_to_string_sub_elements(self): condition = Condition(sub_elements=[Permission(), Return()]) copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_from_string_value(self): text = '<RETURN value="ALLOW" />' ret = Return.from_string(text) right = Return(value = 'ALLOW') self.assertEqual(ret, right)
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)
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)
def test_to_string_value(self): ret = Return(value = 'ALLOW') copy = Return.from_string(str(ret)) self.assertEqual(ret, copy)
def test_to_string_value(self): ret = Return(value='ALLOW') copy = Return.from_string(str(ret)) self.assertEqual(ret, copy)
def test_to_lxml_value(self): ret = Return(value = 'ALLOW') copy = Return.from_lxml_element(ret.to_lxml_element()) self.assertEqual(ret, copy)