aboutsummaryrefslogtreecommitdiffstats
path: root/tests (follow)
Commit message (Collapse)AuthorAgeLines
...
| * | | | | Remove the now deprecated in_channel_check.Gravatar Leon Sandøy2020-05-27-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This check was no longer being used anywhere, having been replaced by in_whitelist_check.
| * | | | | Find + change all InWhitelistCheckFailure importsGravatar Leon Sandøy2020-05-27-2/+1
| | | | | |
| * | | | | Refactor the in_whitelist deco to a check.Gravatar Leon Sandøy2020-05-27-2/+2
| | |_|/ / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We're moving the actual predicate into the `utils.checks` folder, just like we're doing with most of the other decorators. This is to allow us the flexibility to use it as a pure check, not only as a decorator. This commit doesn't actually change any functionality, just moves it around.
* | | | | Floats are no longer permitted as RedisCache keys.Gravatar Leon Sandøy2020-05-27-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also added a test for this. This is the DRYest approach I could find. It's a little ugly, but I think it's probably good enough.
* | | | | Refactor .increment and add lock test.Gravatar Leon Sandøy2020-05-27-64/+99
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The way we were doing the asyncio.Lock() stuff for increment was slightly problematic. @aeros has adviced us that it's better to just initialize the lock as None in __init__, and then initialize it inside the first coroutine that uses it instead. This ensures that the correct loop gets attached to the lock, so we don't end up getting errors like this one: RuntimeError: got Future <Future pending> attached to a different loop This happens because the lock and the actual calling coroutines aren't on the same loop. When creating a new test, test_increment_lock, we discovered that we needed a small refactor here and also in the test class to make this new test pass. So, now we're creating a DummyCog for every test method, and this will ensure the loop streams never cross. Cause we all know we must never cross the streams.
* | | | | Clear cache in asyncSetUp instead of tests.Gravatar Leon Sandøy2020-05-27-6/+1
| | | | |
* | | | | Add a test for RuntimeErrors.Gravatar Leon Sandøy2020-05-26-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This just tests that the various RuntimeErrors are reachable - that includes the error about not having a bot instance, the one about not being a class attribute, and the one about not having instantiated the class. This test addresses a concern raised by @MarkKoz in a review. I've decided not to test that actual contents of these RuntimeErrors, because I believe that sort of testing is a bit too brittle. It shouldn't break a test just to change the content of an error string.
* | | | | Improve output of section name in config validation subtestsGravatar MarkKoz2020-05-25-1/+1
| | | | |
* | | | | Support validating collection types for constantsGravatar MarkKoz2020-05-25-8/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a simple validation that only check the type of the collection. It does not validate the types inside the collection because that has proven to be quite complex.
* | | | | Add support for Union type annotations for constantsGravatar MarkKoz2020-05-24-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Note that `Optional[x]` is just an alias for `Union[None, x]` so this effectively supports `Optional` too. This was especially troublesome because the redis password must be unset/None in order to avoid authentication, but the test would complain that `None` isn't a `str`. Setting to an empty string would pass the test but then make redis authenticate and fail.
* | | | | Improve error and error testing for incrementGravatar Leon Sandøy2020-05-24-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Changed a RuntimeError to a KeyError (thanks @MarkKoz), and also added some tests to ensure that the right errors are raised whenever this method is used incorrectly.
* | | | | MockBot needs to be aware of redis_readyGravatar Leon Sandøy2020-05-24-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Forgot to update the additional_spec_asyncs when changing the name of this Bot attribute to be public.
* | | | | Add .increment and .decrement methods.Gravatar Leon Sandøy2020-05-24-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes, we just want to store a counter in the cache. In this case, it is convenient to have a single method that will allow us to increment or decrement this counter. These methods allow you to decrement or increment floats and integers by an specified amount. By default, it'll increment or decrement by 1. Since this involves several API requests, we create an asyncio.Lock so that we don't end up with race conditions.
* | | | | Make .items return ItemsView instead of AsyncIterGravatar Leon Sandøy2020-05-24-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There really was no compelling reason why this method should return an AsyncIterator or than that `async for items in cache.items()` has nice readability, but there were a few concerns. One is a concern about race conditions raised by @SebastiaanZ, and @MarkKoz raised a concern that it was misleading to have an AsyncIterator that only "pretended" to be lazy. To address these concerns, I've refactored it to return a regular ItemsView instead. I also improved the docstring, and fixed the relevant tests.
* | | | | Remove redis session mock from MockBotGravatar MarkKoz2020-05-23-16/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's not feasible to mock it because all the commands return futures rather than being coroutines, so they cannot automatically be turned into AsyncMocks. Furthermore, no code should ever use the redis session directly besides RedisCache. Since the tests for RedisCache already use fakeredis, there's no use in trying to mock redis in MockBot.
* | | | | DRY approach to typestring prefix resolutionGravatar Leon Sandøy2020-05-23-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Thanks to @kwzrd for this idea, basically we're making a constant with the typestring prefixes and iterating that in all our converters. These converter functions will also now raise TypeErrors if we try to convert something that isn't in this constants list. I've also added a new test that tests this functionality.
* | | | | Fix typo in test_to_dict docstringGravatar Leon Sandøy2020-05-23-1/+1
| | | | |
* | | | | Merge branch 'master' into redis_persistenceGravatar Leon Sandøy2020-05-23-4/+7
|\| | | |
| * | | | Merge branch 'master' into eval-timeout-increaseGravatar Dennis Pham2020-05-19-3/+2
| |\ \ \ \
| | * | | | Use `Command`-object for `send_help`Gravatar Sebastiaan Zeeff2020-05-17-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As @mathsman5133 pointed out, it's better to use the `Command`-instance we typically already have in the current context than to rely on parsing the qualified name again. The invocation is now done as: `await ctx.send_help(ctx.command)`
| | * | | | Use `send_help` to invoke command helpGravatar Sebastiaan Zeeff2020-05-17-2/+1
| | | |_|/ | | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After the refactoring of the help command, we need to use the built-in method of calling the help command: `Context.send_help`. As an argument, the qualified name (a string containing the full command path, including parents) of the command can be passed. Examples: - await ctx.send_help("reminders edit") This would send a help embed with information on `!reminders edit` to the Context. - await ctx.send_help(ctx.command.qualified_name) This would extract the qualified name of the command, which is the full command path, and send a help embed to Context. - await ctx.send_help() This will send the main "root" help embed to the Context.
| * / | | Change tests to use the new timeout constantGravatar Numerlor2020-05-15-1/+5
| |/ / /
* | | | Complete asyncified test suite for RedisCacheGravatar Leon Sandøy2020-05-23-94/+112
| | | | | | | | | | | | | | | | | | | | This commit just alters existing code to work with the new interface, and with async. All tests are passing successfully.
* | | | Finish .set and .get, and add tests.Gravatar Leon Sandøy2020-05-23-12/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The .set and .get will accept ints, floats, and strings. These will be converted into "typestrings", which is basically just a simple format that's been invented for this object. For example, an int looks like `b"i|2423"`. Note how it is still stored as a bytestring (like everything in Redis), but because of this prefix we are able to coerce it into the type we want on the way out of the db.
* | | | Use autospecced mocks in MockBot for the stats and aiohttp sessionGravatar MarkKoz2020-05-22-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | This will help catch anything that tries to get/set an attribute/method which doesn't exist. It'll also catch missing/too many parameters being passed to methods.
* | | | Properly mock the redis pool in MockBotGravatar MarkKoz2020-05-22-9/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Because some of the redis pool/connection methods return futures rather than being coroutines, the redis pool had to be mocked using the CustomMockMixin so it could take advantage of `additional_spec_asyncs` to use AsyncMocks for these future-returning methods.
* | | | Fix unawaited coro warning when instantiating Bot for MockBot's specGravatar MarkKoz2020-05-22-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The fix is to mock the loop and pass it to the Bot. It will then set it as `self.loop` rather than trying to get an event loop from asyncio. The `create_task` patch has been moved to this loop mock rather than being done in MockBot to ensure that it applies to anything calling it when instantiating the Bot.
* | | | Improve aiohttp context manager mocking in snekbox testsGravatar MarkKoz2020-05-22-3/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm not sure how it even managed to work before. It was calling the `post` coroutine (without specifying a URL) and then changing `__aenter__`. Now, a separate mock is created for the context manager and the `post` simply returns that mocked context manager.
* | | | Fix assertion for `create_task` in duck pond testsGravatar MarkKoz2020-05-22-1/+1
| | | | | | | | | | | | | | | | | | | | The assertion wasn't using the assertion method. Furthermore, it was testing a non-existent function `create_loop` rather than `create_task`.
* | | | Set up async testbedGravatar Leon Sandøy2020-05-22-189/+128
| | | |
* | | | Test suite for the redis dict.Gravatar Leon Sandøy2020-05-17-0/+189
|/ / /
* | | 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