Decrease number of requests in tests (#755)

This commit is contained in:
Ihor Polyakov 2017-08-01 04:16:44 +07:00 committed by Noam Meltzer
parent d19ae5084a
commit 454ab050c0
8 changed files with 29 additions and 45 deletions

View file

@ -24,6 +24,8 @@ import sys
from nose.tools import make_decorator from nose.tools import make_decorator
from tests.bots import get_bot
sys.path.append('.') sys.path.append('.')
import json import json
@ -33,19 +35,20 @@ import telegram
class BaseTest(object): class BaseTest(object):
"""This object represents a Base test and its sets of functions.""" """This object represents a Base test and its sets of functions."""
def __init__(self, *args, **kwargs): _group_id = None
super(BaseTest, self).__init__(*args, **kwargs) _channel_id = None
_bot = None
_chat_id = None
_payment_provider_token = None
bot = telegram.Bot( @classmethod
os.environ.get('TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0')) def setUpClass(cls):
chat_id = os.environ.get('CHAT_ID', '12173560') bot_info = get_bot()
cls._chat_id = bot_info['chat_id']
self._group_id = os.environ.get('GROUP_ID', '-49740850') cls._bot = telegram.Bot(bot_info['token'])
self._channel_id = os.environ.get('CHANNEL_ID', '@pythontelegrambottests') cls._group_id = bot_info['group_id']
self._bot = bot cls._channel_id = bot_info['channel_id']
self._chat_id = chat_id cls._payment_provider_token = bot_info['payment_provider_token']
self._payment_provider_token = os.environ.get('PAYMENT_PROVIDER_TOKEN',
'284685063:TEST:ZGJlMmQxZDI3ZTc3')
@staticmethod @staticmethod
def is_json(string): def is_json(string):

View file

@ -25,7 +25,6 @@ from flaky import flaky
import telegram import telegram
from tests.base import BaseTest, timeout from tests.base import BaseTest, timeout
from tests.bots import get_bot
class AudioTest(BaseTest, unittest.TestCase): class AudioTest(BaseTest, unittest.TestCase):
@ -33,6 +32,8 @@ class AudioTest(BaseTest, unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(AudioTest, cls).setUpClass()
cls.caption = "Test audio" cls.caption = "Test audio"
cls.performer = 'Leandro Toledo' cls.performer = 'Leandro Toledo'
cls.title = 'Teste' cls.title = 'Teste'
@ -40,10 +41,6 @@ class AudioTest(BaseTest, unittest.TestCase):
# Shortened link, the above one is cached with the wrong duration. # Shortened link, the above one is cached with the wrong duration.
cls.audio_file_url = "https://goo.gl/3En24v" cls.audio_file_url = "https://goo.gl/3En24v"
bot_info = get_bot()
cls._chat_id = bot_info['chat_id']
cls._bot = telegram.Bot(bot_info['token'])
audio_file = open('tests/data/telegram.mp3', 'rb') audio_file = open('tests/data/telegram.mp3', 'rb')
audio = cls._bot.send_audio(cls._chat_id, audio=audio_file, timeout=10).audio audio = cls._bot.send_audio(cls._chat_id, audio=audio_file, timeout=10).audio
cls.audio = audio cls.audio = audio

View file

@ -25,20 +25,18 @@ from flaky import flaky
import telegram import telegram
from tests.base import BaseTest, timeout from tests.base import BaseTest, timeout
from tests.bots import get_bot
class DocumentTest(BaseTest, unittest.TestCase): class DocumentTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram Document.""" """This object represents Tests for Telegram Document."""
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(DocumentTest, cls).setUpClass()
cls.caption = u'DocumentTest - Caption' cls.caption = u'DocumentTest - Caption'
cls.document_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.gif' cls.document_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.gif'
bot_info = get_bot()
cls._chat_id = bot_info['chat_id']
cls._bot = telegram.Bot(bot_info['token'])
document_file = open('tests/data/telegram.png', 'rb') document_file = open('tests/data/telegram.png', 'rb')
document = cls._bot.send_document(cls._chat_id, document=document_file, timeout=10).document document = cls._bot.send_document(cls._chat_id, document=document_file, timeout=10).document
cls.document = document cls.document = document

View file

@ -26,7 +26,6 @@ from flaky import flaky
import telegram import telegram
from tests.base import BaseTest, timeout from tests.base import BaseTest, timeout
from tests.bots import get_bot
class PhotoTest(BaseTest, unittest.TestCase): class PhotoTest(BaseTest, unittest.TestCase):
@ -34,13 +33,11 @@ class PhotoTest(BaseTest, unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(PhotoTest, cls).setUpClass()
cls.caption = u'PhotoTest - Caption' cls.caption = u'PhotoTest - Caption'
cls.photo_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.jpg' cls.photo_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.jpg'
bot_info = get_bot()
cls._chat_id = bot_info['chat_id']
cls._bot = telegram.Bot(bot_info['token'])
photo_file = open('tests/data/telegram.jpg', 'rb') photo_file = open('tests/data/telegram.jpg', 'rb')
photo = cls._bot.send_photo(cls._chat_id, photo=photo_file, timeout=10).photo photo = cls._bot.send_photo(cls._chat_id, photo=photo_file, timeout=10).photo
cls.thumb, cls.photo = photo cls.thumb, cls.photo = photo

View file

@ -27,7 +27,6 @@ from future.utils import PY2
import telegram import telegram
from tests.base import BaseTest, timeout from tests.base import BaseTest, timeout
from tests.bots import get_bot
class StickerTest(BaseTest, unittest.TestCase): class StickerTest(BaseTest, unittest.TestCase):
@ -35,15 +34,13 @@ class StickerTest(BaseTest, unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(StickerTest, cls).setUpClass()
cls.emoji = '💪' cls.emoji = '💪'
# cls.sticker_file_url = "https://python-telegram-bot.org/static/testfiles/telegram.webp" # cls.sticker_file_url = "https://python-telegram-bot.org/static/testfiles/telegram.webp"
# Serving sticker from gh since our server sends wrong content_type # Serving sticker from gh since our server sends wrong content_type
cls.sticker_file_url = "https://github.com/python-telegram-bot/python-telegram-bot/blob/master/tests/data/telegram.webp?raw=true" # noqa cls.sticker_file_url = "https://github.com/python-telegram-bot/python-telegram-bot/blob/master/tests/data/telegram.webp?raw=true" # noqa
bot_info = get_bot()
cls._chat_id = bot_info['chat_id']
cls._bot = telegram.Bot(bot_info['token'])
sticker_file = open('tests/data/telegram.webp', 'rb') sticker_file = open('tests/data/telegram.webp', 'rb')
sticker = cls._bot.send_sticker(cls._chat_id, sticker=sticker_file, timeout=10).sticker sticker = cls._bot.send_sticker(cls._chat_id, sticker=sticker_file, timeout=10).sticker
cls.sticker = sticker cls.sticker = sticker

View file

@ -25,7 +25,6 @@ from flaky import flaky
import telegram import telegram
from tests.base import BaseTest, timeout from tests.base import BaseTest, timeout
from tests.bots import get_bot
class VideoTest(BaseTest, unittest.TestCase): class VideoTest(BaseTest, unittest.TestCase):
@ -33,13 +32,11 @@ class VideoTest(BaseTest, unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(VideoTest, cls).setUpClass()
cls.caption = u'VideoTest - Caption' cls.caption = u'VideoTest - Caption'
cls.video_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.mp4' cls.video_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.mp4'
bot_info = get_bot()
cls._chat_id = bot_info['chat_id']
cls._bot = telegram.Bot(bot_info['token'])
video_file = open('tests/data/telegram.mp4', 'rb') video_file = open('tests/data/telegram.mp4', 'rb')
video = cls._bot.send_video(cls._chat_id, video=video_file, timeout=10).video video = cls._bot.send_video(cls._chat_id, video=video_file, timeout=10).video
cls.video = video cls.video = video

View file

@ -24,7 +24,6 @@ from flaky import flaky
import telegram import telegram
from tests.base import BaseTest, timeout from tests.base import BaseTest, timeout
from tests.bots import get_bot
class VideoNoteTest(BaseTest, unittest.TestCase): class VideoNoteTest(BaseTest, unittest.TestCase):
@ -32,9 +31,7 @@ class VideoNoteTest(BaseTest, unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
bot_info = get_bot() super(VideoNoteTest, cls).setUpClass()
cls._chat_id = bot_info['chat_id']
cls._bot = telegram.Bot(bot_info['token'])
videonote_file = open('tests/data/telegram2.mp4', 'rb') videonote_file = open('tests/data/telegram2.mp4', 'rb')
video_note = cls._bot.send_video_note(cls._chat_id, video_note=videonote_file, timeout=10).video_note video_note = cls._bot.send_video_note(cls._chat_id, video_note=videonote_file, timeout=10).video_note

View file

@ -25,7 +25,6 @@ from flaky import flaky
import telegram import telegram
from tests.base import BaseTest, timeout from tests.base import BaseTest, timeout
from tests.bots import get_bot
class VoiceTest(BaseTest, unittest.TestCase): class VoiceTest(BaseTest, unittest.TestCase):
@ -33,13 +32,12 @@ class VoiceTest(BaseTest, unittest.TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
super(VoiceTest, cls).setUpClass()
cls.voice_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.ogg' cls.voice_file_url = 'https://python-telegram-bot.org/static/testfiles/telegram.ogg'
cls.caption = u"Test voice" cls.caption = u"Test voice"
voice_file = open('tests/data/telegram.ogg', 'rb') voice_file = open('tests/data/telegram.ogg', 'rb')
bot_info = get_bot()
cls._chat_id = bot_info['chat_id']
cls._bot = telegram.Bot(bot_info['token'])
voice = cls._bot.send_voice(cls._chat_id, voice=voice_file).voice voice = cls._bot.send_voice(cls._chat_id, voice=voice_file).voice
cls.voice = voice cls.voice = voice