Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def send_xml(self, xml):
message = parse_user_msg(xml)
return self.send(message)
def test_subscribe_event():
message = parse_user_msg(
"""
123456789
"""
)
assert message.target == "toUser"
assert message.source == "FromUser"
assert message.time == 123456789
assert message.type == "subscribe_event"
message = parse_user_msg(
def test_image():
@werobot.image
def image(message):
return '图片喵'
message = parse_user_msg(
"""
1348831860
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'图片喵'
def test_wechat_reply():
message = parse_user_msg(
"""
1348831860
1234567890123456
"""
)
s = to_binary("喵fdsjaklfsk")
reply = WeChatReply(message=message, s=s)
assert reply._args['source'] == 'toUser'
assert reply._args['target'] == 'fromUser'
def test_card_pay_order_event():
message = parse_user_msg(
"""
1453295737
1453295737
0
def test_none_message():
assert not parse_user_msg("")
def test_user_consume_card_event():
message = parse_user_msg(
"""
1472549042
"""
123456789
"""
)
assert message.target == "toUser"
assert message.source == "FromUser"
assert message.time == 123456789
assert message.type == "subscribe_event"
message = parse_user_msg(
"""
123456789
"""
)
assert message.target == "toUser"
assert message.source == "FromUser"
assert message.time == 123456789
assert message.type == "subscribe_event"
assert message.key == "qrscene_123123"
def test_unknown_event():
message = parse_user_msg(
"""
123456789
"""
)
assert message.target == "toUser"
assert message.source == "FromUser"
assert message.time == 123456789
assert message.type == "unknown_event"
def handle(self, **kwargs):
if not self.entry:
self.init()
if not self.robot.check_signature(
request.params.get("timestamp"),
request.params.get("nonce"),
request.params.get("signature")
):
return abort(403)
body = request.httprequest.data
message = parse_user_msg(body)
self.robot.logger.info("Receive message %s" % message)
reply = self.robot.get_reply(message)
if not reply:
self.robot.logger.warning("No handler responded message %s"
% message)
return ''
_logger.info('>>> reply: %s'%reply)
return reply