- Notifications
You must be signed in to change notification settings - Fork5.7k
Refactor JobQueue#1981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Refactor JobQueue#1981
Changes fromall commits
ac6046c
bc9b05c
522558d
2eb198e
8862a32
0e02483
e56af1c
c723f5b
6e1a014
8e587fb
b7e635b
585e5f2
9171103
8d22dcf
d44acb9
271a105
46dcff4
065ce12
8867e1c
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,3 +2,4 @@ certifi | ||
tornado>=5.1 | ||
cryptography | ||
decorator>=4.4.0 | ||
APScheduler==3.6.3 |
Large diffs are not rendered by default.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -24,7 +24,7 @@ | ||
from telegram import (CallbackQuery, Chat, ChosenInlineResult, InlineQuery, Message, | ||
PreCheckoutQuery, ShippingQuery, Update, User, MessageEntity) | ||
from telegram.ext import (ConversationHandler, CommandHandler, CallbackQueryHandler, | ||
MessageHandler, Filters, InlineQueryHandler, CallbackContext, JobQueue) | ||
@pytest.fixture(scope='class') | ||
@@ -37,6 +37,15 @@ def user2(): | ||
return User(first_name='Mister Test', id=124, is_bot=False) | ||
@pytest.fixture(autouse=True) | ||
def start_stop_job_queue(dp): | ||
dp.job_queue = JobQueue() | ||
dp.job_queue.set_dispatcher(dp) | ||
dp.job_queue.start() | ||
yield | ||
dp.job_queue.stop() | ||
class TestConversationHandler: | ||
# State definitions | ||
# At first we're thirsty. Then we brew coffee, we drink it | ||
@@ -530,20 +539,17 @@ def test_conversation_timeout(self, dp, bot, user1): | ||
bot=bot) | ||
dp.process_update(Update(update_id=0, message=message)) | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.THIRSTY | ||
sleep(0.65) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
# Start state machine, do something, then reach timeout | ||
dp.process_update(Update(update_id=1, message=message)) | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.THIRSTY | ||
message.text = '/brew' | ||
message.entities[0].length = len('/brew') | ||
dp.process_update(Update(update_id=2, message=message)) | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.BREWING | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
def test_conversation_handler_timeout_update_and_context(self, cdp, bot, user1): | ||
@@ -578,8 +584,7 @@ def timeout_callback(u, c): | ||
timeout_handler.callback = timeout_callback | ||
cdp.process_update(update) | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert self.is_timeout | ||
@@ -602,24 +607,20 @@ def test_conversation_timeout_keeps_extending(self, dp, bot, user1): | ||
dp.process_update(Update(update_id=0, message=message)) | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.THIRSTY | ||
sleep(0.25) # t=.25 | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.THIRSTY | ||
message.text = '/brew' | ||
message.entities[0].length = len('/brew') | ||
dp.process_update(Update(update_id=0, message=message)) | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.BREWING | ||
sleep(0.35) # t=.6 | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.BREWING | ||
message.text = '/pourCoffee' | ||
message.entities[0].length = len('/pourCoffee') | ||
dp.process_update(Update(update_id=0, message=message)) | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.DRINKING | ||
sleep(.4) # t=1 | ||
assert handler.conversations.get((self.group.id, user1.id)) == self.DRINKING | ||
sleep(.2) # t=1.2 | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
def test_conversation_timeout_two_users(self, dp, bot, user1, user2): | ||
@@ -638,16 +639,13 @@ def test_conversation_timeout_two_users(self, dp, bot, user1, user2): | ||
message.entities[0].length = len('/brew') | ||
message.entities[0].length = len('/brew') | ||
message.from_user = user2 | ||
dp.process_update(Update(update_id=0, message=message)) | ||
assert handler.conversations.get((self.group.id, user2.id)) is None | ||
message.text = '/start' | ||
message.entities[0].length = len('/start') | ||
dp.process_update(Update(update_id=0, message=message)) | ||
assert handler.conversations.get((self.group.id, user2.id)) == self.THIRSTY | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert handler.conversations.get((self.group.id, user2.id)) is None | ||
@@ -670,8 +668,7 @@ def test_conversation_handler_timeout_state(self, dp, bot, user1): | ||
message.text = '/brew' | ||
message.entities[0].length = len('/brew') | ||
dp.process_update(Update(update_id=0, message=message)) | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert self.is_timeout | ||
@@ -680,8 +677,7 @@ def test_conversation_handler_timeout_state(self, dp, bot, user1): | ||
message.text = '/start' | ||
message.entities[0].length = len('/start') | ||
dp.process_update(Update(update_id=1, message=message)) | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert self.is_timeout | ||
@@ -694,8 +690,7 @@ def test_conversation_handler_timeout_state(self, dp, bot, user1): | ||
message.text = '/startCoding' | ||
message.entities[0].length = len('/startCoding') | ||
dp.process_update(Update(update_id=0, message=message)) | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert not self.is_timeout | ||
@@ -718,8 +713,7 @@ def test_conversation_handler_timeout_state_context(self, cdp, bot, user1): | ||
message.text = '/brew' | ||
message.entities[0].length = len('/brew') | ||
cdp.process_update(Update(update_id=0, message=message)) | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert self.is_timeout | ||
@@ -728,8 +722,7 @@ def test_conversation_handler_timeout_state_context(self, cdp, bot, user1): | ||
message.text = '/start' | ||
message.entities[0].length = len('/start') | ||
cdp.process_update(Update(update_id=1, message=message)) | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert self.is_timeout | ||
@@ -742,8 +735,7 @@ def test_conversation_handler_timeout_state_context(self, cdp, bot, user1): | ||
message.text = '/startCoding' | ||
message.entities[0].length = len('/startCoding') | ||
cdp.process_update(Update(update_id=0, message=message)) | ||
sleep(0.6) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. doesnt it make sense to put this in a constant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Not sure, if that's a good idea. Have one of the tests failing in the future, fiddle with the constant, suddenly everthing fails and it's not obvious why … | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert not self.is_timeout | ||
@@ -759,7 +751,6 @@ def test_conversation_timeout_cancel_conflict(self, dp, bot, user1): | ||
def slowbrew(_bot, update): | ||
sleep(0.25) | ||
# Let's give to the original timeout a chance to execute | ||
sleep(0.25) | ||
# By returning None we do not override the conversation state so | ||
# we can see if the timeout has been executed | ||
@@ -781,16 +772,13 @@ def slowbrew(_bot, update): | ||
bot=bot) | ||
dp.process_update(Update(update_id=0, message=message)) | ||
sleep(0.25) | ||
message.text = '/slowbrew' | ||
message.entities[0].length = len('/slowbrew') | ||
dp.process_update(Update(update_id=0, message=message)) | ||
assert handler.conversations.get((self.group.id, user1.id)) is not None | ||
assert not self.is_timeout | ||
sleep(0.6) | ||
assert handler.conversations.get((self.group.id, user1.id)) is None | ||
assert self.is_timeout | ||
Uh oh!
There was an error while loading.Please reload this page.