aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorromangraef <romangraef@loves.dicksinhisan.us>2018-11-26 21:05:44 +0100
committerromangraef <romangraef@loves.dicksinhisan.us>2018-11-26 21:05:44 +0100
commitc8808ec947590b0ab2cce69484e71aa90fecabf0 (patch)
treee2fed2eae59b9dcee961d101443664d9b4711f98 /tests
downloaddrutils-c8808ec947590b0ab2cce69484e71aa90fecabf0.tar.gz
drutils-c8808ec947590b0ab2cce69484e71aa90fecabf0.tar.bz2
drutils-c8808ec947590b0ab2cce69484e71aa90fecabf0.zip
Initial commit
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/test_awaiter.py40
-rw-r--r--tests/utils.py8
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/test_awaiter.py b/tests/test_awaiter.py
new file mode 100644
index 0000000..78d25a8
--- /dev/null
+++ b/tests/test_awaiter.py
@@ -0,0 +1,40 @@
+from unittest.mock import ANY
+
+from aiounittest import AsyncTestCase
+from discord import Object
+
+from drutils.awaiter import AdvancedAwaiter
+from .utils import get_mock_coro
+
+TEST_TEXT = "ABCDEF"
+TEST_RESPONSE = "DEFABC"
+TEST_MESSAGE_ID = 3
+TEST_USER_ID = 2
+TEST_CHANNEL_ID = 1
+TEST_TIMEOUT = 100
+
+
+class AwaiterTest(AsyncTestCase):
+
+ def setUp(self):
+ super().setUp()
+ self.ctx = Object(id=0)
+ self.bot = Object(id=0)
+ self.message = Object(id=TEST_MESSAGE_ID)
+ self.message.content = TEST_RESPONSE
+ self.user = Object(id=TEST_USER_ID)
+ self.message.author = self.user
+ self.bot.wait_for = get_mock_coro(self.message)
+ self.channel = Object(id=TEST_CHANNEL_ID)
+ self.channel.send = get_mock_coro(None)
+ self.ctx.bot = self.bot
+ self.ctx.channel = self.channel
+ self.ctx.guild = None
+ self.ctx.author = self.user
+
+ async def test_text(self):
+ awaiter = AdvancedAwaiter.from_context(self.ctx, timeout=TEST_TIMEOUT)
+ text = await awaiter.text(TEST_TEXT)
+ self.assertEqual(text, TEST_RESPONSE)
+ self.bot.wait_for.assert_called_once_with('message', check=ANY, timeout=TEST_TIMEOUT)
+ self.assertEqual(self.channel.send.call_args[1]['embed'].description, TEST_TEXT)
diff --git a/tests/utils.py b/tests/utils.py
new file mode 100644
index 0000000..20b76c8
--- /dev/null
+++ b/tests/utils.py
@@ -0,0 +1,8 @@
+from unittest.mock import Mock
+
+
+def get_mock_coro(return_value):
+ async def mock_coro(*args, **kwargs):
+ return return_value
+
+ return Mock(wraps=mock_coro)