Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ptbtest/mockbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import time

from ptbmock.mockrequest import MockRequest
from telegram import (User, ReplyMarkup, TelegramObject)
from telegram.error import TelegramError

Expand Down Expand Up @@ -63,6 +64,7 @@ def __init__(self, username="MockBot", **kwargs):
self._updates = []
self.bot = None
self._username = username
self.request = MockRequest()
self._sendmessages = []
from .messagegenerator import MessageGenerator
from .chatgenerator import ChatGenerator
Expand Down Expand Up @@ -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", username=self._username, is_bot=True)
return self.bot

@message
Expand Down
6 changes: 4 additions & 2 deletions ptbtest/usergenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,6 +52,7 @@ def get_user(self, first_name=None, last_name=None, username=None,
first_name (Optional[str]): First name for the returned user.
last_name (Optional[str]): Lst name for the returned user.
username (Optional[str]): Username for the returned user.
is_bot (Optional[bool]): Whether the user is a bot.

Returns:
telegram.User: A telegram user object
Expand All @@ -67,4 +68,5 @@ def get_user(self, first_name=None, last_name=None, username=None,
id or self.gen_id(),
first_name,
last_name=last_name,
username=username)
username=username,
is_bot=is_bot)
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python-telegram-bot
python-telegram-bot==8.0
-e git://github.com/Y0hy0h/PtbMock.git@backwards-compatibility#egg=ptbmock
2 changes: 1 addition & 1 deletion tests/test_Mockbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,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)
Expand Down