示例#1
0
文件: test_tasks.py 项目: mavit/fmn
    def test_user_preferences(self):
        """Assert the user preferences are lazy-loaded on attribute access."""
        find_recipients = tasks._FindRecipients()
        expected_preferences = fmn_lib.load_preferences(
            cull_disabled=True, cull_backends=['desktop'])

        self.assertTrue(find_recipients._user_preferences is None)
        self.assertEqual(expected_preferences, find_recipients.user_preferences)
        self.assertTrue(find_recipients._user_preferences is find_recipients.user_preferences)
示例#2
0
文件: test_lib.py 项目: fmarier/fmn
    def test_load_preferences_skip_disabled(self):
        """Assert all preferences are loaded, excepting disabled preferences"""
        preferences = load_preferences(cull_disabled=True)
        self.assertEqual(1, len(preferences))

        pref = models.Preference.query.filter(
            models.Preference.openid == 'jcline',
            models.Preference.context_name == 'pidgeon').first()
        self.assertEqual(pref.__json__(reify=True), preferences['jcline_pidgeon'])
示例#3
0
文件: test_lib.py 项目: fmarier/fmn
    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, {})
示例#4
0
文件: test_lib.py 项目: fmarier/fmn
    def test_load_preferences_cull_backends(self):
        """Assert all preferences are loaded, excepting specified backends"""
        preferences = load_preferences(cull_backends=['pidgeon'])
        self.assertEqual(2, len(preferences))

        for key in ('jcline_post', 'bowlofeggs_post'):
            self.assertTrue(key in preferences)
            openid, context = key.split('_')
            pref = models.Preference.query.filter(
                models.Preference.openid == openid,
                models.Preference.context_name == context).first()
            self.assertEqual(pref.__json__(reify=True), preferences[key])
示例#5
0
文件: test_lib.py 项目: fmarier/fmn
    def test_load_all_preferences(self):
        """Assert all preferences including disabled are loaded by default"""
        preferences = load_preferences()
        self.assertEqual(3, len(preferences))

        for key in ('jcline_pidgeon', 'jcline_post', 'bowlofeggs_post'):
            self.assertTrue(key in preferences)
            openid, context = key.split('_')
            pref = models.Preference.query.filter(
                models.Preference.openid == openid,
                models.Preference.context_name == context).first()
            self.assertEqual(pref.__json__(reify=True), preferences[key])
示例#6
0
文件: test_lib.py 项目: fmarier/fmn
    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, {})
示例#7
0
    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'])
示例#8
0
文件: test_lib.py 项目: fmarier/fmn
    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, {})
示例#9
0
文件: test_lib.py 项目: fmarier/fmn
    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']))