def test_remove_sub__removes_subscription_case_insensitive(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) watcher.subscriptions.add(Subscription("example", 18749)) watcher.subscriptions.add(Subscription("test", 18747)) new_sub = Subscription("test", 18749) new_sub.latest_update = datetime.datetime.now() watcher.subscriptions.add(new_sub) func = SubscriptionFunctionality(watcher) list_subs = MockMethod("Listing subscriptions") func._list_subs = list_subs.call resp = func._remove_sub(18749, "TEST") assert "Removed subscription: \"TEST\"." in resp assert list_subs.called assert list_subs.args[0] == 18749 assert "Listing subscriptions" in resp assert len(watcher.subscriptions) == 2 subscriptions = list(watcher.subscriptions) if subscriptions[0].query_str == "test": assert subscriptions[0].destination == 18747 assert subscriptions[1].query_str == "example" assert subscriptions[1].destination == 18749 else: assert subscriptions[0].query_str == "example" assert subscriptions[0].destination == 18749 assert subscriptions[1].query_str == "test" assert subscriptions[1].destination == 18747
def test_remove_sub__non_existent_subscription(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) watcher.subscriptions.add(Subscription("example", 18749)) watcher.subscriptions.add(Subscription("test", 18747)) func = SubscriptionFunctionality(watcher) resp = func._remove_sub(18749, "test") assert resp == "There is not a subscription for \"test\" in this chat." assert len(watcher.subscriptions) == 2
async def test_call__route_remove_subscription_with_username(mock_client): event = MockTelegramEvent.with_message( chat_id=14358, text="/remove_subscription@FASearchBot example") api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) func = SubscriptionFunctionality(watcher) delete_sub = MockMethod("Removed subscription test") func._remove_sub = delete_sub.call with pytest.raises(StopPropagation): await func.call(event) assert delete_sub.called assert delete_sub.args is not None assert delete_sub.args[0] == 14358 assert delete_sub.args[1] == "example" event.reply.assert_called() assert event.reply.call_args[0][0] == "Removed subscription test"