Example #1
0
def test_process_music_function_reply():
    reply = process_function_reply(["title", "desc", "url"])
    assert isinstance(reply, MusicReply)
    assert reply.title == "title"
    assert reply.description == "desc"
    assert reply.url == reply.hq_url == "url"

    reply = process_function_reply(["title", "desc", "url", "hq"])
    assert isinstance(reply, MusicReply)
    assert reply.title == "title"
    assert reply.description == "desc"
    assert reply.url == "url"
    assert reply.hq_url == "hq"
Example #2
0
def test_process_music_function_reply():
    reply = process_function_reply(["title", "desc", "url"])
    assert isinstance(reply, MusicReply)
    assert reply.title == "title"
    assert reply.description == "desc"
    assert reply.url == reply.hq_url == "url"

    reply = process_function_reply(["title", "desc", "url", "hq"])
    assert isinstance(reply, MusicReply)
    assert reply.title == "title"
    assert reply.description == "desc"
    assert reply.url == "url"
    assert reply.hq_url == "hq"
Example #3
0
    def get_reply(self, message):
        """
        根据 message 的内容获取 Reply 对象。

        :param message: 要处理的 message
        :return: 获取的 Reply 对象
        """
        session_storage = self.session_storage

        id = None
        session = None
        if session_storage and hasattr(message, "source"):
            id = to_binary(message.source)
            session = session_storage[id]

        handlers = self.get_handlers(message.type)
        try:
            for handler, args_count in handlers:
                args = [message, session][:args_count]
                reply = handler(*args)
                if session_storage and id:
                    session_storage[id] = session
                if reply:
                    return process_function_reply(reply, message=message)
        except:
            self.logger.exception("Catch an exception")
Example #4
0
    def get_reply(self, message):
        """
        根据 message 的内容获取 Reply 对象。

        :param message: 要处理的 message
        :return: 获取的 Reply 对象
        """
        session_storage = self.session_storage

        id = None
        session = None
        if session_storage and hasattr(message, "source"):
            id = to_binary(message.source)
            session = session_storage[id]

        handlers = self.get_handlers(message.type)
        try:
            for handler, args_count in handlers:
                args = [message, session][:args_count]
                reply = handler(*args)
                if session_storage and id:
                    session_storage[id] = session
                if reply:
                    return process_function_reply(reply, message=message)
        except:
            self.logger.exception("Catch an exception")
Example #5
0
def test_process_articles_function_reply():
    reply = process_function_reply([["tt1", 'ds1', 'img', 'url'],
                                    ["tt2", 'ds2', 'im2g', 'u2rl']])
    assert isinstance(reply, ArticlesReply)
    assert len(reply._articles) == 2
    article_1, article_2 = reply._articles
    assert isinstance(article_1, Article), isinstance(article_2, Article)
    assert article_1.title == "tt1", article_2.title == "tt2"
    assert article_1.description == "ds1", article_2.description == "ds2"
    assert article_1.img == "img", article_2.img == "im2g"
    assert article_1.url == "url", article_2.url == "u2rl"

    process_function_reply([[1, 2, 3, 4]] * 10)

    with pytest.raises(AttributeError):
        process_function_reply([[1, 2, 3, 4]] * 11)
Example #6
0
def test_process_articles_function_reply():
    reply = process_function_reply(
        [["tt1", 'ds1', 'img', 'url'], ["tt2", 'ds2', 'im2g', 'u2rl']]
    )
    assert isinstance(reply, ArticlesReply)
    assert len(reply._articles) == 2
    article_1, article_2 = reply._articles
    assert isinstance(article_1, Article), isinstance(article_2, Article)
    assert article_1.title == "tt1", article_2.title == "tt2"
    assert article_1.description == "ds1", article_2.description == "ds2"
    assert article_1.img == "img", article_2.img == "im2g"
    assert article_1.url == "url", article_2.url == "u2rl"

    process_function_reply([[1, 2, 3, 4]] * 10)

    with pytest.raises(AttributeError):
        process_function_reply([[1, 2, 3, 4]] * 11)
Example #7
0
    def get_reply(self, message):
        """
        Return the Reply Object for the given message.
        """
        session_storage = self.config["SESSION_STORAGE"]

        id = None
        session = None
        if session_storage and hasattr(message, "source"):
            id = to_binary(message.source)
            session = session_storage[id]

        handlers = self.get_handlers(message.type)
        try:
            for handler, args_count in handlers:
                args = [message, session][:args_count]
                reply = handler(*args)
                if session_storage and id:
                    session_storage[id] = session
                if reply:
                    return process_function_reply(reply, message=message)
        except:
            self.logger.warning("Catch an exception", exc_info=True)
Example #8
0
    def get_reply(self, message):
        """
        Return the Reply Object for the given message.
        """
        session_storage = self.config["SESSION_STORAGE"]

        id = None
        session = None
        if session_storage and hasattr(message, "source"):
            id = to_binary(message.source)
            session = session_storage[id]

        handlers = self.get_handlers(message.type)
        try:
            for handler, args_count in handlers:
                args = [message, session][:args_count]
                reply = handler(*args)
                if session_storage and id:
                    session_storage[id] = session
                if reply:
                    return process_function_reply(reply, message=message)
        except:
            self.logger.warning("Catch an exception", exc_info=True)
Example #9
0
def test_process_text_function_reply():
    reply = process_function_reply("test")
    assert isinstance(reply, TextReply)
    assert reply.content == "test"
Example #10
0
def test_process_unknown_function_reply():
    reply = SuccessReply()
    assert process_function_reply(reply) == reply
Example #11
0
def test_process_text_function_reply():
    reply = process_function_reply("test")
    assert isinstance(reply, TextReply)
    assert reply.content == "test"
Example #12
0
def test_process_unknown_function_reply():
    reply = SuccessReply()
    assert process_function_reply(reply) == reply