Skip to content

Instantly share code, notes, and snippets.

@jrabbit
Created October 12, 2016 14:10
Show Gist options
  • Save jrabbit/1c2fc32809e60f2ee76f88ea05c40e59 to your computer and use it in GitHub Desktop.
Save jrabbit/1c2fc32809e60f2ee76f88ea05c40e59 to your computer and use it in GitHub Desktop.
class TestOnMessage(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
def tearDown(self):
self.loop.close()
@mock.patch('pyborg_discord.PyborgDiscord')
def test_no_reply(self, patched_pyb_discord):
msg = mock.Mock()
msg.return_value.content = "Yolo!"
our_pybd = pyborg_discord.PyborgDiscord("pyborg/fixtures/discord.toml")
self.loop.run_until_complete(our_pybd.on_message(msg))
patched_pyb_discord.learn.assert_not_called()
@mock.patch('pyborg_discord.PyborgDiscord.user', create=True)
@mock.patch('pyborg_discord.PyborgDiscord.learn')
@mock.patch('pyborg_discord.PyborgDiscord.reply')
def test_reply(self, patched_reply, patched_learn, patched_user):
msg = mock.Mock()
msg.content = "<@221134985560588289> you should play dota!"
patched_user.return_value.id = "221134985560588289"
our_pybd = pyborg_discord.PyborgDiscord("pyborg/fixtures/discord.toml")
patched_reply.return_value = "I should play dota!"
self.loop.run_until_complete(our_pybd.on_message(msg))
# await our_pybd.on_message(msg)
# print(our_pybd.user.id)
# patched_pyb_discord.user.id.assert_called_once_with()
print(patched_user.mock_calls, patched_user.mock_calls)
print(msg.content)
patched_learn.assert_called_once_with("you should play dota!")
patched_reply.assert_called_once_with("you should play dota!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment