Esempio n. 1
0
 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())
Esempio n. 2
0
 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())
Esempio n. 3
0
 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())
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
0
 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, [])
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)
Esempio n. 9
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))
Esempio n. 10
0
 def test_to_string_name(self):
     condition = Condition(name = 'name')
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 11
0
 def test_to_string_regex(self):
     condition = Condition(regex = True)
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 12
0
 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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
0
 def test_to_string_name(self):
     condition = Condition(name='name')
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 16
0
 def test_to_lxml_value(self):
     condition = Condition(value='value')
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Esempio n. 17
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)
Esempio n. 18
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)
Esempio n. 19
0
 def test_to_lxml_name(self):
     condition = Condition(name='name')
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Esempio n. 20
0
 def test_to_string_sub_elements(self):
     condition = Condition(sub_elements=[Permission(), Return()])
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 21
0
 def test_to_string_regex(self):
     condition = Condition(regex=True)
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 22
0
 def test_to_string_value(self):
     condition = Condition(value='value')
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 23
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)
Esempio n. 24
0
 def test_to_lxml_regex(self):
     condition = Condition(regex=True)
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Esempio n. 25
0
 def test_to_lxml_value(self):
     condition = Condition(value = 'value')
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Esempio n. 26
0
 def test_from_string(self):
     text = '<CONDITION />'
     condition = Condition.from_string(text)
     right = Condition()
     self.assertEqual(condition, right)
Esempio n. 27
0
 def test_from_string(self):
     text = '<CONDITION />'
     condition = Condition.from_string(text)
     right = Condition()
     self.assertEqual(condition, right)
Esempio n. 28
0
 def test_from_string_regex(self):
     text = '<CONDITION regex="yes" />'
     condition = Condition.from_string(text)
     right = Condition(regex = True)
     self.assertEqual(condition, right)
Esempio n. 29
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)
Esempio n. 30
0
 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)
Esempio n. 31
0
 def test_from_string_value(self):
     text = '<CONDITION value="test" />'
     condition = Condition.from_string(text)
     right = Condition(value = 'test')
     self.assertEqual(condition, right)
Esempio n. 32
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)
Esempio n. 33
0
 def test_from_lxml(self):
     text = '<CONDITION />'
     condition = Condition.from_lxml_element(etree.XML(text))
     right = Condition()
     self.assertEqual(condition, right)
Esempio n. 34
0
 def test_from_lxml(self):
     text = '<CONDITION />'
     condition = Condition.from_lxml_element(etree.XML(text))
     right = Condition()
     self.assertEqual(condition, right)
Esempio n. 35
0
 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)
Esempio n. 36
0
 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())
Esempio n. 37
0
 def test_from_string_value(self):
     text = '<CONDITION value="test" />'
     condition = Condition.from_string(text)
     right = Condition(value='test')
     self.assertEqual(condition, right)
Esempio n. 38
0
 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())
Esempio n. 39
0
 def test_to_string_value(self):
     condition = Condition(value = 'value')
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 40
0
 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())
Esempio n. 41
0
 def test_to_string_sub_elements(self):
     condition = Condition(sub_elements = [Permission(), Return()])
     copy = Condition.from_string(str(condition))
     self.assertEqual(condition, copy)
Esempio n. 42
0
 def test_from_string_regex(self):
     text = '<CONDITION regex="yes" />'
     condition = Condition.from_string(text)
     right = Condition(regex=True)
     self.assertEqual(condition, right)
Esempio n. 43
0
 def test_to_lxml_name(self):
     condition = Condition(name = 'name')
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Esempio n. 44
0
 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')
Esempio n. 45
0
 def test_to_lxml_regex(self):
     condition = Condition(regex = True)
     copy = Condition.from_lxml_element(condition.to_lxml_element())
     self.assertEqual(condition, copy)
Esempio n. 46
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)
Esempio n. 47
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)
Esempio n. 48
0
 def test_to_string_elements(self):
     slist = SecurityList([Condition(), Return()])
     copy = SecurityList.from_string(str(slist))
     self.assertEqual(slist, copy)
Esempio n. 49
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))
Esempio n. 50
0
 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)
Esempio n. 51
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))
Esempio n. 52
0
 def test_equality(self):
     self.assertEqual(SecurityList([Condition()]),
                      SecurityList([Condition()]))
     self.assertNotEqual(SecurityList([Condition()]), SecurityList([]))
     self.assertNotEqual(SecurityList(), 'another type')