diff options
| author | 2019-10-13 12:12:11 +0200 | |
|---|---|---|
| committer | 2019-10-13 12:12:11 +0200 | |
| commit | 4cbbe6fd8976f2cf1b2611f04b4ddce2568d9a04 (patch) | |
| tree | 0dc0314451d82bcf4e4c5b1cf09abe82aa383154 /tests/bot | |
| parent | Merge branch 'rules-attachment-tests-unittest' into unittest-migration (diff) | |
| parent | Move test_antispam.py to tests.bot.cogs (diff) | |
Merge branch 'cogs-antispam-unittest' into unittest-migration
Diffstat (limited to '')
| -rw-r--r-- | tests/bot/cogs/test_antispam.py | 35 | 
1 files changed, 35 insertions, 0 deletions
| diff --git a/tests/bot/cogs/test_antispam.py b/tests/bot/cogs/test_antispam.py new file mode 100644 index 000000000..ce5472c71 --- /dev/null +++ b/tests/bot/cogs/test_antispam.py @@ -0,0 +1,35 @@ +import unittest + +from bot.cogs import antispam + + +class AntispamConfigurationValidationTests(unittest.TestCase): +    """Tests validation of the antispam cog configuration.""" + +    def test_default_antispam_config_is_valid(self): +        """The default antispam configuration is valid.""" +        validation_errors = antispam.validate_config() +        self.assertEqual(validation_errors, {}) + +    def test_unknown_rule_returns_error(self): +        """Configuring an unknown rule returns an error.""" +        self.assertEqual( +            antispam.validate_config({'invalid-rule': {}}), +            {'invalid-rule': "`invalid-rule` is not recognized as an antispam rule."} +        ) + +    def test_missing_keys_returns_error(self): +        """Not configuring required keys returns an error.""" +        keys = (('interval', 'max'), ('max', 'interval')) +        for configured_key, unconfigured_key in keys: +            with self.subTest( +                configured_key=configured_key, +                unconfigured_key=unconfigured_key +            ): +                config = {'burst': {configured_key: 10}} +                error = f"Key `{unconfigured_key}` is required but not set for rule `burst`" + +                self.assertEqual( +                    antispam.validate_config(config), +                    {'burst': error} +                ) | 
