def test_add_sub__invalid_query(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) func = SubscriptionFunctionality(watcher) resp = func._add_sub(18749, "(hello") assert resp.startswith("Failed to parse subscription query") assert len(watcher.subscriptions) == 0
def test_add_sub__no_add_blank(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) func = SubscriptionFunctionality(watcher) resp = func._add_sub(18749, "") assert resp == "Please specify the subscription query you wish to add." assert len(watcher.subscriptions) == 0
def test_add_sub__no_add_duplicate_case_insensitive(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) watcher.subscriptions.add(Subscription("test", 18749)) func = SubscriptionFunctionality(watcher) resp = func._add_sub(18749, "TEST") assert resp == "A subscription already exists for \"TEST\"." assert len(watcher.subscriptions) == 1
async def test_call__route_add_subscription_with_username(mock_client): event = MockTelegramEvent.with_message( chat_id=14358, text="/add_subscription@FASearchBot test") api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) func = SubscriptionFunctionality(watcher) add_sub = MockMethod("Added subscription test") func._add_sub = add_sub.call with pytest.raises(StopPropagation): await func.call(event) assert add_sub.called assert add_sub.args is not None assert add_sub.args[0] == 14358 assert add_sub.args[1] == "test" event.reply.assert_called() assert event.reply.call_args[0][0] == "Added subscription test"
def test_add_sub__adds_subscription(mock_client): api = MockExportAPI() watcher = SubscriptionWatcher(api, mock_client) func = SubscriptionFunctionality(watcher) list_subs = MockMethod("Listing subscriptions") func._list_subs = list_subs.call resp = func._add_sub(18749, "test") assert "Added subscription" in resp assert "\"test\"" in resp assert list_subs.called assert list_subs.args[0] == 18749 assert "Listing subscriptions" in resp assert len(watcher.subscriptions) == 1 subscription = list(watcher.subscriptions)[0] assert subscription.query_str == "test" assert subscription.destination == 18749 assert subscription.latest_update is None