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 #13

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion ptbtest/mockbot.py
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
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
@@ -1 +1,2 @@
python-telegram-bot
python-telegram-bot==8.0
-e git://github.com/Y0hy0h/PtbMock.git#egg=ptbmock
4 changes: 1 addition & 3 deletions setup.py
@@ -1,9 +1,7 @@
import codecs
from distutils.core import setup

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',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_Mockbot.py
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