Repository: python-telegram-bot/python-telegram-bot

Issue:
[FEATURE] CallbackQurey.delete_message
missed that in #2043


Discussion:

Resolving patch:
diff --git a/telegram/callbackquery.py b/telegram/callbackquery.py
--- a/telegram/callbackquery.py
+++ b/telegram/callbackquery.py
@@ -131,9 +131,7 @@ def answer(self, *args: Any, **kwargs: Any) -> bool:
     def edit_message_text(self, text: str, *args: Any, **kwargs: Any) -> Union[Message, bool]:
         """Shortcut for either::
 
-            bot.edit_message_text(text, chat_id=update.callback_query.message.chat_id,
-                                message_id=update.callback_query.message.message_id,
-                                *args, **kwargs)
+            update.callback_query.message.edit_text(text, *args, **kwargs)
 
         or::
 
@@ -149,23 +147,14 @@ def edit_message_text(self, text: str, *args: Any, **kwargs: Any) -> Union[Messa
             return self.bot.edit_message_text(
                 text, inline_message_id=self.inline_message_id, *args, **kwargs
             )
-        return self.bot.edit_message_text(
-            text,
-            chat_id=self.message.chat_id,
-            message_id=self.message.message_id,
-            *args,
-            **kwargs,
-        )
+        return self.message.edit_text(text, *args, **kwargs)
 
     def edit_message_caption(
         self, caption: str, *args: Any, **kwargs: Any
     ) -> Union[Message, bool]:
         """Shortcut for either::
 
-            bot.edit_message_caption(caption=caption,
-                                   chat_id=update.callback_query.message.chat_id,
-                                   message_id=update.callback_query.message.message_id,
-                                   *args, **kwargs)
+            update.callback_query.message.edit_caption(caption, *args, **kwargs)
 
         or::
 
@@ -182,24 +171,17 @@ def edit_message_caption(
             return self.bot.edit_message_caption(
                 caption=caption, inline_message_id=self.inline_message_id, *args, **kwargs
             )
-        return self.bot.edit_message_caption(
-            caption=caption,
-            chat_id=self.message.chat_id,
-            message_id=self.message.message_id,
-            *args,
-            **kwargs,
-        )
+        return self.message.edit_caption(caption=caption, *args, **kwargs)
 
     def edit_message_reply_markup(
         self, reply_markup: 'InlineKeyboardMarkup', *args: Any, **kwargs: Any
     ) -> Union[Message, bool]:
         """Shortcut for either::
 
-            bot.edit_message_reply_markup(
-                chat_id=update.callback_query.message.chat_id,
-                message_id=update.callback_query.message.message_id,
+            update.callback_query.message.edit_reply_markup(
                 reply_markup=reply_markup,
-                *args, **kwargs
+                *args,
+                **kwargs
             )
 
         or::
@@ -223,26 +205,16 @@ def edit_message_reply_markup(
                 *args,
                 **kwargs,
             )
-        return self.bot.edit_message_reply_markup(
-            reply_markup=reply_markup,
-            chat_id=self.message.chat_id,
-            message_id=self.message.message_id,
-            *args,
-            **kwargs,
-        )
+        return self.message.edit_reply_markup(reply_markup=reply_markup, *args, **kwargs)
 
     def edit_message_media(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:
         """Shortcut for either::
 
-            bot.edit_message_media(chat_id=update.callback_query.message.chat_id,
-                                   message_id=update.callback_query.message.message_id,
-                                   media=media,
-                                   *args, **kwargs)
+            update.callback_query.message.edit_media(*args, **kwargs)
 
         or::
 
             bot.edit_message_media(inline_message_id=update.callback_query.inline_message_id,
-                                   media=media,
                                    *args, **kwargs)
 
         Returns:
@@ -254,23 +226,17 @@ def edit_message_media(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:
             return self.bot.edit_message_media(
                 inline_message_id=self.inline_message_id, *args, **kwargs
             )
-        return self.bot.edit_message_media(
-            chat_id=self.message.chat_id, message_id=self.message.message_id, *args, **kwargs
-        )
+        return self.message.edit_media(*args, **kwargs)
 
     def edit_message_live_location(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:
         """Shortcut for either::
 
-            bot.edit_message_live_location(chat_id=update.callback_query.message.chat_id,
-                                           message_id=update.callback_query.message.message_id,
-                                           reply_markup=reply_markup,
-                                           *args, **kwargs)
+            update.callback_query.message.edit_live_location(*args, **kwargs)
 
         or::
 
             bot.edit_message_live_location(
                 inline_message_id=update.callback_query.inline_message_id,
-                reply_markup=reply_markup,
                 *args, **kwargs
             )
 
@@ -283,23 +249,17 @@ def edit_message_live_location(self, *args: Any, **kwargs: Any) -> Union[Message
             return self.bot.edit_message_live_location(
                 inline_message_id=self.inline_message_id, *args, **kwargs
             )
-        return self.bot.edit_message_live_location(
-            chat_id=self.message.chat_id, message_id=self.message.message_id, *args, **kwargs
-        )
+        return self.message.edit_live_location(*args, **kwargs)
 
     def stop_message_live_location(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:
         """Shortcut for either::
 
-            bot.stop_message_live_location(chat_id=update.callback_query.message.chat_id,
-                                           message_id=update.callback_query.message.message_id,
-                                           reply_markup=reply_markup,
-                                           *args, **kwargs)
+            update.callback_query.message.stop_live_location(*args, **kwargs)
 
         or::
 
             bot.stop_message_live_location(
                 inline_message_id=update.callback_query.inline_message_id,
-                reply_markup=reply_markup,
                 *args, **kwargs
             )
 
@@ -312,22 +272,16 @@ def stop_message_live_location(self, *args: Any, **kwargs: Any) -> Union[Message
             return self.bot.stop_message_live_location(
                 inline_message_id=self.inline_message_id, *args, **kwargs
             )
-        return self.bot.stop_message_live_location(
-            chat_id=self.message.chat_id, message_id=self.message.message_id, *args, **kwargs
-        )
+        return self.message.stop_live_location(*args, **kwargs)
 
     def set_game_score(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:
         """Shortcut for either::
 
-            bot.set_game_score(chat_id=update.callback_query.message.chat_id,
-                               message_id=update.callback_query.message.message_id,
-                               reply_markup=reply_markup,
-                               *args, **kwargs)
+           update.callback_query.message.set_game_score(*args, **kwargs)
 
         or::
 
             bot.set_game_score(inline_message_id=update.callback_query.inline_message_id,
-                               reply_markup=reply_markup,
                                *args, **kwargs)
 
         Returns:
@@ -339,22 +293,16 @@ def set_game_score(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:
             return self.bot.set_game_score(
                 inline_message_id=self.inline_message_id, *args, **kwargs
             )
-        return self.bot.set_game_score(
-            chat_id=self.message.chat_id, message_id=self.message.message_id, *args, **kwargs
-        )
+        return self.message.set_game_score(*args, **kwargs)
 
     def get_game_high_scores(self, *args: Any, **kwargs: Any) -> List['GameHighScore']:
         """Shortcut for either::
 
-            bot.get_game_high_scores(chat_id=update.callback_query.message.chat_id,
-                                     message_id=update.callback_query.message.message_id,
-                                     reply_markup=reply_markup,
-                                     *args, **kwargs)
+            update.callback_query.message.get_game_high_score(*args, **kwargs)
 
         or::
 
             bot.get_game_high_scores(inline_message_id=update.callback_query.inline_message_id,
-                                     reply_markup=reply_markup,
                                      *args, **kwargs)
 
         Returns:
@@ -365,6 +313,15 @@ def get_game_high_scores(self, *args: Any, **kwargs: Any) -> List['GameHighScore
             return self.bot.get_game_high_scores(
                 inline_message_id=self.inline_message_id, *args, **kwargs
             )
-        return self.bot.get_game_high_scores(
-            chat_id=self.message.chat_id, message_id=self.message.message_id, *args, **kwargs
-        )
+        return self.message.get_game_high_scores(*args, **kwargs)
+
+    def delete_message(self, *args: Any, **kwargs: Any) -> Union[Message, bool]:
+        """Shortcut for::
+
+            update.callback_query.message.delete(*args, **kwargs)
+
+        Returns:
+            :obj:`bool`: On success, :obj:`True` is returned.
+
+        """
+        return self.message.delete(*args, **kwargs)


Test patch:
diff --git a/tests/test_callbackquery.py b/tests/test_callbackquery.py
--- a/tests/test_callbackquery.py
+++ b/tests/test_callbackquery.py
@@ -34,6 +34,7 @@ def callback_query(bot, request):
     )
     if request.param == 'message':
         cbq.message = TestCallbackQuery.message
+        cbq.message.bot = bot
     else:
         cbq.inline_message_id = TestCallbackQuery.inline_message_id
     return cbq
@@ -210,6 +211,18 @@ def test(*args, **kwargs):
         assert callback_query.get_game_high_scores(user_id=1)
         assert callback_query.get_game_high_scores(1)
 
+    def test_delete_message(self, monkeypatch, callback_query):
+        if callback_query.inline_message_id:
+            pytest.skip("Can't delete inline messages")
+
+        def make_assertion(*args, **kwargs):
+            id_ = kwargs['chat_id'] == callback_query.message.chat_id
+            message = kwargs['message_id'] == callback_query.message.message_id
+            return id_ and message
+
+        monkeypatch.setattr(callback_query.bot, 'delete_message', make_assertion)
+        assert callback_query.delete_message()
+
     def test_equality(self):
         a = CallbackQuery(self.id_, self.from_user, 'chat')
         b = CallbackQuery(self.id_, self.from_user, 'chat')