set_game_score might return True

This commit is contained in:
Jacob Bom 2016-10-16 12:33:22 +02:00
parent a68cf8d464
commit 305ff93018
2 changed files with 18 additions and 2 deletions
telegram
tests

View file

@ -1515,7 +1515,8 @@ class Bot(TelegramObject):
"""Use this method to set the score of the specified user in a game.
Returns:
:class:`telegram.Message`: The edited message.
:class:`telegram.Message` or True: The edited message, or if the
message wasn't sent by the bot, True.
"""
url = '{0}/setGameScore'.format(self.base_url)
@ -1532,7 +1533,10 @@ class Bot(TelegramObject):
data['edit_message'] = edit_message
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
return Message.de_json(result, self)
if result is True:
return result
else:
return Message.de_json(result, self)
def getGameHighScores(self,
user_id,

View file

@ -31,6 +31,7 @@ from flaky import flaky
sys.path.append('.')
import telegram
from telegram.error import BadRequest
from tests.base import BaseTest, timeout
@ -314,6 +315,17 @@ class BotTest(BaseTest, unittest.TestCase):
self.assertEqual(message.game.photo[0].file_size, game.game.photo[0].file_size)
self.assertNotEqual(message.game.text, game.game.text)
@flaky(3, 1)
@timeout(10)
def test_set_game_score_too_low_score(self):
# We need a game to set the score for
game_short_name = 'python_telegram_bot_test_game'
game = self._bot.sendGame(game_short_name=game_short_name, chat_id=self._chat_id)
with self.assertRaises(BadRequest):
self._bot.set_game_score(
user_id=self._chat_id, score=100, chat_id=game.chat_id, message_id=game.message_id)
def _testUserEqualsBot(self, user):
"""Tests if user is our trusty @PythonTelegramBot."""
self.assertEqual(user.id, 133505823)