# Path: WeCron/wxhook/message_handler.py
# def handle_message(msg):
#     # msgid = str(msg.id)
#     # if msgid not in ['0', 'None'] and shove.get('last_msgid') == msgid:  # Duplicated message
#     #     return TextReply(
#     #         content='',
#     #         message=msg,
#     #     ).render()
#     # TODO unique based on msgid
#     resp_msg = WechatMessage(msg).handle()
#     # shove['last_msgid'] = msgid
#     return resp_msg


from django.test import TestCase
from django.db.models.signals import post_save
from django.utils import timezone
from wechatpy import parse_message
from httmock import urlmatch, response, HTTMock
from common import wechat_client
from common.tests import access_token_mock
from ..message_handler import handle_message
from wechat_user.models import WechatUser
from remind.models import Remind

    mock = HTTMock(access_token_mock, semantic_parser_mock, send_message_mock)

    @classmethod
    def setUpTestData(cls):
        cls.mock.__enter__()

    def setUp(self):
        self.user = WechatUser(openid='FromUser', nickname='UserName')
        self.user.save()
        self.settings(WX_APPID='123').enable()
        wechat_client.appid = '123'
        # Disable scheduler
        post_save.disconnect(dispatch_uid='update-scheduler')

    def build_wechat_msg(self, req_text):
        return parse_message(req_text)

    def test_text(self):
        req_text = """
        <xml>
        <ToUserName><![CDATA[toUser]]></ToUserName>
        <FromUserName><![CDATA[FromUser]]></FromUserName>
        <CreateTime>1348831860</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[%s]]></Content>
        <MsgId>12345678901234561</MsgId>
        </xml>
        """ % self.remind_desc
        wechat_msg = self.build_wechat_msg(req_text)

# Path: WeCron/wxhook/message_handler.py
# def handle_message(msg):
#     # msgid = str(msg.id)
#     # if msgid not in ['0', 'None'] and shove.get('last_msgid') == msgid:  # Duplicated message
#     #     return TextReply(
#     #         content='',
#     #         message=msg,
#     #     ).render()
#     # TODO unique based on msgid
#     resp_msg = WechatMessage(msg).handle()
#     # shove['last_msgid'] = msgid
#     return resp_msg


# Path: WeCron/wxhook/tests/test_message_handler.py
from django.test import TestCase
from django.db.models.signals import post_save
from django.utils import timezone
from wechatpy import parse_message
from httmock import urlmatch, response, HTTMock
from common import wechat_client
from common.tests import access_token_mock
from ..message_handler import handle_message
from wechat_user.models import WechatUser
from remind.models import Remind


    mock = HTTMock(access_token_mock, semantic_parser_mock, send_message_mock)

    @classmethod
    def setUpTestData(cls):
        cls.mock.__enter__()

    def setUp(self):
        self.user = WechatUser(openid='FromUser', nickname='UserName')
        self.user.save()
        self.settings(WX_APPID='123').enable()
        wechat_client.appid = '123'
        # Disable scheduler
        post_save.disconnect(dispatch_uid='update-scheduler')

    def build_wechat_msg(self, req_text):
        return parse_message(req_text)

    def test_text(self):
        req_text = """
        <xml>
        <ToUserName><![CDATA[toUser]]></ToUserName>
        <FromUserName><![CDATA[FromUser]]></FromUserName>
        <CreateTime>1348831860</CreateTime>
        <MsgType><![CDATA[text]]></MsgType>
        <Content><![CDATA[%s]]></Content>
        <MsgId>12345678901234561</MsgId>
        </xml>
        """ % self.remind_desc
        wechat_msg = self.build_wechat_msg(req_text)

        resp_xml = handle_message(wechat_msg)