diff options
| author | 2020-01-02 10:22:11 -0800 | |
|---|---|---|
| committer | 2020-02-12 10:07:48 -0800 | |
| commit | dd07547977a4d49d34ebf597d6072d274b2e4feb (patch) | |
| tree | 33e574d73ee32ebe6caaf455ffcda7903dec2500 | |
| parent | Sync tests: create separate role test cases for diff and sync tests (diff) | |
Sync tests: test API requests for role syncing
| -rw-r--r-- | tests/bot/cogs/sync/test_roles.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/bot/cogs/sync/test_roles.py b/tests/bot/cogs/sync/test_roles.py index 10818a501..719c93d7a 100644 --- a/tests/bot/cogs/sync/test_roles.py +++ b/tests/bot/cogs/sync/test_roles.py @@ -3,7 +3,7 @@ import unittest import discord -from bot.cogs.sync.syncers import RoleSyncer, _Role +from bot.cogs.sync.syncers import RoleSyncer, _Diff, _Role from tests import helpers @@ -103,3 +103,36 @@ class RoleSyncerSyncTests(unittest.TestCase): def setUp(self): self.bot = helpers.MockBot() self.syncer = RoleSyncer(self.bot) + + def test_sync_created_role(self): + """Only a POST request should be made with the correct payload.""" + role = {"id": 41, "name": "new", "colour": 33, "permissions": 0x8, "position": 1} + diff = _Diff({_Role(**role)}, set(), set()) + + asyncio.run(self.syncer._sync(diff)) + + self.bot.api_client.post.assert_called_once_with("bot/roles", json=role) + self.bot.api_client.put.assert_not_called() + self.bot.api_client.delete.assert_not_called() + + def test_sync_updated_role(self): + """Only a PUT request should be made with the correct payload.""" + role = {"id": 51, "name": "updated", "colour": 44, "permissions": 0x7, "position": 2} + diff = _Diff(set(), {_Role(**role)}, set()) + + asyncio.run(self.syncer._sync(diff)) + + self.bot.api_client.put.assert_called_once_with(f"bot/roles/{role['id']}", json=role) + self.bot.api_client.post.assert_not_called() + self.bot.api_client.delete.assert_not_called() + + def test_sync_deleted_role(self): + """Only a DELETE request should be made with the correct payload.""" + role = {"id": 61, "name": "deleted", "colour": 55, "permissions": 0x6, "position": 3} + diff = _Diff(set(), set(), {_Role(**role)}) + + asyncio.run(self.syncer._sync(diff)) + + self.bot.api_client.delete.assert_called_once_with(f"bot/roles/{role['id']}") + self.bot.api_client.post.assert_not_called() + self.bot.api_client.put.assert_not_called() |