Skip to content
Permalink
Browse files

Merge d5e3ae1 into eee0f78

  • Loading branch information
jsmnbom committed Jun 20, 2017
2 parents eee0f78 + d5e3ae1 commit 87648b0157106ab621d143ac6885bdd0db708dd4
Showing with 68 additions and 8 deletions.
  1. +7 −7 tests/base.py
  2. +20 −0 tests/bots.py
  3. +39 −0 tests/reupload.py
  4. +2 −1 tests/test_audio.py
@@ -28,6 +28,7 @@

import json
import telegram
from tests.bots import get_bot


class BaseTest(object):
@@ -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):
@@ -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]
@@ -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
@@ -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'

0 comments on commit 87648b0

Please sign in to comment.
You can’t perform that action at this time.