|
| 1 | +#!/usr/bin/env python |
| 2 | +# encoding: utf-8 |
| 3 | +# |
| 4 | +# A library that provides a Python interface to the Telegram Bot API |
| 5 | +# Copyright (C) 2015-2016 |
| 6 | +# Leandro Toledo de Souza <devs@python-telegram-bot.org> |
| 7 | +# |
| 8 | +# This program is free software: you can redistribute it and/or modify |
| 9 | +# it under the terms of the GNU General Public License as published by |
| 10 | +# the Free Software Foundation, either version 3 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | +# |
| 13 | +# This program is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU General Public License |
| 19 | +# along with this program. If not, see [http://www.gnu.org/licenses/]. |
| 20 | +"""This module contains an object that represents ProxyTests for Telegram Message""" |
| 21 | + |
| 22 | +from datetime import datetime |
| 23 | +import os |
| 24 | +import sys |
| 25 | +import unittest |
| 26 | + |
| 27 | +sys.path.append('.') |
| 28 | + |
| 29 | +from flaky import flaky |
| 30 | +from telegram.utils.request import Request |
| 31 | +import telegram |
| 32 | + |
| 33 | +from tests.base import BaseTest, timeout |
| 34 | + |
| 35 | + |
| 36 | +class AnonymousHttpsProxyTest(BaseTest, unittest.TestCase): |
| 37 | + """This object represents AnonymousHttpsProxyTest for Telegram MessageTest.""" |
| 38 | + |
| 39 | + @classmethod |
| 40 | + def setUpClass(cls): |
| 41 | + # Proxy taken from https://sslproxies.org . |
| 42 | + cls._bot = telegram.Bot( |
| 43 | + os.environ.get('TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'), |
| 44 | + request=Request(proxy_url='https://91.195.183.57:3128')) |
| 45 | + |
| 46 | + @flaky(3, 1) |
| 47 | + @timeout(10) |
| 48 | + def testSendMessage(self): |
| 49 | + message = self._bot.sendMessage( |
| 50 | + chat_id=self._chat_id, text='Моё судно на воздушной подушке полно угрей') |
| 51 | + |
| 52 | + self.assertTrue(self.is_json(message.to_json())) |
| 53 | + self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей') |
| 54 | + self.assertTrue(isinstance(message.date, datetime)) |
| 55 | + |
| 56 | + @flaky(3, 1) |
| 57 | + @timeout(10) |
| 58 | + def test_reply_text(self): |
| 59 | + """Test for a proxied Message.reply_text""" |
| 60 | + message = self._bot.sendMessage(self._chat_id, '.') |
| 61 | + message = message.reply_text('Testing proxy mode.') |
| 62 | + |
| 63 | + self.assertTrue(self.is_json(message.to_json())) |
| 64 | + self.assertEqual(message.text, 'Testing proxy mode.') |
| 65 | + |
| 66 | + |
| 67 | +class AnonymousHttpProxyTest(BaseTest, unittest.TestCase): |
| 68 | + """This object represents AnonymousHttpProxyTest for Telegram MessageTest.""" |
| 69 | + |
| 70 | + @classmethod |
| 71 | + def setUpClass(cls): |
| 72 | + # Proxy taken from https://incloak.com . |
| 73 | + cls._bot = telegram.Bot( |
| 74 | + os.environ.get('TOKEN', '133505823:AAHZFMHno3mzVLErU5b5jJvaeG--qUyLyG0'), |
| 75 | + request=Request(proxy_url='http://138.201.63.123:31288')) |
| 76 | + |
| 77 | + @timeout(15) |
| 78 | + @flaky(3, 1) |
| 79 | + def testSendMessage(self): |
| 80 | + message = self._bot.sendMessage( |
| 81 | + chat_id=self._chat_id, text='Моё судно на воздушной подушке полно угрей') |
| 82 | + |
| 83 | + self.assertTrue(self.is_json(message.to_json())) |
| 84 | + self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей') |
| 85 | + self.assertTrue(isinstance(message.date, datetime)) |
| 86 | + |
| 87 | + @flaky(3, 1) |
| 88 | + @timeout(15) |
| 89 | + def test_reply_text(self): |
| 90 | + """Test for a proxied Message.reply_text""" |
| 91 | + message = self._bot.sendMessage(self._chat_id, '.') |
| 92 | + message = message.reply_text('Testing proxy mode.') |
| 93 | + |
| 94 | + self.assertTrue(self.is_json(message.to_json())) |
| 95 | + self.assertEqual(message.text, 'Testing proxy mode.') |
| 96 | + |
| 97 | + |
| 98 | +if __name__ == '__main__': |
| 99 | + unittest.main() |
0 commit comments