# -*- coding: utf-8 -*-
from werobot import WeRoBot
from werobot.parser import parse_user_msg
from werobot.replies import TextReply
import os
werobot = WeRoBot(SESSION_STORAGE=False)
def teardown_module(module):
try:
os.remove(os.path.abspath("werobot_session"))
except OSError:
pass
def test_subscribe_handler():
@werobot.subscribe
def subscribe(message):
return '关注'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'关注'
def test_unsubscribe_handler():
@werobot.unsubscribe
def unsubscribe(message):
return '取消关注'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'取消关注'
def test_scan_push_handler():
@werobot.scancode_push
def scancode_push(message):
return '扫描推送'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'扫描推送'
def test_scan_waitmsg_handler():
@werobot.scancode_waitmsg
def scancode_waitmsg(message):
return '扫描弹消息'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'扫描弹消息'
def test_pic_sysphoto_handler():
@werobot.pic_sysphoto
def pic_sysphoto():
return '瞧一瞧系统拍照'
message = parse_user_msg(
"""
1408090651
1
-
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'瞧一瞧系统拍照'
def test_pic_photo_or_album_handler():
@werobot.pic_photo_or_album
def pic_photo_or_album():
return '瞧一瞧拍照或者相册'
message = parse_user_msg(
"""
1408090816
1
-
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'瞧一瞧拍照或者相册'
def test_pic_weixin_handler():
@werobot.pic_weixin
def pic_weixin():
return '瞧一瞧微信相册'
message = parse_user_msg(
"""
1408090816
1
-
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'瞧一瞧微信相册'
def test_location_select_handler():
@werobot.location_select
def location_select():
return '瞧一瞧地理位置'
message = parse_user_msg(
"""
1408091189
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'瞧一瞧地理位置'
def test_click_handler():
@werobot.click
def scan(message):
return '喵喵'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'喵喵'
def test_view_handler():
@werobot.view
def view(message):
return '汪汪'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'汪汪'
def test_location_event_handler():
@werobot.location_event
def location_event(message):
return '位置喵喵'
message = parse_user_msg(
"""
123456789
23.137466
113.352425
119.385040
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'位置喵喵'
def test_card_pass_check_handler():
@werobot.card_pass_check
def card_pass_check():
return '瞧一瞧通过了'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'瞧一瞧通过了'
def test_card_not_pass_check_handler():
@werobot.card_not_pass_check
def card_pass_not_check():
return '瞧一瞧没过'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'瞧一瞧没过'
def test_user_get_card_handler():
@werobot.user_get_card
def user_get_card():
return '恭喜入坑'
message = parse_user_msg(
"""
1472551036
0
0
0
0
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'恭喜入坑'
def test_user_gifting_card_handler():
@werobot.user_gifting_card
def user_gifting_card():
return '锅从天上来'
message = parse_user_msg(
"""
1474181868
0
0
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'锅从天上来'
def test_user_del_card_handler():
@werobot.user_del_card
def user_del_card():
return '摆脱负担'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'摆脱负担'
def test_user_consume_card_handler():
@werobot.user_consume_card
def user_consume_card():
return '恭喜脱坑'
message = parse_user_msg(
"""
1472549042
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'恭喜脱坑'
def test_user_pay_from_pay_cell_handler():
@werobot.user_pay_from_pay_cell
def user_pay_from_pay_cell():
return '冲动消费'
message = parse_user_msg(
"""
1442390947
291710000
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'冲动消费'
def test_user_view_card_handler():
@werobot.user_view_card
def user_view_card():
return '我就瞧一瞧,不买'
message = parse_user_msg(
"""
1467811138
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'我就瞧一瞧,不买'
def test_user_enter_session_from_card_handler():
@werobot.user_enter_session_from_card
def user_enter_session_from_card():
return '退货是不可能退货的'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'退货是不可能退货的'
def test_update_member_card_handler():
@werobot.update_member_card
def update_member_card():
return '冲动消费导致余额减少'
message = parse_user_msg(
"""
1445507140
3
0
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'冲动消费导致余额减少'
def test_card_sku_remind_handler():
@werobot.card_sku_remind
def card_sku_remind():
return '骗钱大成功'
message = parse_user_msg(
"""
1443838506
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'骗钱大成功'
def test_card_pay_order_handler():
@werobot.card_pay_order
def card_pay_order():
return '冲动消费的凭证'
message = parse_user_msg(
"""
1453295737
1453295737
0
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'冲动消费的凭证'
def test_submit_membercard_user_info_handler():
@werobot.submit_membercard_user_info
def submit_membercard_user_info():
return '现在醒一醒还来得及'
message = parse_user_msg(
"""
1432668700
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'现在醒一醒还来得及'
def test_templatesendjobfinish_event_handler():
@werobot.templatesendjobfinish_event
def templatesendjobfinish_event():
return '喵喵~模板消息已经推送'
message = parse_user_msg(
"""
1395658920
200163836
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'喵喵~模板消息已经推送'
def test_unknown_event():
@werobot.unknown_event
def unknown_event(message):
return '不知道的事件喵'
message = parse_user_msg(
"""
123456789
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'不知道的事件喵'
def test_text():
@werobot.text
def text(message):
return '普通的Text喵'
message = parse_user_msg(
"""
1348831860
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'普通的Text喵'
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_location():
@werobot.location
def location(message):
return '地理位置汪'
message = parse_user_msg(
"""
1351776360
23.134521
113.358803
20
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'地理位置汪'
def test_link():
@werobot.link
def link(message):
return '链接喵'
message = parse_user_msg(
"""
1351776360
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'链接喵'
def test_voice():
@werobot.voice
def voice(message):
return '声音喵'
message = parse_user_msg(
"""
1357290913
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'声音喵'
def test_video():
@werobot.video
def video():
return '请收下这一段榴莲的视频'
message = parse_user_msg(
"""
1357290913
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'请收下这一段榴莲的视频'
def test_shortvideo():
@werobot.shortvideo
def shortvideo():
return '请收下这一段榴莲的小视频'
message = parse_user_msg(
"""
1357290913
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'请收下这一段榴莲的小视频'
def test_user_scan_product():
@werobot.user_scan_product
def user_scan_product():
return '打扰了'
message = parse_user_msg(
"""
1438250110
1
2
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'打扰了'
def test_user_scan_product_enter_session():
@werobot.user_scan_product_enter_session
def user_scan_product_enter_session():
return '再次打扰了'
message = parse_user_msg(
"""
1433259128
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'再次打扰了'
def test_user_scan_product_async():
@werobot.user_scan_product_async
def user_scan_product_async():
return '异步的地理位置喵'
message = parse_user_msg(
"""
1434541327
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'异步的地理位置喵'
def test_user_scan_product_verify_action():
@werobot.user_scan_product_verify_action
def user_scan_product_verify_action():
return '审核通过了喵'
message = parse_user_msg(
"""
1450429257
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'审核通过了喵'
def test_unknown():
@werobot.unknown
def unknown(message):
return '不知道喵'
message = parse_user_msg(
"""
1351776360
1234567890123456
"""
)
reply = werobot.get_reply(message)
assert isinstance(reply, TextReply)
assert reply._args['content'] == u'不知道喵'