aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-01-31 14:04:17 -0800
committerGravatar MarkKoz <[email protected]>2020-02-12 10:07:56 -0800
commit948661e3738ae2bd2636631bf2a91c1589aa0bde (patch)
treee19e2b16debad3c071e691b8d4ff47cbf7164b8c /tests
parentSync tests: create a test case for listener tests (diff)
Sync tests: test Sync cog's on_guild_role_create listener
A POST request should be sent with the new role's data. * Add a fixture to create a MockRole
Diffstat (limited to 'tests')
-rw-r--r--tests/bot/cogs/sync/test_cog.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/bot/cogs/sync/test_cog.py b/tests/bot/cogs/sync/test_cog.py
index d71366791..a4969551d 100644
--- a/tests/bot/cogs/sync/test_cog.py
+++ b/tests/bot/cogs/sync/test_cog.py
@@ -1,7 +1,10 @@
import asyncio
+import typing as t
import unittest
from unittest import mock
+import discord
+
from bot import constants
from bot.api import ResponseCodeError
from bot.cogs import sync
@@ -139,3 +142,29 @@ class SyncCogListenerTests(SyncCogTestCase):
def setUp(self):
super().setUp()
self.cog.patch_user = helpers.AsyncMock(spec_set=self.cog.patch_user)
+
+ @staticmethod
+ def mock_role() -> t.Tuple[helpers.MockRole, t.Dict[str, t.Any]]:
+ """Fixture to return a MockRole and corresponding JSON dict."""
+ colour = 49
+ permissions = 8
+ role_data = {
+ "colour": colour,
+ "id": 777,
+ "name": "rolename",
+ "permissions": permissions,
+ "position": 23,
+ }
+
+ role = helpers.MockRole(**role_data)
+ role.colour = discord.Colour(colour)
+ role.permissions = discord.Permissions(permissions)
+
+ return role, role_data
+
+ def test_sync_cog_on_guild_role_create(self):
+ """A POST request should be sent with the new role's data."""
+ role, role_data = self.mock_role()
+ asyncio.run(self.cog.on_guild_role_create(role))
+
+ self.bot.api_client.post.assert_called_once_with("bot/roles", json=role_data)