Ejemplo n.º 1
0
def test_pause_subscription__case_insensitive(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    watcher.subscriptions.add(Subscription("EXAMPLE", 18749))
    watcher.subscriptions.add(Subscription("TEST", 18749))
    func = SubscriptionFunctionality(watcher)
    list_subs = MockMethod("Listing subscriptions")
    func._list_subs = list_subs.call

    resp = func._pause_subscription(18749, "test")

    assert f"Paused 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 True
    assert sub2.query_str == "EXAMPLE"
    assert sub2.destination == 18749
    assert sub2.paused is False
Ejemplo n.º 2
0
def test_pause_subscription__one_matching_in_wrong_destination(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    watcher.subscriptions.add(Subscription("example", 18749))
    watcher.subscriptions.add(Subscription("test", 12345))
    func = SubscriptionFunctionality(watcher)

    resp = func._pause_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 False
Ejemplo n.º 3
0
async def test_call__route_pause_subscription_with_handle(mock_client):
    event = MockTelegramEvent.with_message(chat_id=14358, text="/pause@FASearchBot test")
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    func = SubscriptionFunctionality(watcher)
    pause_sub = MockMethod("Paused subscription")
    func._pause_subscription = pause_sub.call

    with pytest.raises(StopPropagation):
        await func.call(event)

    assert pause_sub.called
    assert pause_sub.args is not None
    assert pause_sub.args[0] == event.chat_id
    assert pause_sub.args[1] == "test"
    event.reply.assert_called()
    assert event.reply.call_args[0][0] == "Paused subscription"
Ejemplo n.º 4
0
def test_pause_subscription__already_paused(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    watcher.subscriptions.add(Subscription("example", 18749))
    sub = Subscription("test", 18749)
    sub.paused = True
    watcher.subscriptions.add(sub)
    func = SubscriptionFunctionality(watcher)

    resp = func._pause_subscription(18749, "test")

    assert resp == f"Subscription for \"test\" is already paused."
    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 True
    assert sub2.query_str == "example"
    assert sub2.destination == 18749
    assert sub2.paused is False