Ejemplo n.º 1
0
def test_remove_from_blocklist__tag_not_in_blocklist(context):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, context.bot)
    watcher.blocklists[18749] = {"example"}
    watcher.blocklists[18747] = {"test"}
    func = BlocklistFunctionality(watcher)

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

    assert resp == "The tag \"test\" is not on the blocklist for this chat."
    assert len(watcher.blocklists) == 2
    assert len(watcher.blocklists[18749]) == 1
    assert len(watcher.blocklists[18747]) == 1
Ejemplo n.º 2
0
def test_call__route_remove_blocklisted_tag(context):
    update = MockTelegramUpdate.with_message(
        chat_id=14358, text="/remove_blocklisted_tag example")
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, context.bot)
    func = BlocklistFunctionality(watcher)
    remove_tag = MockMethod("Removed from blocklist: example")
    func._remove_from_blocklist = remove_tag.call

    func.call(update, context)

    assert remove_tag.called
    assert remove_tag.args is not None
    assert remove_tag.args[0] == 14358
    assert remove_tag.args[1] == "example"
    context.bot.send_message.assert_called()
    assert context.bot.send_message.call_args[1][
        'chat_id'] == update.message.chat_id
    assert context.bot.send_message.call_args[1][
        'text'] == "Removed from blocklist: example"
Ejemplo n.º 3
0
def test_remove_from_blocklist__removes_tag_from_blocklist(context):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, context.bot)
    watcher.blocklists[18749] = {"example", "test"}
    watcher.blocklists[18747] = {"test"}
    func = BlocklistFunctionality(watcher)
    list_tags = MockMethod("Listing blocklisted tags")
    func._list_blocklisted_tags = list_tags.call

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

    assert "Removed tag from blocklist: \"test\"." in resp
    assert list_tags.called
    assert list_tags.args[0] == 18749
    assert "Listing blocklisted tags" in resp
    assert len(watcher.blocklists) == 2
    assert len(watcher.blocklists[18749]) == 1
    assert len(watcher.blocklists[18747]) == 1
    assert watcher.blocklists[18749] == {"example"}
    assert watcher.blocklists[18747] == {"test"}