mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Add test for clean argument of Updater.start_polling/webhook (#2002)
* added test for 'clean' argument passed to 'start_polling()' * remove TODO * prettify * remove bool from func name * improve name-ing of fake update func * cleanup class and nameing * replace while for for * swap valueerror for runtimeerror * remove all other code to reduce testing * add comments * don't raise error, complete cycle and assert * remove inf loop protection * Revert "remove all other code to reduce testing" This reverts commit4566a1debd
. * remove error parametrization * remove comment * remove pass from class * rename update_id to offset as the original get_updates() takes argument offset (which is the update_id) * rename test func to match original func * fix comment * shorten for loop * mock get_updates() behavior when 'offset' is passed. Assert with get_updates() * remove other functions to reduce testing * replicate original get_updates() * move fakeupdate class and list creation outside get_updates and store in var * loop from 0 to make update_id consistant w array key, just easier to debug * update comments * Revert "remove other functions to reduce testing" This reverts commit1fb498a6cc
. * fix typo * Revert "fix typo" This reverts commitade9fec609
. * Revert "Revert "remove other functions to reduce testing"" This reverts commit734de1371c
. * Revert "update comments" This reverts commitf3a032e75e
. * Revert "loop from 0 to make update_id consistant w array key, just easier to debug" This reverts commit0c6881d8a1
. * Revert "move fakeupdate class and list creation outside get_updates and store in var" This reverts commit71de999300
. * Revert "replicate original get_updates()" This reverts commit5d0710ac3a
. * Revert "remove other functions to reduce testing" This reverts commit1fb498a6cc
. * Revert "mock get_updates() behavior when 'offset' is passed. Assert with get_updates()" This reverts commit8c727ba1e8
. * loop from 0 to make update_id consistant w array key, for consitency Co-authored-by: ikkemaniac <ikkemaniac@localhost>
This commit is contained in:
parent
15268acb27
commit
e60318166e
1 changed files with 37 additions and 2 deletions
|
@ -75,6 +75,7 @@ class TestUpdater:
|
|||
attempts = 0
|
||||
err_handler_called = Event()
|
||||
cb_handler_called = Event()
|
||||
offset = 0
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset(self):
|
||||
|
@ -92,8 +93,6 @@ class TestUpdater:
|
|||
self.received = update.message.text
|
||||
self.cb_handler_called.set()
|
||||
|
||||
# TODO: test clean= argument of Updater._bootstrap
|
||||
|
||||
@pytest.mark.parametrize(('error',),
|
||||
argvalues=[(TelegramError('Test Error 2'),),
|
||||
(Unauthorized('Test Unauthorized'),)],
|
||||
|
@ -331,6 +330,42 @@ class TestUpdater:
|
|||
updater._bootstrap(retries, False, 'path', None, bootstrap_interval=0)
|
||||
assert self.attempts == attempts
|
||||
|
||||
def test_bootstrap_clean_updates(self, monkeypatch, updater):
|
||||
clean = True
|
||||
expected_id = 4
|
||||
self.offset = 0
|
||||
|
||||
def get_updates(*args, **kwargs):
|
||||
# we're hitting this func twice
|
||||
# 1. no args, return list of updates
|
||||
# 2. with 1 arg, int => if int == expected_id => test successful
|
||||
|
||||
# case 2
|
||||
# 2nd call from bootstrap____clean
|
||||
# we should be called with offset = 4
|
||||
# save value passed in self.offset for assert down below
|
||||
if len(args) > 0:
|
||||
self.offset = int(args[0])
|
||||
return []
|
||||
|
||||
class FakeUpdate():
|
||||
def __init__(self, update_id):
|
||||
self.update_id = update_id
|
||||
|
||||
# case 1
|
||||
# return list of obj's
|
||||
|
||||
# build list of fake updates
|
||||
# returns list of 4 objects with
|
||||
# update_id's 0, 1, 2 and 3
|
||||
return [FakeUpdate(i) for i in range(0, expected_id)]
|
||||
|
||||
monkeypatch.setattr(updater.bot, 'get_updates', get_updates)
|
||||
|
||||
updater.running = True
|
||||
updater._bootstrap(1, clean, None, None, bootstrap_interval=0)
|
||||
assert self.offset == expected_id
|
||||
|
||||
@flaky(3, 1)
|
||||
def test_webhook_invalid_posts(self, updater):
|
||||
ip = '127.0.0.1'
|
||||
|
|
Loading…
Reference in a new issue