diff options
author | 2019-10-12 14:16:20 +0200 | |
---|---|---|
committer | 2019-10-12 14:16:20 +0200 | |
commit | 6d3af7ccbc8a0ff0d9657c562707281a3a7c2ee2 (patch) | |
tree | c97e1f5398f2a1f49ed7c51857fa82d15da90d65 /tests | |
parent | Update README.md (diff) |
Move the `antispam` cog tests to `unittest`.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cogs/__init__.py | 0 | ||||
-rw-r--r-- | tests/cogs/test_antispam.py | 35 |
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/cogs/__init__.py b/tests/cogs/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/cogs/__init__.py diff --git a/tests/cogs/test_antispam.py b/tests/cogs/test_antispam.py new file mode 100644 index 000000000..ce5472c71 --- /dev/null +++ b/tests/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} + ) |