aboutsummaryrefslogtreecommitdiffstats
path: root/tests (follow)
Commit message (Collapse)AuthorAgeLines
* Fix multiple match text for token regexGravatar MarkKoz2020-05-25-2/+3
| | | | | | | It has to account for the addition of groups. It's easiest to compare the entire string so `finditer` is used to return re.Match objects; the tuples of `findall` would be cumbersome. Also threw in a change to use `assertCountEqual` cause the order doesn't really matter.
* Fix valid token regex testGravatar MarkKoz2020-05-25-2/+2
| | | | | | | | It was broken due to the addition of groups. Rather than returning the full match, `findall` returns groups if any exist. The test was comparing a tuple of groups to the token string, which was of course failing. Now `fullmatch` is used cause it's simpler - just check for `None` and don't worry about iterating matches to search.
* Add more valid tokens to test the regex withGravatar MarkKoz2020-05-25-3/+5
|
* Test token regex won't match non-base64 charactersGravatar MarkKoz2020-05-25-4/+3
|
* Fix a test needlessly being a coroutineGravatar MarkKoz2020-05-13-1/+1
|
* Use subtests for valid ID/timestamp tests and test non-ASCII inputsGravatar MarkKoz2020-05-11-18/+25
|
* Clean up token remover test importsGravatar MarkKoz2020-05-11-16/+12
|
* Replace deprecated assertion methodsGravatar MarkKoz2020-05-11-2/+2
|
* Refactor `TokenRemoverSetupTests` and add a more thorough testGravatar MarkKoz2020-05-11-4/+8
| | | | | The test now ensures the cog is instantiated and that the instance is passed as an argument to `add_cog`.
* Test TokenRemover.take_actionGravatar MarkKoz2020-05-11-43/+30
| | | | | | | | * Remove `bot.get_cog` mocks in `setUp` * Mock the logger cause it's easier to assert logs * Remove subtests * Assert helper functions were called * Create an autospec for ModLog
* Test TokenRemover.format_log_messageGravatar MarkKoz2020-05-11-0/+16
|
* Test token remover's message deletionGravatar MarkKoz2020-05-11-0/+9
|
* Simplify token remover's message mockGravatar MarkKoz2020-05-11-9/+3
| | | | | * Rely on default values for the author * Set the content to a non-empty string
* Avoid instantiating the cog when testing static/class methodsGravatar MarkKoz2020-05-11-10/+5
|
* Correct the return type annotation for the autospec decoratorGravatar MarkKoz2020-05-11-2/+2
|
* Test token regex matches valid tokensGravatar MarkKoz2020-05-11-0/+21
|
* Test is_maybe_tokenGravatar MarkKoz2020-05-11-7/+24
|
* Test `is_maybe_token` returns False for missing partsGravatar MarkKoz2020-05-11-0/+10
| | | | | | | In practice, this won't ever happen since the regex wouldn't match strings with missing parts. However, the function does check it so may as well test it. It's not necessarily bound to always use inputs from the regex either I suppose.
* Fix autospec decorator when used with multiple attributesGravatar MarkKoz2020-05-11-16/+12
| | | | | | | | The original approach of messing with the `attribute_name` didn't work for reasons I won't discuss here (would require knowledge of patcher internals). The new approach doesn't use patch.multiple but mimics it by applying multiple patch decorators to the function. As a consequence, this can no longer be used as a context manager.
* Test token regex doesn't match invalid tokensGravatar MarkKoz2020-05-11-7/+25
|
* Test `find_token_in_message` returns the found tokenGravatar MarkKoz2020-05-11-0/+24
|
* Test `find_token_in_message` returns None if no matches foundGravatar MarkKoz2020-05-11-0/+14
|
* Fix test for token remover ignoring bot messagesGravatar MarkKoz2020-05-11-4/+9
| | | | | | It's not possible to test this via asserting the return value of `on_message` since it never returns anything. Instead, the actual relevant unit, `find_token_in_message,` should be tested.
* Allow using arbitrary parameter names with the autospec decoratorGravatar MarkKoz2020-05-11-2/+15
| | | | | This gives the caller more flexibility. Sometimes attribute names are too long or they don't follow a naming scheme accepted by the linter.
* Test token remover skips messages without tokensGravatar MarkKoz2020-05-11-0/+11
|
* Test token remover takes action if a token is foundGravatar MarkKoz2020-05-11-1/+13
|
* Add a test helper function to patch multiple attributes with autospecsGravatar MarkKoz2020-05-11-0/+9
| | | | | | This helper reduces redundancy/boilerplate by setting default values. It also has the consequence of shortening the length of the invocation, which makes it faster to use and easier to read.
* Test on_message_edit of token remover uses on_messageGravatar MarkKoz2020-05-11-2/+10
|
* Tests: change avatar_url_as assertion to use static_formatGravatar MarkKoz2020-04-30-1/+1
|
* Add DMChannel tests for in_whitelist decoratorGravatar Sebastiaan Zeeff2020-04-27-31/+63
| | | | | | The `in_whitelist` decorator should not fail when a decorated command was called in a DMChannel; it should simply conclude that the user is not allowed to use the command. I've added a test case that uses a DMChannel context with User, not Member, objects. In addition, I've opted to display a test case description in the `subTest`: Simply printing the actual arguments and context is messy and does not actually show you the information you'd like. This description is enough to figure out which test is failing and what the gist of the test is.
* Add mock for discord.DMChannelsGravatar Sebastiaan Zeeff2020-04-27-0/+21
|
* Exclude never-run lines from coverageGravatar Sebastiaan Zeeff2020-04-27-2/+2
|
* Simplify `in_whitelisted_context` decorator APIGravatar Sebastiaan Zeeff2020-04-23-32/+32
| | | | | | | | | | | | | | | | The API of the `in_whitelisted_context` decorator was a bit clunky: - The long parameter names frequently required multiline decorators - Despite `#bot-commands` being the defacto default, it needed to be passed - The name of the function, `in_whitelisted_context` is fairly long in itself To shorten the call length of the decorator, the parameter names were shortened by dropping the `whitelisted_` prefix. This means that the parameter names are now just `channels`, `categories`, and `roles`. This already means that all current usages of the decorator are reduced to one line. In addition, `#bot-commands` has now been made the default redirect channel for the decorator. This means that if no `redirect` was passed, users will be redirected to `bot-commands` to use the command. If needed, `None` (or any falsey value) can be passed to disable redirection. Passing another channel id will trigger that channel to be used as the redirection target instead of bot-commands. Finally, the name of the decorator was shortened to `in_whitelist`, which already communicates what it is supposed to do.
* Add tests for `in_whitelisted_context` decoratorGravatar Sebastiaan Zeeff2020-04-23-0/+115
| | | | I have added tests for the new `in_whitelisted_context` decorator. They work by calling the decorator with different kwargs to generate a specific predicate callable. That callable is then called to assess if it comes to the right conclusion.
* Remove vestigial kwargs from MockTextChannel.__init__Gravatar Sebastiaan Zeeff2020-04-23-1/+1
|
* Replace `in_channel` decorator by `in_whitelisted_context`Gravatar Sebastiaan Zeeff2020-04-23-2/+2
| | | | | | | | The `in_channel` decorator that served as a factory for `in_channel` checks was replaced by the broaded `in_whitelisted_context` decorator. This means that we can now whitelist commands using channel IDs, category IDs, and/or role IDs. The whitelists will be applied in an "OR" fashion, meaning that as soon as some part of the context happens to be whitelisted, the `predicate` check the decorator produces will return `True`. To reflect that this is now a broader decorator that checks for a whitelisted *context* (as opposed to just whitelisted channels), the exception the predicate raises has been changed to `InWhitelistedContextCheckFailure` to reflect the broader scope of the decorator. I've updated all the commands that used the previous version, `in_channel`, to use the replacement.
* (Syncer Tests): Replaced wrong side effectGravatar ks1292020-04-09-1/+2
| | | Replaced `TimeoutError` with `asyncio.TimeoutError`.
* Set unsilence permissions to inherit instead of trueGravatar Sebastiaan Zeeff2020-03-30-1/+1
| | | | | | The "unsilence" action of the silence/hush command used `send_messages=True` when unsilencing a hushed channel. This had the side effect of also enabling send messages permissions for those with the Muted rule, as an explicit True permission apparently overwrites an explicit False permission, even if the latter was set for a higher top-role. The solution is to revert back to the `Inherit` permission by assigning `None`. This is what we normally use when Developers are allowed to send messages to a channel.
* Merge branch 'master' into hush-cogGravatar Eivind Teig2020-03-30-58/+131
|\
| * Snekbox tests: use `get_code` in `test_continue_eval_does_continue`Gravatar MarkKoz2020-03-25-3/+6
| |
| * Snekbox tests: test `get_code`Gravatar MarkKoz2020-03-25-4/+32
| | | | | | | | | | Should return 1st arg (or None) if eval cmd in message, otherwise return full content.
| * Cog tests: comment some code for clarificationGravatar MarkKoz2020-03-16-0/+3
| |
| * Cog tests: fix error on import due to discord.ext.tasks.loopGravatar MarkKoz2020-03-13-3/+5
| | | | | | | | | | The tasks extensions loop requires an event loop to exist. To work around this, it's been mocked.
| * Cog tests: fix leading space in aliases without parentsGravatar MarkKoz2020-03-13-1/+1
| |
| * Cog tests: add a test for duplicate command names & aliasesGravatar MarkKoz2020-03-13-0/+17
| |
| * Cog tests: fix duplicate commands being yieldedGravatar MarkKoz2020-03-13-1/+2
| | | | | | | | | | discord.py yields duplicate Command objects for each alias a command has, so the duplicates need to be removed on our end.
| * Cog tests: fix nested modules not being foundGravatar MarkKoz2020-03-13-9/+13
| | | | | | | | | | * Rename `walk_extensions` to `walk_modules` because some extensions don't consist of a single module
| * Cog tests: fix duplicate cogs being yieldedGravatar MarkKoz2020-03-13-1/+2
| | | | | | | | Have to check the modules are equal to prevent yielding imported cogs.
| * Cog tests: fix Cog type check in `walk_cogs`Gravatar MarkKoz2020-03-13-3/+3
| |
| * Cog tests: add a function to yield all commandsGravatar MarkKoz2020-03-13-0/+7
| | | | | | | | This will help reduce nesting in the actual test.