def test_sender_called_on_success(self):
     settings = gen_settings()
     collector = Collector()
     with mock.patch("live_client.events.messenger.build_sender_function",
                     lambda _: collector):
         messenger.maybe_send_chat_message("_", settings)
         assert not collector.is_empty()
 def test_author_name_updates_author(self):
     settings = gen_settings()
     new_author_name = "__new_author__"
     assert settings["output"]["author"]["name"] != new_author_name
     collector = Collector()
     with mock.patch("live_client.events.messenger.build_sender_function",
                     lambda _: collector):
         messenger.maybe_send_chat_message("_",
                                           settings,
                                           author_name=new_author_name)
     assert collector.buffer[0]["author"]["name"] == new_author_name
    def test_message_not_sent_if_no_author(self):
        settings = {"output": {"room": "__room__"}, "live": {}}
        collector = Collector()
        with mock.patch("live_client.events.messenger.build_sender_function",
                        lambda _: collector):
            message_sent_1 = messenger.maybe_send_chat_message("_", settings)
            assert not message_sent_1 and collector.is_empty()

        settings["output"]["author"] = None
        collector = Collector()
        with mock.patch("live_client.events.messenger.build_sender_function",
                        lambda _: collector):
            message_sent_2 = messenger.maybe_send_chat_message("_", settings)
            assert not message_sent_2 and collector.is_empty()
Пример #4
0
def update_chat(chat, last_ts, next_ts, index_mnemonic, settings):
    if not chat:
        return

    items_to_send = []
    for item in chat:
        item_index = int(item.get(index_mnemonic, -1))

        if last_ts <= item_index < next_ts:
            items_to_send.append(item)
        elif item_index > next_ts:
            break

    logging.debug("{} messages between {} and {}".format(
        len(items_to_send), last_ts, next_ts))

    for item in items_to_send:
        message = item.get("MESSAGE", "")
        source = item.get("SOURCE", "")
        if message and source:
            messenger.maybe_send_chat_message(message,
                                              timestamp.get_timestamp(),
                                              settings,
                                              author_name=source)
Пример #5
0
def send_message(message, timestamp, settings=None):
    messenger.maybe_send_message_event(message, timestamp, settings)
    messenger.maybe_send_chat_message(message, timestamp, settings)
 def test_returns_true_on_success(self):
     settings = gen_settings(output={})
     ret = messenger.maybe_send_chat_message("_", settings)
     assert ret is False
    def test_message_should_be_sent(self):
        settings = {"output": {"author": {}, "room": "__room__"}, "live": {}}

        message_sent = messenger.maybe_send_chat_message("_", settings)
        assert message_sent