Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_click_event(self):
xml = """
123456789
1
"""
msg = parse_message(xml)
self.assertEqual('event', msg.type)
self.assertEqual('click', msg.event)
self.assertEqual('EVENTKEY', msg.key)
def test_parse_video_message(self):
xml = """
1357290913
1234567890123456
1
"""
msg = parse_message(xml)
self.assertEqual('video', msg.type)
def test_parse_voice_message(self):
xml = """
1357290913
1234567890123456
1
"""
msg = parse_message(xml)
self.assertEqual('voice', msg.type)
def test_parse_view_event(self):
xml = """
123456789
1
"""
msg = parse_message(xml)
self.assertEqual('event', msg.type)
self.assertEqual('view', msg.event)
self.assertEqual('www.qq.com', msg.url)
def test_parse_location_event(self):
xml = """
123456789
23.137466
113.352425
119.385040
1
"""
msg = parse_message(xml)
self.assertEqual('event', msg.type)
self.assertEqual('location', msg.event)
self.assertEqual(23.137466, msg.latitude)
self.assertEqual(113.352425, msg.longitude)
self.assertEqual(119.385040, msg.precision)
def test_parse_location_message(self):
xml = """
1351776360
23.134521
113.358803
20
<label></label>
1234567890123456
1
"""
msg = parse_message(xml)
self.assertEqual('location', msg.type)
def test_parse_subscribe_event(self):
xml = """
123456789
1
"""
msg = parse_message(xml)
self.assertEqual('event', msg.type)
self.assertEqual('subscribe', msg.event)
def test_parse_text_message(self):
xml = """
1348831860
<content></content>
1234567890123456
1
"""
msg = parse_message(xml)
self.assertEqual('text', msg.type)
self.assertEqual(1, msg.agent)
)
except InvalidSignatureException:
abort(403)
return echo_str
try:
msg = crypto.decrypt_message(
request.data,
signature,
timestamp,
nonce,
)
except (InvalidSignatureException, InvalidCorpIdException):
return abort(403)
else:
request.wechat_msg = parse_message(msg)
res = method(*args, **kwargs)
xml = ''
if isinstance(res, BaseReply):
xml = res.render()
crypto = WeChatCrypto(
current_app.config['WECHAT_TOKEN'],
current_app.config['WECHAT_AES_KEY'],
current_app.config['WECHAT_APPID']
)
xml = crypto.encrypt_message(xml, nonce, timestamp)
return xml
echo_str
)
except InvalidSignatureException:
abort(403)
return echo_str
else:
try:
msg = crypto.decrypt_message(
request.data,
signature,
timestamp,
nonce
)
except (InvalidSignatureException, InvalidCorpIdException):
abort(403)
msg = parse_message(msg)
if msg.type == 'text':
reply = create_reply(msg.content, msg).render()
else:
reply = create_reply('Can not handle this for now', msg).render()
res = crypto.encrypt_message(reply, nonce, timestamp)
return res