Пример #1
0
    def test_001_defaults(self):
        """Test condition defaults"""

        config = {'conditions': ['hello']}

        conditions = PluggableConditions(config, self.test_object)

        self.assertTrue(conditions.check('hello'))
        self.assertTrue(conditions.check_final())
Пример #2
0
    def test_002_match(self):
        """Test basic matching"""

        config = {'conditions': [{'match': 'hello'}]}

        conditions = PluggableConditions(config, self.test_object)

        self.assertTrue(conditions.check('hello'))
        self.assertTrue(conditions.check_final())
Пример #3
0
    def test_003_optional(self):
        """Test optional matching"""

        config = {'conditions': [{'optional': 'hello'}]}

        conditions = PluggableConditions(config, self.test_object)

        # Check with no message handled
        self.assertTrue(conditions.check_final())

        # Now check once message handled
        self.assertTrue(conditions.check('hello'))
        self.assertTrue(conditions.check_final())
Пример #4
0
    def test_008_max(self):
        """Test no match condition"""

        config = {'conditions': [{'match': 'hello', 'count': '0'}]}

        conditions = PluggableConditions(config, self.test_object)

        # Check with no message handled
        self.assertTrue(conditions.check_final())

        # Check with one message handled
        self.assertFalse(conditions.check('hello'))
        self.assertTrue(conditions.check_final())  # min met
Пример #5
0
    def test_010_trigger_on_all(self):
        """Test trigger on all option"""

        config = {
            'trigger-on-all':
            True,
            'conditions': [{
                'match': 'hello',
                'count': '1'
            }, {
                'match': 'world',
                'count': '2'
            }]
        }

        conditions = PluggableConditions(config, self.test_object)

        self.assertFalse(conditions.check('world'))
        self.assertFalse(conditions.check_final())

        self.assertFalse(conditions.check('hello'))  # 'world' not met
        self.assertFalse(conditions.check_final())

        self.assertTrue(conditions.check('world'))
        self.assertTrue(conditions.check_final())
Пример #6
0
    def test_010_trigger_on_first(self):
        """Test trigger on first match (other conditions don't apply)"""

        config = {
            'trigger-on-any':
            False,
            'trigger-on-all':
            False,
            'conditions': [{
                'match': 'hello',
                'count': '1'
            }, {
                'match': 'world',
                'count': '2'
            }]
        }

        conditions = PluggableConditions(config, self.test_object)

        self.assertTrue(conditions.check('world'))
        self.assertFalse(conditions.check_final())  # 'hello' & 'world' not met
Пример #7
0
    def test_006_min(self):
        """Test minimum condition"""

        config = {'conditions': [{'match': 'hello', 'count': '>1'}]}

        conditions = PluggableConditions(config, self.test_object)

        # Check with no message handled
        self.assertFalse(conditions.check_final())

        # Check with one message handled
        self.assertFalse(conditions.check('hello'))
        self.assertFalse(conditions.check_final())

        # Check with two messages handled
        self.assertTrue(conditions.check('hello'))
        self.assertTrue(conditions.check_final())
Пример #8
0
    def test_005_count(self):
        """Test range count condition"""

        config = {'conditions': [{'match': 'hello', 'count': '2-4'}]}

        conditions = PluggableConditions(config, self.test_object)

        # Check with no message handled
        self.assertFalse(conditions.check_final())

        # Check with one message handled
        self.assertFalse(conditions.check('hello'))
        self.assertFalse(conditions.check_final())

        # Check with two messages handled
        self.assertTrue(conditions.check('hello'))
        self.assertTrue(conditions.check_final())

        # Check with four messages handled
        self.assertTrue(conditions.check('hello'))
        self.assertTrue(conditions.check('hello'))
        self.assertTrue(conditions.check_final())

        # Check with five messages handled
        self.assertFalse(conditions.check('hello'))
        self.assertTrue(conditions.check_final())  # min met