예제 #1
0
    def test_common_filter(self):
        def t(m): return True

        def f(m): return False

        m = parse_wechat_message(messages["text1"])

        self.assertTrue(filters.all(m))

        self.assertTrue(filters.or_(t, t)(m) == True)
        self.assertTrue(filters.or_(f, t)(m) == True)
        self.assertTrue(filters.or_(t, f)(m) == True)
        self.assertFalse(filters.or_(f, f)(m) == True)
        self.assertTrue(filters.or_(t, t, t)(m) == True)
        self.assertTrue(filters.or_(t, t, f)(m) == True)
        self.assertTrue(filters.or_(t, f, t)(m) == True)
        self.assertTrue(filters.or_(t, f, f)(m) == True)
        self.assertTrue(filters.or_(f, t, t)(m) == True)
        self.assertTrue(filters.or_(f, t, f)(m) == True)
        self.assertTrue(filters.or_(f, f, t)(m) == True)
        self.assertFalse(filters.or_(f, f, f)(m) == True)

        self.assertTrue(filters.and_(t, t)(m) == True)
        self.assertFalse(filters.and_(t, f)(m) == True)
        self.assertFalse(filters.and_(f, t)(m) == True)
        self.assertFalse(filters.and_(f, f)(m) == True)
        self.assertTrue(filters.and_(t, t, t)(m) == True)
        self.assertFalse(filters.and_(t, t, f)(m) == True)
        self.assertFalse(filters.and_(t, f, t)(m) == True)
        self.assertFalse(filters.and_(t, f, f)(m) == True)
        self.assertFalse(filters.and_(f, t, t)(m) == True)
        self.assertFalse(filters.and_(f, t, f)(m) == True)
        self.assertFalse(filters.and_(f, f, t)(m) == True)
        self.assertFalse(filters.and_(f, f, f)(m) == True)
예제 #2
0
 def test_location_filter(self):
     msg = parse_wechat_message(messages.get('location'))
     self.assertTrue(
         filters.message.in_location(msg.location_x, msg.location_y, 1)(msg)
     )
     self.assertFalse(
         filters.message.in_location(msg.location_x + 2, msg.location_y, 1)(msg)
     )
예제 #3
0
    def do_message_filter_test(self, filter, result):
        messages_ = {k: parse_wechat_message(v)
                     for k, v in messages.items()}
        rv = True
        self.assertTrue(len(messages_) == len(result))
        filter_ = filter
        l = []
        for v in messages_.values():
            l.append(filter_(v))

        while l and rv:
            rv = rv and (l.pop() == result.pop())

        return rv
예제 #4
0
파일: __init__.py 프로젝트: cls1997/wx
    def handle_message(self, msg):
        """
        TODO: We need INTERCEPTOR!!!
        """
        self.logger.info("Message before parsing: {}".format(msg))
        start = time.time()
        msg = parse_wechat_message(msg)
        self.logger.info(
            "Message parsed.Type {}, Id {}".format(type(msg), msg.msg_id))
        self.logger.debug("Message parsing over.")

        # Input a BaseMessage return a BaseReply
        reply = self.do_filter(msg)

        self.logger.debug(reply)
        self.logger.info("It spent %dms to make this response.",
                         int((time.time() - start) * 1000))
        return reply
예제 #5
0
 def test_all_filter(self):
     self.assertTrue(filters.all(parse_wechat_message(messages['text1'])))
예제 #6
0
 def setUp(self):
     self.messages = {k: parse_wechat_message(v)
                      for k, v in messages.items()}