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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install:
- pip install -r requirements-dev.txt
- if [[ $TRAVIS_PYTHON_VERSION != 'pypy'* ]]; then pip install ujson; fi
script:
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/ tests
- nosetests -v --with-flaky --no-flaky-report --with-coverage --with-randomly --cover-package=telegram/ tests
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then pre-commit run --all-files; fi
- python ./setup.py bdist_dumb
after_success:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ lint:
$(PYLINT) -E telegram --disable=no-name-in-module,import-error

test:
$(NOSETESTS) -v
$(NOSETESTS) -v --with-randomly tests

install:
$(PIP) install -r requirements.txt -r requirements-dev.txt
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
flake8
nose
nose-randomly
pep257
pylint
flaky
Expand Down
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would upload the file for every test in test_audio. setUp() is called before every test. I would go for setUpClass in this case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right... Whoops. Originally had it only do it when the class was imported (which would make it only run once in total over the entire lifetime of the tests). But along the way I realised that in some cases there's no need to upload all files if you for example are only running audio tests. But since it would have to way of figuring out which tests are gonna be run, I'll just switch it back to uploading on import I think. Unless you have a better idea? :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually.... are you sure? In get_file_id there's a test to see if it's already been uploaded... wouldn't that be global across all tests in theory?

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