Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import json
import telegram
from tests.bots import get_bot


class BaseTest(object):
Expand All @@ -36,16 +37,15 @@ class BaseTest(object):
def __init__(self, *args, **kwargs):
super(BaseTest, self).__init__(*args, **kwargs)

bot = telegram.Bot(
os.environ.get('TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'))
chat_id = os.environ.get('CHAT_ID', '12173560')
bot_info = get_bot()
bot = telegram.Bot(bot_info['token'])
chat_id = bot_info['chat_id']

self._group_id = os.environ.get('GROUP_ID', '-49740850')
self._channel_id = os.environ.get('CHANNEL_ID', '@pythontelegrambottests')
self._group_id = bot_info['group_id']
self._channel_id = bot_info['channel_id']
self._bot = bot
self._chat_id = chat_id
self._payment_provider_token = os.environ.get('PAYMENT_PROVIDER_TOKEN',
'284685063:TEST:ZGJlMmQxZDI3ZTc3')
self._payment_provider_token = bot_info['payment_provider_token']

@staticmethod
def is_json(string):
Expand Down
20 changes: 20 additions & 0 deletions tests/bots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sys

sys.path.append('.')

import telegram

bots = [
{
'token': '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0',
'chat_id': '12173560',
'group_id': '-49740850',
'channel_id': '@pythontelegrambottests',
'payment_provider_token': '284685063:TEST:ZGJlMmQxZDI3ZTc3',
'user': telegram.User(133505823, 'PythonTelegramBot', username='PythonTelegramBot')
}
]


def get_bot():
return bots[0]
39 changes: 39 additions & 0 deletions tests/reupload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging
import sys

sys.path.append('.')

import telegram
from tests.bots import get_bot

logger = logging.getLogger('tests.reupload')

bot_data = get_bot()
bot = telegram.Bot(bot_data['token'])

FILES = {
'audio': {
'file': 'telegram.mp3',
'url': 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.mp3'
}
}

sent_files = {file_type: {t: None for t, file in files.items()} for file_type, files in
FILES.items()}


def reupload(file_type):
for t, file in FILES[file_type].items():
file = file if t == 'url' else open('tests/data/' + file, 'rb')
msg = getattr(bot, 'send_' + file_type)(bot_data['chat_id'], file)
sent_files[file_type][t] = getattr(msg, file_type)


def get_file_id(file_type, url=False, thumb=False):
file = sent_files[file_type]['url' if url else 'file']
if file is None:
reupload(file_type)
return get_file_id(file_type, url, thumb)
if thumb:
file = file.thumb
return file.file_id
3 changes: 2 additions & 1 deletion tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@

import telegram
from tests.base import BaseTest, timeout
from tests.reupload import get_file_id


class AudioTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram Audio."""

def setUp(self):
self.audio_file = open('tests/data/telegram.mp3', 'rb')
self.audio_file_id = 'CQADAQADDwADHyP1B6PSPq2HjX8kAg'
self.audio_file_id = get_file_id('audio')
self.audio_file_url = 'https://raw.githubusercontent.com/python-telegram-bot/python-telegram-bot/master/tests/data/telegram.mp3'
self.duration = 4
self.performer = 'Leandro Toledo'
Expand Down