def test_resume_subscription__case_insensitive(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) sub1 = Subscription("EXAMPLE", 18749) sub1.paused = True watcher.subscriptions.add(sub1) sub2 = Subscription("TEST", 18749) sub2.paused = True watcher.subscriptions.add(sub2) func = SubscriptionFunctionality(watcher) list_subs = MockMethod("Listing subscriptions") func._list_subs = list_subs.call resp = func._resume_subscription(18749, "test") assert f"Resumed subscription: \"test\"." in resp assert list_subs.called assert list_subs.args[0] == 18749 assert "Listing subscriptions" in resp assert len(watcher.subscriptions) == 2 sub1, sub2 = watcher.subscriptions if sub1.query_str != "TEST": sub1, sub2 = sub2, sub1 assert sub1.query_str == "TEST" assert sub1.destination == 18749 assert sub1.paused is False assert sub2.query_str == "EXAMPLE" assert sub2.destination == 18749 assert sub2.paused is True
async def test_call__route_resume_subscription_with_handle(mock_client): event = MockTelegramEvent.with_message(chat_id=14358, text="/resume@FASearchBot test") api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) func = SubscriptionFunctionality(watcher) resume_sub = MockMethod("Resumed subscription") func._resume_subscription = resume_sub.call with pytest.raises(StopPropagation): await func.call(event) assert resume_sub.called assert resume_sub.args is not None assert resume_sub.args[0] == event.chat_id assert resume_sub.args[1] == "test" event.reply.assert_called() assert event.reply.call_args[0][0] == "Resumed subscription"
def test_resume_subscription__one_matching_in_wrong_destination(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) sub1 = Subscription("example", 18749) sub1.paused = True watcher.subscriptions.add(sub1) sub2 = Subscription("test", 12345) sub2.paused = True watcher.subscriptions.add(sub2) func = SubscriptionFunctionality(watcher) resp = func._resume_subscription(18749, "test") assert resp == "There is not a subscription for \"test\" in this chat." assert len(watcher.subscriptions) == 2 for subscription in watcher.subscriptions: assert subscription.paused is True
def test_resume_subscription__already_running(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) sub1 = Subscription("example", 18749) sub1.paused = True watcher.subscriptions.add(sub1) sub2 = Subscription("test", 18749) sub2.paused = False watcher.subscriptions.add(sub2) func = SubscriptionFunctionality(watcher) resp = func._resume_subscription(18749, "test") assert resp == f"Subscription for \"test\" is already running." assert len(watcher.subscriptions) == 2 sub1, sub2 = watcher.subscriptions if sub1.query_str != "test": sub1, sub2 = sub2, sub1 assert sub1.query_str == "test" assert sub1.destination == 18749 assert sub1.paused is False assert sub2.query_str == "example" assert sub2.destination == 18749 assert sub2.paused is True