async def test_on_message(_self): """ Ensure response correct """ ma_nobot = MockAuthor(bot=False) mm = MockMessage(author=ma_nobot) # test: no pope, no bot _self._has_pope.return_value = False with patch("random.randint", return_value=1) as _: await PopeImage.on_message(_self, mm) mm.assert_not_called() # test: has pope, is bot _self._has_pope.return_value = True ma_nobot.bot = True with patch("random.randint", return_value=1) as _: await PopeImage.on_message(_self, mm) mm.assert_not_called() # test: has pope, no bot ma_nobot.bot = False with patch("random.randint", return_value=1) as _: await PopeImage.on_message(_self, mm) mm.reply.assert_called_with(f"#1\n{_POPEFILE_CONTENT[1]}")
def test_aptitude(self, mock_randint: MagicMock): user = MockAuthor("TestUser") mock_randint.return_value = 12 skill_check = check.create_response(MockMessage(user, "11,9,9@4")) self.checkPayload( skill_check, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 12 12 12\n" "FW 4 -1 -3 -3 = -3 FP\n" "Nicht bestanden\n" "```", ) mock_randint.return_value = 2 aptitude = check.create_response(MockMessage(user, "begabung 2")) self.checkPayload( aptitude, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 12 2 12\n" "FW 4 -1 -3 = 0 FP\n" "Bestanden mit QS 1\n" "```", )
def test_parse(self): author = MockAuthor("TestUser") self.assertIsInstance(check.create_check(author, "13 14 15@2"), SkillCheck) self.assertIsInstance(check.create_check(author, "13"), AttributeCheck) self.assertIsInstance(check.create_check(author, "13 @2"), AttributeCheck) self.assertIsInstance(check.create_check(author, "13 14 -2"), GenericCheck) self.assertIsInstance(check.create_check(author, "13 14 @2"), GenericCheck)
def test_force(self, mock_randint: MagicMock): user = MockAuthor("TestUser") mock_randint.return_value = 12 first = check.create_response(MockMessage(user, "14,14,14@12")) self.checkPayload( first, " \n```py\nRoutineprobe: 6 FP = QS 2\n```", ) second = check.create_response(MockMessage(user, "force")) self.checkPayload( second, " \n" "```py\n" "EEW: 14 14 14\n" "Würfel: 12 12 12\n" "FW 12 = 12 FP\n" "Bestanden mit QS 4\n" "```", )
def test_incompetence(self, mock_randint: MagicMock): user = MockAuthor("TestUser") mock_randint.return_value = 12 skill_check = check.create_response(MockMessage(user, "11,10,9@4")) self.checkPayload( skill_check, " \n" "```py\n" "EEW: 11 10 9\n" "Würfel: 12 12 12\n" "FW 4 -1 -2 -3 = -2 FP\n" "Nicht bestanden\n" "```", ) mock_randint.return_value = 9 aptitude = check.create_response(MockMessage(user, "unfähig")) self.checkPayload( aptitude, " \n" "```py\n" "EEW: 11 10 9\n" "Würfel: 12 12 9\n" "FW 4 -1 -2 = 1 FP\n" "Bestanden mit QS 1\n" "```", ) mock_randint.return_value = 13 aptitude = check.create_response(MockMessage(user, "incompetent")) self.checkPayload( aptitude, " \n" "```py\n" "EEW: 11 10 9\n" "Würfel: 12 12 13\n" "FW 4 -1 -2 -4 = -3 FP\n" "Nicht bestanden\n" "```", )
def test_retry_repeat(self, mock_randint: MagicMock): user = MockAuthor("TestUser") mock_randint.return_value = 12 first = check.create_response(MockMessage(user, "11,9,9@4")) self.checkPayload( first, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 12 12 12\n" "FW 4 -1 -3 -3 = -3 FP\n" "Nicht bestanden\n" "```", ) mock_randint.return_value = 10 second = check.create_response(MockMessage(user, "repeat")) self.checkPayload( second, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 10 10 10\n" "FW 4 -1 -1 = 2 FP\n" "Bestanden mit QS 1\n" "```", ) mock_randint.return_value = 9 third = check.create_response(MockMessage(user, "retry")) self.checkPayload( third, " \n" "```py\n" "EEW: 10 8 8\n" "Würfel: 9 9 9\n" "FW 4 -1 -1 = 2 FP\n" "Bestanden mit QS 1\n" "```", )
def setUpClass(self) -> None: self.author = MockAuthor("TestUser")
def create_response(content): res = hit_zone.create_response(MockMessage(MockAuthor("TestUser"), content)) return res.messages[0]["args"][0]
def test_fate(self, mock_randint: MagicMock): user = MockAuthor("TestUser") note_id = f"schips_{str(user)}" note.create_note(note_id, True, 3, user) mock_randint.return_value = 12 first = check.create_response(MockMessage(user, "11,9,9@4")) self.checkPayload( first, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 12 12 12\n" "FW 4 -1 -3 -3 = -3 FP\n" "Nicht bestanden\n" "```", ) other_message = MockMessage(MockAuthor("NotTestUser"), "14,14,10@6") check.create_response(other_message) self.assertNotEqual(user, other_message.author) mock_randint.return_value = 2 second = check.create_response(MockMessage(user, "schips rrr")) self.checkPayload( second, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 2 2 2\n" "FW 4 = 4 FP\n" "Bestanden mit QS 2\n" "```", ) mock_randint.return_value = 10 third = check.create_response(MockMessage(user, "schips rkk")) self.checkPayload( third, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 10 2 2\n" "FW 4 = 4 FP\n" "Bestanden mit QS 2\n" "```", ) mock_randint.return_value = 10 fourth = check.create_response(MockMessage(user, "schips rkk")) self.checkPayload( fourth, " \n" "```py\n" "EEW: 11 9 9\n" "Würfel: 10 2 2\n" "FW 4 = 4 FP\n" "Bestanden mit QS 2\n" "```", ) mock_randint.return_value = 10 fifth = check.create_response(MockMessage(user, "schips rkk")) self.checkPayload(fifth, " Keine Schips übrig!") note.delete_note(user, note_id)
def setUpClass(self) -> None: self.testchannel = MockChannel() self.testauthor = MockAuthor("Author")
def setUpClass(self) -> None: self.author = MockAuthor("TestUser") # This needs to be executed before the first test persistence.on_ready()