Пример #1
0
from unittest.mock import MagicMock

from notifirc.processor import process_messages
from notifirc.message_store import MessageStore
from notifirc.subscriber import Subscriber
from notifirc.filters import create_filter
from notifirc.match_writer import MatchWriter
from notifirc.message import Message


FILTS = [
    create_filter(0, 'contains', 'hi')
]


def test_process_messages_saves_each_message():
    msg_store = MessageStore()
    msg_store.save_message = MagicMock()
    msg_store.get_message = MagicMock(return_value=None)
    sub = Subscriber()
    msg = Message(0, 'mychannel', 'rth', 'zero')
    sub.listen = MagicMock(return_value=[
        {'data': msg.encode()}
    ])
    m_writer = MatchWriter()

    process_messages(msg_store, sub, FILTS, m_writer)

    msg_store.save_message.assert_called_with(msg)

Пример #2
0
def test_create_filter():
    f = create_filter(0, "starts_with", "meow")
    assert_equals(f["id"], 0)
    assert_equals(f["func"]("meow hiss"), True)