def test_regex(self): condition = Condition('name1', 'value1', False, False) self.assertFalse(condition.get_regex()) condition.set_regex(True) self.assertTrue(condition.get_regex()) condition.set_regex(None) self.assertEqual(None, condition.get_regex()) condition = Condition(regex = True) self.assertTrue(condition.get_regex())
def test_name(self): condition = Condition('name1') self.assertEqual('name1', condition.get_name()) condition.set_name('name2') self.assertEqual('name2', condition.get_name()) condition.set_name(None) self.assertEqual(None, condition.get_name()) condition = Condition(name = 'name1') self.assertEqual('name1', condition.get_name())
def test_value(self): condition = Condition('name1', 'value1') self.assertEqual('value1', condition.get_value()) condition.set_value('value2') self.assertEqual('value2', condition.get_value()) condition.set_value(None) self.assertEqual(None, condition.get_value()) condition = Condition(value = 'value1') self.assertEqual('value1', condition.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 test_creation(self): condition = Condition() condition = Condition('name') condition = Condition('name', 'value') condition = Condition('name', 'value', False) condition = Condition('name', 'value', False, False) condition = Condition('name', 'value', False, False, [])
def condition_test(self): text = ''' <CONDITION custom="unknown"> <PERMISSION /> <UNKNOWN> <CUSTOM /> </UNKNOWN> </CONDITION>''' condition = Condition.from_string(text) tree = condition.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_to_string_name(self): condition = Condition(name = 'name') copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_to_string_regex(self): condition = Condition(regex = True) copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_from_lxml_value(self): text = '<CONDITION value="test" />' condition = Condition.from_lxml_element(etree.XML(text)) right = Condition(value = 'test') self.assertEqual(condition, right)
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_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_string_name(self): condition = Condition(name='name') copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_to_lxml_value(self): condition = Condition(value='value') 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_to_string_full(self): condition = Condition('name', 'value', True, True, [Permission(), Return()]) copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_to_lxml_name(self): condition = Condition(name='name') copy = Condition.from_lxml_element(condition.to_lxml_element()) self.assertEqual(condition, 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_to_string_regex(self): condition = Condition(regex=True) copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_to_string_value(self): condition = Condition(value='value') copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_to_lxml_regex(self): condition = Condition(regex=True) copy = Condition.from_lxml_element(condition.to_lxml_element()) self.assertEqual(condition, copy)
def test_to_lxml_value(self): condition = Condition(value = 'value') copy = Condition.from_lxml_element(condition.to_lxml_element()) self.assertEqual(condition, copy)
def test_from_string(self): text = '<CONDITION />' condition = Condition.from_string(text) right = Condition() self.assertEqual(condition, right)
def test_from_string_regex(self): text = '<CONDITION regex="yes" />' condition = Condition.from_string(text) right = Condition(regex = True) self.assertEqual(condition, right)
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_value(self): text = '<CONDITION value="test" />' condition = Condition.from_lxml_element(etree.XML(text)) right = Condition(value='test') self.assertEqual(condition, right)
def test_from_string_value(self): text = '<CONDITION value="test" />' condition = Condition.from_string(text) right = Condition(value = 'test') self.assertEqual(condition, right)
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_from_lxml(self): text = '<CONDITION />' condition = Condition.from_lxml_element(etree.XML(text)) right = Condition() self.assertEqual(condition, right)
def test_from_lxml_regex(self): text = '<CONDITION regex="yes" />' condition = Condition.from_lxml_element(etree.XML(text)) right = Condition(regex = True) self.assertEqual(condition, right)
def test_name(self): condition = Condition('name1') self.assertEqual('name1', condition.get_name()) condition.set_name('name2') self.assertEqual('name2', condition.get_name()) condition.set_name(None) self.assertEqual(None, condition.get_name()) condition = Condition(name='name1') self.assertEqual('name1', condition.get_name())
def test_from_string_value(self): text = '<CONDITION value="test" />' condition = Condition.from_string(text) right = Condition(value='test') self.assertEqual(condition, right)
def test_value(self): condition = Condition('name1', 'value1') self.assertEqual('value1', condition.get_value()) condition.set_value('value2') self.assertEqual('value2', condition.get_value()) condition.set_value(None) self.assertEqual(None, condition.get_value()) condition = Condition(value='value1') self.assertEqual('value1', condition.get_value())
def test_to_string_value(self): condition = Condition(value = 'value') copy = Condition.from_string(str(condition)) self.assertEqual(condition, copy)
def test_regex(self): condition = Condition('name1', 'value1', False, False) self.assertFalse(condition.get_regex()) condition.set_regex(True) self.assertTrue(condition.get_regex()) condition.set_regex(None) self.assertEqual(None, condition.get_regex()) condition = Condition(regex=True) self.assertTrue(condition.get_regex())
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_regex(self): text = '<CONDITION regex="yes" />' condition = Condition.from_string(text) right = Condition(regex=True) self.assertEqual(condition, right)
def test_to_lxml_name(self): condition = Condition(name = 'name') copy = Condition.from_lxml_element(condition.to_lxml_element()) self.assertEqual(condition, copy)
def test_equality(self): self.assertEqual(Condition('name1', 'value1', False, False, []), Condition('name1', 'value1', False, False, [])) self.assertNotEqual(Condition('name1', 'value1', False, False, []), Condition('name2', 'value1', False, False, [])) self.assertNotEqual(Condition('name1', 'value1', False, False, []), Condition('name1', 'value2', False, False, [])) self.assertNotEqual(Condition('name1', 'value1', False, False, []), Condition('name1', 'value1', True, False, [])) self.assertNotEqual(Condition('name1', 'value1', False, False, []), Condition('name1', 'value1', False, True, [])) self.assertNotEqual( Condition('name1', 'value1', False, False, []), Condition('name1', 'value1', False, False, [Condition()])) self.assertNotEqual(Condition(), 'another type')
def test_to_lxml_regex(self): condition = Condition(regex = True) copy = Condition.from_lxml_element(condition.to_lxml_element()) 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_to_string_elements(self): slist = SecurityList([Condition(), Return()]) copy = SecurityList.from_string(str(slist)) self.assertEqual(slist, copy)
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_from_lxml_regex(self): text = '<CONDITION regex="yes" />' condition = Condition.from_lxml_element(etree.XML(text)) right = Condition(regex=True) self.assertEqual(condition, right)
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_equality(self): self.assertEqual(SecurityList([Condition()]), SecurityList([Condition()])) self.assertNotEqual(SecurityList([Condition()]), SecurityList([])) self.assertNotEqual(SecurityList(), 'another type')