mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-29 01:37:28 +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:
|
else:
|
||||||
result = self._request_wrapper('POST', url,
|
result = self._request_wrapper('POST', url,
|
||||||
body=json.dumps(data).encode('utf-8'),
|
body=json.dumps(data).encode('utf-8'),
|
||||||
headers={'Content-Type': 'application/json'})
|
headers={'Content-Type': 'application/json'},
|
||||||
|
**urlopen_kwargs)
|
||||||
|
|
||||||
return self._parse(result)
|
return self._parse(result)
|
||||||
|
|
||||||
|
|
|
@ -618,16 +618,27 @@ class TestBot(object):
|
||||||
# test_sticker module.
|
# test_sticker module.
|
||||||
|
|
||||||
def test_timeout_propagation(self, monkeypatch, bot, chat_id):
|
def test_timeout_propagation(self, monkeypatch, bot, chat_id):
|
||||||
|
|
||||||
|
from telegram.vendor.ptb_urllib3.urllib3.util.timeout import Timeout
|
||||||
|
|
||||||
class OkException(Exception):
|
class OkException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
timeout = 500
|
TIMEOUT = 500
|
||||||
|
|
||||||
def post(*args, **kwargs):
|
def request_wrapper(*args, **kwargs):
|
||||||
if kwargs.get('timeout') == 500:
|
obj = kwargs.get('timeout')
|
||||||
|
if isinstance(obj, Timeout) and obj._read == TIMEOUT:
|
||||||
raise OkException
|
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):
|
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…
Add table
Reference in a new issue