def test_empty_recipients_list(self): self.create_user_and_context_data() self.create_preference_data_empty() msg = { "wat": "blah", } preferences = load_preferences() recipients = get_recipients( preferences, msg, self.valid_paths, self.config) self.assertEqual(recipients, {})
def test_miss_recipients_list(self): self.create_user_and_context_data() self.create_preference_data_empty() code_path = "fmn.tests.example_rules:not_wat_rule" self.create_preference_data_basic(code_path) msg = { "wat": "blah", } preferences = load_preferences() recipients = get_recipients( preferences, msg, self.valid_paths, self.config) self.assertEqual(recipients, {})
def test_multiple_different_filters_hit(self): self.create_user_and_context_data() self.create_preference_data_empty() # Tack two identical filters onto the preferenced code_path = "fmn.tests.example_rules:wat_rule" self.create_preference_data_basic(code_path) code_path = "fmn.tests.example_rules:not_wat_rule" self.create_preference_data_basic(code_path) preference = models.Preference.load(self.sess, "ralph.id.fedoraproject.org", "irc") self.assertEqual(len(preference.filters), 2) msg = { "wat": "blah", } preferences = load_preferences() recipients = get_recipients(preferences, msg, self.valid_paths, self.config) expected_recipients = [ { 'triggered_by_links': True, 'markup_messages': False, 'shorten_links': False, 'irc nick': 'threebean', 'user': '******', 'filter_name': 'test filter', 'filter_id': 1, 'filter_oneshot': False, 'verbose': True, }, { 'triggered_by_links': True, 'markup_messages': False, 'shorten_links': False, 'irc nick': 'abadger1999', 'user': '******', 'filter_name': 'test filter 2', 'filter_id': 2, 'filter_oneshot': False, 'verbose': True, }, ] self.assertEqual(expected_recipients, recipients['irc'])
def test_multiple_identical_filters_miss(self): self.create_user_and_context_data() self.create_preference_data_empty() # Tack two identical filters onto the preferenced code_path = "fmn.tests.example_rules:not_wat_rule" self.create_preference_data_basic(code_path) code_path = "fmn.tests.example_rules:not_wat_rule" self.create_preference_data_basic(code_path) preference = models.Preference.load( self.sess, "ralph.id.fedoraproject.org", "irc") self.assertEqual(len(preference.filters), 2) msg = { "wat": "blah", } preferences = load_preferences() recipients = get_recipients( preferences, msg, self.valid_paths, self.config) self.assertEqual(recipients, {})
def test_basic_recipients_list(self): self.create_user_and_context_data() self.create_preference_data_empty() expected_recipients = sorted([ { 'triggered_by_links': True, 'markup_messages': False, 'shorten_links': False, 'irc nick': 'threebean', 'user': '******', 'filter_name': 'test filter', 'filter_id': 1, 'filter_oneshot': False, 'verbose': True, }, { 'triggered_by_links': True, 'markup_messages': False, 'shorten_links': False, 'irc nick': 'abadger1999', 'user': '******', 'filter_name': 'test filter 2', 'filter_id': 2, 'filter_oneshot': False, 'verbose': True, }, ]) code_path = "fmn.tests.example_rules:wat_rule" self.create_preference_data_basic(code_path) msg = { "wat": "blah", } preferences = load_preferences() recipients = get_recipients( preferences, msg, self.valid_paths, self.config) self.assertEqual(expected_recipients, sorted(recipients['irc']))