aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-17 19:15:53 -0700
committerGravatar MarkKoz <[email protected]>2020-08-17 19:15:53 -0700
commiteda342b40ccd941050a1421ef1907cb2790c1cde (patch)
tree9f69f99d1d0e85c44028739311ad062c59d5c5b0
parentSilence tests: fix mock for _init_task (diff)
Silence tests: add a test for the time cache
-rw-r--r--tests/bot/cogs/moderation/test_silence.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/bot/cogs/moderation/test_silence.py b/tests/bot/cogs/moderation/test_silence.py
index 5d42d8c36..1ae17177f 100644
--- a/tests/bot/cogs/moderation/test_silence.py
+++ b/tests/bot/cogs/moderation/test_silence.py
@@ -1,5 +1,6 @@
import asyncio
import unittest
+from datetime import datetime, timezone
from unittest import mock
from unittest.mock import Mock
@@ -220,6 +221,20 @@ class SilenceTests(unittest.IsolatedAsyncioTestCase):
await self.cog._silence(self.channel, False, None)
self.cog.muted_channel_perms.set.assert_called_once_with(self.channel.id, overwrite_json)
+ @autospec("bot.cogs.moderation.silence", "datetime")
+ async def test_cached_unsilence_time(self, datetime_mock):
+ """The UTC POSIX timestamp for the unsilence was cached."""
+ now_timestamp = 100
+ duration = 15
+ timestamp = now_timestamp + duration * 60
+ datetime_mock.now.return_value = datetime.fromtimestamp(now_timestamp, tz=timezone.utc)
+
+ ctx = MockContext(channel=self.channel)
+ await self.cog.silence.callback(self.cog, ctx, duration)
+
+ self.cog.muted_channel_times.set.assert_awaited_once_with(ctx.channel.id, timestamp)
+ datetime_mock.now.assert_called_once_with(tz=timezone.utc) # Ensure it's using an aware dt.
+
@autospec(Silence, "muted_channel_times", pass_mocks=False)
class UnsilenceTests(unittest.IsolatedAsyncioTestCase):