Skip to content

Move the token_remover cog tests to unittest.#526

Closed
jchristgit wants to merge 31 commits into
unittest-migrationfrom
cogs-tokenremover-unittest
Closed

Move the token_remover cog tests to unittest.#526
jchristgit wants to merge 31 commits into
unittest-migrationfrom
cogs-tokenremover-unittest

Conversation

@jchristgit
Copy link
Copy Markdown
Contributor

No description provided.

@jchristgit jchristgit added a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) a: CI Related to continuous intergration and deployment type: tests labels Oct 12, 2019
Comment thread tests/cogs/test_token_remover.py Outdated
Comment thread tests/cogs/test_token_remover.py Outdated
self.bot.get_cog.return_value.send_log_message = AsyncMock()
self.cog = TokenRemover(bot=self.bot)

self.msg = MagicMock()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a good idea to create a mock helper for messages and use mocks with specs for some of the attributes here (like the author and channel).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems reasonable to me.

I think we should factor out the mocking of those Discord "Model" that we use a lot and typically require the same or a very similar set-up. Since it does mean we'd basically have to maintain and test a small discord.py mocking library, I'd say we should restrict it those those base models though. I think that with a set of Member, Guild, Role, Message, TextChannel, Context, Bot, and Role we've covered a lot of things that we typically usr.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkKoz @jchristgit I'm going to add a couple more specific mocks and tests, but I'll resolve this during the merge.

Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz Oct 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means this should be left alone for now?

Comment thread tests/cogs/test_token_remover.py Outdated
This commit introduces some new Mock-types to the already existing
Mock-types for discord.py objects. The total list is now:

- MockGuild
- MockRole
- MockMember
- MockBot
- MockContext
- MockTextChannel
- MockMessage

In addition, I've added all coroutines in the documentation for these
discord.py objects as `AsyncMock` attributes to ease testing. Tests
ensure that the attributes set for the Mocks exist for the actual
discord.py objects as well.
@SebastiaanZ SebastiaanZ requested a review from MarkKoz October 14, 2019 20:19
jchristgit and others added 5 commits October 14, 2019 22:20
This commit replaces the standard MagicMocks by our specialized mocks
for discord.py objects. It also adds the missing `channel` attribute
to the `tests.helpers.MockMessage` mock and moves the file to the
correct folder.
@SebastiaanZ
Copy link
Copy Markdown
Contributor

Uhm, I messed up the git history... But, I've merged this correctly on the command line, so I'm just going to close this. Sorry for that. (Please don't hurt me.)

@jchristgit jchristgit deleted the cogs-tokenremover-unittest branch October 17, 2019 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) a: CI Related to continuous intergration and deployment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants