mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
* Fix #1328: custom timeout argument does not work * Remove unused import
This commit is contained in:
parent
c03160c07f
commit
3e8d71582d
2 changed files with 18 additions and 6 deletions
|
@ -323,7 +323,8 @@ class Request(object):
|
|||
else:
|
||||
result = self._request_wrapper('POST', url,
|
||||
body=json.dumps(data).encode('utf-8'),
|
||||
headers={'Content-Type': 'application/json'})
|
||||
headers={'Content-Type': 'application/json'},
|
||||
**urlopen_kwargs)
|
||||
|
||||
return self._parse(result)
|
||||
|
||||
|
|
|
@ -618,16 +618,27 @@ class TestBot(object):
|
|||
# test_sticker module.
|
||||
|
||||
def test_timeout_propagation(self, monkeypatch, bot, chat_id):
|
||||
|
||||
from telegram.vendor.ptb_urllib3.urllib3.util.timeout import Timeout
|
||||
|
||||
class OkException(Exception):
|
||||
pass
|
||||
|
||||
timeout = 500
|
||||
TIMEOUT = 500
|
||||
|
||||
def post(*args, **kwargs):
|
||||
if kwargs.get('timeout') == 500:
|
||||
def request_wrapper(*args, **kwargs):
|
||||
obj = kwargs.get('timeout')
|
||||
if isinstance(obj, Timeout) and obj._read == TIMEOUT:
|
||||
raise OkException
|
||||
|
||||
monkeypatch.setattr('telegram.utils.request.Request.post', post)
|
||||
return b'{"ok": true, "result": []}'
|
||||
|
||||
monkeypatch.setattr('telegram.utils.request.Request._request_wrapper', request_wrapper)
|
||||
|
||||
# Test file uploading
|
||||
with pytest.raises(OkException):
|
||||
bot.send_photo(chat_id, open('tests/data/telegram.jpg', 'rb'), timeout=timeout)
|
||||
bot.send_photo(chat_id, open('tests/data/telegram.jpg', 'rb'), timeout=TIMEOUT)
|
||||
|
||||
# Test JSON submition
|
||||
with pytest.raises(OkException):
|
||||
bot.get_chat_administrators(chat_id, timeout=TIMEOUT)
|
||||
|
|
Loading…
Reference in a new issue