Ejemplo n.º 1
0
def test_resume_destination__not_in_other_destination(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    sub1 = Subscription("test", 18749)
    sub1.paused = True
    watcher.subscriptions.add(sub1)
    sub2 = Subscription("example", 12345)
    sub2.paused = True
    watcher.subscriptions.add(sub2)
    func = SubscriptionFunctionality(watcher)
    list_subs = MockMethod("Listing subscriptions")
    func._list_subs = list_subs.call

    resp = func._resume_destination(18749)

    assert "Resumed all subscriptions." in resp
    assert len(watcher.subscriptions) == 2
    assert list_subs.called
    assert list_subs.args[0] == 18749
    assert "Listing subscriptions" in resp
    sub1, sub2 = list(watcher.subscriptions)[:2]
    if sub1.destination != 18749:
        sub2, sub1 = sub1, sub2
    assert sub1.destination == 18749
    assert sub1.query_str == "test"
    assert sub1.paused is False
    assert sub2.destination == 12345
    assert sub2.query_str == "example"
    assert sub2.paused is True
Ejemplo n.º 2
0
def test_resume_destination__no_subs(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    func = SubscriptionFunctionality(watcher)

    resp = func._resume_destination(18749)

    assert resp == "There are no subscriptions posting here to resume."
    assert len(watcher.subscriptions) == 0
Ejemplo n.º 3
0
async def test_call__route_resume_destination_with_handle(mock_client):
    event = MockTelegramEvent.with_message(chat_id=14358, text="/resume@FASearchBot")
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    func = SubscriptionFunctionality(watcher)
    resume_dest = MockMethod("Resumed all subscriptions")
    func._resume_destination = resume_dest.call

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

    assert resume_dest.called
    assert resume_dest.args is not None
    assert resume_dest.args[0] == event.chat_id
    event.reply.assert_called()
    assert event.reply.call_args[0][0] == "Resumed all subscriptions"
Ejemplo n.º 4
0
def test_resume_destination__all_running(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    sub1 = Subscription("test", 18749)
    sub1.paused = False
    watcher.subscriptions.add(sub1)
    sub2 = Subscription("example", 18749)
    sub2.paused = False
    watcher.subscriptions.add(sub2)
    func = SubscriptionFunctionality(watcher)

    resp = func._resume_destination(18749)

    assert resp == "All subscriptions are already running."
    assert len(watcher.subscriptions) == 2
    for subscription in watcher.subscriptions:
        assert subscription.query_str in ["test", "example"]
        assert subscription.destination == 18749
        assert subscription.paused is False
Ejemplo n.º 5
0
def test_resume_destination__one_sub(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    sub = Subscription("test", 18749)
    sub.paused = True
    watcher.subscriptions.add(sub)
    func = SubscriptionFunctionality(watcher)
    list_subs = MockMethod("Listing subscriptions")
    func._list_subs = list_subs.call

    resp = func._resume_destination(18749)

    assert "Resumed all subscriptions" 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.paused is False
Ejemplo n.º 6
0
def test_resume_destination__all_running_except_elsewhere(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    sub1 = Subscription("test", 18749)
    sub1.paused = False
    watcher.subscriptions.add(sub1)
    sub2 = Subscription("example", 12345)
    sub2.paused = True
    watcher.subscriptions.add(sub2)
    func = SubscriptionFunctionality(watcher)

    resp = func._resume_destination(18749)

    assert resp == "All subscriptions are already running."
    assert len(watcher.subscriptions) == 2
    sub1, sub2 = list(watcher.subscriptions)[:2]
    if sub1.destination != 18749:
        sub2, sub1 = sub1, sub2
    assert sub1.destination == 18749
    assert sub1.query_str == "test"
    assert sub1.paused is False
    assert sub2.destination == 12345
    assert sub2.query_str == "example"
    assert sub2.paused is True
Ejemplo n.º 7
0
def test_resume_destination__multiple_subs(mock_client):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, mock_client)
    sub1 = Subscription("test", 18749)
    sub1.paused = True
    watcher.subscriptions.add(sub1)
    sub2 = Subscription("example", 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_destination(18749)

    assert "Resumed all subscriptions." in resp
    assert len(watcher.subscriptions) == 2
    assert list_subs.called
    assert list_subs.args[0] == 18749
    assert "Listing subscriptions" in resp
    for subscription in watcher.subscriptions:
        assert subscription.query_str in ["test", "example"]
        assert subscription.destination == 18749
        assert subscription.paused is False