コード例 #1
0
ファイル: test_bot.py プロジェクト: BeastlyTheos/Dice-Mice
	def test_ifTimelimitExceeded_whileProcessingMessage_thenAbortMessage(self):
		msg = AsyncMock()
		msg.content = "1000000d1000000h1"
		msg.channel.send = AsyncMock()
		msg.author.display_name = "bert"
		with self.assertLogs("main", logging.WARNING):
			with self.assertRaises(ParserTimeoutError):
				run(on_message(msg))
		msg.channel.send.assert_called()
コード例 #2
0
ファイル: test_bot.py プロジェクト: BeastlyTheos/Dice-Mice
	def test_doesNothing_whenMessageHasNoDice(self):
		msg = Mock()
		for content in (
			"hello world",
			"indi12",
			"4+4d",
			"",
			"d\n67",
		):
			msg.content = content
			res = run(on_message(msg))
			self.assertEqual(res, "no dice")
コード例 #3
0
ファイル: test_bot.py プロジェクト: BeastlyTheos/Dice-Mice
	def test_sendsReply_whenMessageContainsDiceCodes(self):
		msg = Mock()
		msg.channel.send = AsyncMock()
		for content in (
			"d20",
			"Hello d20dis world",
			"hit for d20adv+3 then d6+2 damage.",
			"d8\nd9+4",
			"hello\nthere\nd2",
		):
			msg.content = content
			run(on_message(msg))
			msg.channel.send.assert_called()
コード例 #4
0
ファイル: app.py プロジェクト: Mashakal/pybot-v3
def root():
    msg = Message(request.json)

    if msg.type.lower() == 'ping':
        return

    if msg.type.lower() == 'message':
        return bot.on_message(msg)

    try:
        handler = getattr(bot, msg.type)
    except AttributeError:
        return {"message": "TODO: " + msg.type}
    else:
        return handler(msg)
コード例 #5
0
ファイル: test_bot.py プロジェクト: BeastlyTheos/Dice-Mice
	def test_logsError_whenRaisingException(self):
		with self.assertLogs("main", logging.ERROR):
			run(on_message(Mock(side_effect=Exception("test exception"))))
コード例 #6
0
ファイル: test_bot.py プロジェクト: BeastlyTheos/Dice-Mice
	def test_doesNothing_whenMessageIsFromSelf(self):
		bot.client = Mock()
		msg = Mock()
		msg.author = bot.client.user = Mock()
		res = run(on_message(msg))
		self.assertEqual(res, "own message")