From 652150ebc1fc9605cf6bbb21de4ad894a23b516f Mon Sep 17 00:00:00 2001 From: Lucas Peres Date: Wed, 8 Nov 2017 13:31:02 -0300 Subject: [PATCH 1/5] Adapting code to python-telegram-bot 8.1.1 --- ptbtest/mockbot.py | 4 +++- ptbtest/usergenerator.py | 3 ++- tests/test_Callbackquerygenerator.py | 3 +++ tests/test_Chatgenerator.py | 3 +++ tests/test_Inlinequerygenerator.py | 3 +++ tests/test_Messagegenerator.py | 2 ++ tests/test_Mockbot.py | 4 +++- tests/test_Usergenerator.py | 3 +++ 8 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ptbtest/mockbot.py b/ptbtest/mockbot.py index 86860fc..852e147 100644 --- a/ptbtest/mockbot.py +++ b/ptbtest/mockbot.py @@ -27,6 +27,7 @@ import time from telegram import (User, ReplyMarkup, TelegramObject) +from telegram.utils.request import Request from telegram.error import TelegramError logging.getLogger(__name__).addHandler(logging.NullHandler()) @@ -68,6 +69,7 @@ def __init__(self, username="MockBot", **kwargs): from .chatgenerator import ChatGenerator self.mg = MessageGenerator(bot=self) self.cg = ChatGenerator() + self.request = Request() @property def sent_messages(self): @@ -190,7 +192,7 @@ def decorator(self, *args, **kwargs): return decorator def getMe(self, timeout=None, **kwargs): - self.bot = User(0, "Mockbot", last_name="Bot", username=self._username) + self.bot = User(0, "Mockbot", last_name="Bot", is_bot=True, username=self._username) return self.bot @message diff --git a/ptbtest/usergenerator.py b/ptbtest/usergenerator.py index ba4b0de..6d88ca8 100644 --- a/ptbtest/usergenerator.py +++ b/ptbtest/usergenerator.py @@ -42,7 +42,7 @@ def __init__(self): PtbGenerator.__init__(self) def get_user(self, first_name=None, last_name=None, username=None, - id=None): + id=None, is_bot=False): """ Returns a telegram.User object with the optionally given name(s) or username If any of the arguments are omitted the names will be chosen randomly and the @@ -66,5 +66,6 @@ def get_user(self, first_name=None, last_name=None, username=None, return User( id or self.gen_id(), first_name, + is_bot=is_bot, last_name=last_name, username=username) diff --git a/tests/test_Callbackquerygenerator.py b/tests/test_Callbackquerygenerator.py index 0d8524d..49ef5aa 100644 --- a/tests/test_Callbackquerygenerator.py +++ b/tests/test_Callbackquerygenerator.py @@ -19,6 +19,9 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. from __future__ import absolute_import +from os import sys +sys.path.append("..") + import unittest from ptbtest import (BadBotException, BadCallbackQueryException, diff --git a/tests/test_Chatgenerator.py b/tests/test_Chatgenerator.py index e6767e5..d51d04f 100644 --- a/tests/test_Chatgenerator.py +++ b/tests/test_Chatgenerator.py @@ -19,6 +19,9 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. from __future__ import absolute_import +from os import sys +sys.path.append("..") + import unittest from ptbtest import ChatGenerator from ptbtest import UserGenerator diff --git a/tests/test_Inlinequerygenerator.py b/tests/test_Inlinequerygenerator.py index faf0dbe..6e6e8bd 100644 --- a/tests/test_Inlinequerygenerator.py +++ b/tests/test_Inlinequerygenerator.py @@ -19,6 +19,9 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. from __future__ import absolute_import +from os import sys +sys.path.append("..") + import unittest from ptbtest.errors import (BadBotException, BadUserException) diff --git a/tests/test_Messagegenerator.py b/tests/test_Messagegenerator.py index db08aa5..41a6c89 100644 --- a/tests/test_Messagegenerator.py +++ b/tests/test_Messagegenerator.py @@ -1,4 +1,6 @@ from __future__ import absolute_import +from os import sys +sys.path.append("..") import unittest diff --git a/tests/test_Mockbot.py b/tests/test_Mockbot.py index d00a703..8692d49 100644 --- a/tests/test_Mockbot.py +++ b/tests/test_Mockbot.py @@ -19,6 +19,8 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. from __future__ import absolute_import +from os import sys +sys.path.append("..") import unittest @@ -47,7 +49,7 @@ def start(bot, update): dp = updater.dispatcher dp.add_handler(CommandHandler("start", start)) updater.start_polling() - user = User(id=1, first_name="test") + user = User(id=1, first_name="test", is_bot=False) chat = Chat(45, "group") message = Message( 404, user, None, chat, text="/start", bot=self.mockbot) diff --git a/tests/test_Usergenerator.py b/tests/test_Usergenerator.py index f63c770..49273db 100644 --- a/tests/test_Usergenerator.py +++ b/tests/test_Usergenerator.py @@ -19,6 +19,9 @@ # You should have received a copy of the GNU Lesser Public License # along with this program. If not, see [http://www.gnu.org/licenses/]. from __future__ import absolute_import +from os import sys +sys.path.append("..") + import unittest from ptbtest import UserGenerator From e36d35343ba32c9ebb49bb0acc3bf74a992f4bdc Mon Sep 17 00:00:00 2001 From: Derik Date: Sun, 22 Apr 2018 23:25:53 +0300 Subject: [PATCH 2/5] Fix "'Mockbot' object has no attribute 'delete_webhook'" error --- ptbtest/mockbot.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ptbtest/mockbot.py b/ptbtest/mockbot.py index 852e147..7910baf 100644 --- a/ptbtest/mockbot.py +++ b/ptbtest/mockbot.py @@ -30,6 +30,7 @@ from telegram.utils.request import Request from telegram.error import TelegramError + logging.getLogger(__name__).addHandler(logging.NullHandler()) @@ -669,6 +670,9 @@ def setWebhook(self, **kwargs): return None + def delete_webhook(self, timeout=None, **kwargs): + return None + def leaveChat(self, chat_id, timeout=None, **kwargs): data = {'chat_id': chat_id} From cecd50682e26b6fa02d968317de9997fe78833b0 Mon Sep 17 00:00:00 2001 From: Derik Date: Sun, 22 Apr 2018 23:40:22 +0300 Subject: [PATCH 3/5] Fix build error. Where is readme.rst file? --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 24bd8fe..930038a 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import find_packages -with codecs.open("readme.rst", "r", "utf-8") as fd: +with codecs.open("readme.MD", "r", "utf-8") as fd: setup( name='ptbtest', From 101b70125a2c488712358197cd95b4f33518a760 Mon Sep 17 00:00:00 2001 From: Derik Date: Sun, 22 Apr 2018 23:43:13 +0300 Subject: [PATCH 4/5] Revert "Fix build error." This reverts commit cecd50682e26b6fa02d968317de9997fe78833b0. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 930038a..24bd8fe 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import find_packages -with codecs.open("readme.MD", "r", "utf-8") as fd: +with codecs.open("readme.rst", "r", "utf-8") as fd: setup( name='ptbtest', From 3b4ed1c2dc9d58d05642eb83ac9c5b83781c2ba1 Mon Sep 17 00:00:00 2001 From: Derik Date: Thu, 12 Jul 2018 21:55:04 +0300 Subject: [PATCH 5/5] Add readme.rst --- readme.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 readme.rst diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..e69de29