Ejemplo n.º 1
0
def test_add_to_blocklist__no_add_blank(context):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, context.bot)
    func = BlocklistFunctionality(watcher)

    resp = func._add_to_blocklist(18749, "")

    assert resp == "Please specify the tag you wish to add to blocklist."
    assert len(watcher.blocklists) == 0
Ejemplo n.º 2
0
def test_add_to_blocklist__creates_blocklist_for_channel(context):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, context.bot)
    func = BlocklistFunctionality(watcher)
    list_tags = MockMethod("Listing blocklisted tags")
    func._list_blocklisted_tags = list_tags.call

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

    assert "Added tag to blocklist" in resp
    assert "\"test\"" in resp
    assert list_tags.called
    assert list_tags.args[0] == 18749
    assert "Listing blocklisted tags" in resp
    assert len(watcher.blocklists[18749]) == 1
    assert isinstance(watcher.blocklists[18749], set)
    tag = list(watcher.blocklists[18749])[0]
    assert tag == "test"
Ejemplo n.º 3
0
def test_add_to_blocklist__add_tag_to_blocklist(context):
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, context.bot)
    watcher.blocklists[18749] = {"example"}
    func = BlocklistFunctionality(watcher)
    list_tags = MockMethod("Listing blocklisted tags")
    func._list_blocklisted_tags = list_tags.call

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

    assert "Added tag to blocklist" in resp
    assert "\"test\"" in resp
    assert list_tags.called
    assert list_tags.args[0] == 18749
    assert "Listing blocklisted tags" in resp
    assert len(watcher.blocklists[18749]) == 2
    assert isinstance(watcher.blocklists[18749], set)
    assert "example" in watcher.blocklists[18749]
    assert "test" in watcher.blocklists[18749]
Ejemplo n.º 4
0
def test_call__route_add_blocklisted_tag(context):
    update = MockTelegramUpdate.with_message(chat_id=14358,
                                             text="/add_blocklisted_tag test")
    api = MockExportAPI()
    watcher = SubscriptionWatcher(api, context.bot)
    func = BlocklistFunctionality(watcher)
    add_tag = MockMethod("Added to blocklist: test")
    func._add_to_blocklist = add_tag.call

    func.call(update, context)

    assert add_tag.called
    assert add_tag.args is not None
    assert add_tag.args[0] == 14358
    assert add_tag.args[1] == "test"
    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'] == "Added to blocklist: test"