Пример #1
0
 def test_regex_black_list(self):
     events = list(
         set([
             "".join(sample(letters, event_name_size))
             for i in range(samples_to_test)
         ]))
     none_event_listener = ami.EventListener(black_list=re.compile('.*'))
     for event_name in events:
         self.assertFalse(none_event_listener.check_event_name(event_name))
     all_event_listener = ami.EventListener(
         black_list=[re.compile('[0-9]+')])
     for event_name in events:
         self.assertTrue(all_event_listener.check_event_name(event_name))
Пример #2
0
 def test_attr_filter(self):
     event_listener = ami.EventListener(on_event=self.receive_event,
                                        Value1='teste')
     self.assertIsNone(
         event_listener(event=self.build_some_event(Value1='null')))
     self.assertTrue(
         event_listener(event=self.build_some_event(Value1='teste')))
     event_listener = ami.EventListener(on_event=self.receive_event,
                                        Value1=re.compile('^t.*'))
     self.assertIsNone(
         event_listener(event=self.build_some_event(Value1='null')))
     self.assertTrue(
         event_listener(event=self.build_some_event(Value1='teste')))
Пример #3
0
 def test_multiple_attr_filter(self):
     event_listener = ami.EventListener(on_event=self.receive_event,
                                        Value1=['teste', 'None'])
     self.assertIsNone(
         event_listener(event=self.build_some_event(Value1='null')))
     self.assertTrue(
         event_listener(event=self.build_some_event(Value1='teste')))
     self.assertTrue(
         event_listener(event=self.build_some_event(Value1='None')))
     event_listener = ami.EventListener(
         on_event=self.receive_event,
         Value1=[re.compile('^t.*'), re.compile('a')])
     self.assertIsNone(
         event_listener(event=self.build_some_event(Value1='null')))
     self.assertTrue(
         event_listener(event=self.build_some_event(Value1='teste')))
     self.assertTrue(
         event_listener(event=self.build_some_event(Value1='__a__')))
Пример #4
0
 def test_string_black_list(self):
     string_rules = list(
         set([
             "".join(sample(letters, event_name_size))
             for i in range(samples_to_test)
         ]))
     in_black_list = string_rules[:int(len(string_rules) / 2)]
     out_black_list = string_rules[int(len(string_rules) / 2):]
     event_listener = ami.EventListener(black_list=in_black_list)
     for rule in in_black_list:
         self.assertFalse(event_listener.check_event_name(rule))
     for rule in out_black_list:
         self.assertTrue(event_listener.check_event_name(rule))
Пример #5
0
 def test_on_event(self):
     event_listener = ami.EventListener(on_event=self.receive_event)
     result = event_listener(event=self.build_some_event(), source=self)
     self.assertTrue(result)
Пример #6
0
 def test_empty_black_list(self):
     event_listener = ami.EventListener(black_list=[])
     for i in range(samples_to_test):
         event_name = sample(letters, event_name_size)
         self.assertTrue(event_listener.check_event_name(event_name))
Пример #7
0
 def test_empty_white_list(self):
     event_listener = ami.EventListener(white_list=[])
     for i in range(samples_to_test):
         event_name = "".join(sample(letters, event_name_size))
         self.assertFalse(event_listener.check_event_name(event_name))