aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-01-31 12:52:40 -0800
committerGravatar MarkKoz <[email protected]>2020-02-12 10:07:55 -0800
commit93b3ec43526096bdf3f4c8a9ee2c9de29d25a562 (patch)
tree329fbf9d30444c931d183d28b6a738332e8a1fc8
parentSync tests: test patch_user (diff)
Sync tests: add helper function for testing patch_user
Reduces redundancy in the tests by taking care of the mocks, calling of the function, and the assertion.
-rw-r--r--tests/bot/cogs/sync/test_cog.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/tests/bot/cogs/sync/test_cog.py b/tests/bot/cogs/sync/test_cog.py
index 0eb8954f1..bdb7aeb63 100644
--- a/tests/bot/cogs/sync/test_cog.py
+++ b/tests/bot/cogs/sync/test_cog.py
@@ -105,19 +105,26 @@ class SyncCogTests(unittest.TestCase):
self.cog.role_syncer.sync.assert_called_once_with(guild)
self.cog.user_syncer.sync.assert_called_once_with(guild)
+ def patch_user_helper(self, side_effect: BaseException) -> None:
+ """Helper to set a side effect for bot.api_client.patch and then assert it is called."""
+ self.bot.api_client.patch.reset_mock(side_effect=True)
+ self.bot.api_client.patch.side_effect = side_effect
+
+ user_id, updated_information = 5, {"key": 123}
+ asyncio.run(self.cog.patch_user(user_id, updated_information))
+
+ self.bot.api_client.patch.assert_called_once_with(
+ f"bot/users/{user_id}",
+ json=updated_information,
+ )
+
def test_sync_cog_patch_user(self):
"""A PATCH request should be sent and 404 errors ignored."""
for side_effect in (None, self.response_error(404)):
with self.subTest(side_effect=side_effect):
- self.bot.api_client.patch.reset_mock(side_effect=True)
- self.bot.api_client.patch.side_effect = side_effect
-
- asyncio.run(self.cog.patch_user(5, {}))
- self.bot.api_client.patch.assert_called_once()
+ self.patch_user_helper(side_effect)
def test_sync_cog_patch_user_non_404(self):
"""A PATCH request should be sent and the error raised if it's not a 404."""
- self.bot.api_client.patch.side_effect = self.response_error(500)
with self.assertRaises(ResponseCodeError):
- asyncio.run(self.cog.patch_user(5, {}))
- self.bot.api_client.patch.assert_called_once()
+ self.patch_user_helper(self.response_error(500))