diff options
| author | 2019-10-13 12:11:13 +0200 | |
|---|---|---|
| committer | 2019-10-13 12:11:13 +0200 | |
| commit | 7bd0be0c7dfd0d75ccaa639ccc124fffd9ef785a (patch) | |
| tree | 349cdfd0b0599d801523f629d4ecd3435ab8fd9d /tests/bot | |
| parent | Move the `antispam` cog tests to `unittest`. (diff) | |
Move test_antispam.py to tests.bot.cogs
Diffstat (limited to 'tests/bot')
| -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} + ) |