def __init__(self, appname, ini_name): """ 基类构造函数 @param appname: 应用名称 @param ini_name: 配置文件路径 @return: """ self.appname = appname if ini_name: self.config = utils.get_config(ini_name) else: self.config = utils.get_config() self.logger = logging.getLogger('easy_wechat') self.init_logger()
def test_verify_OK(self): """ 测试是否能够正确完成接口验证 @return: None """ echo_str = ('JJbZng5xDFUaE4UhtGVct3ksIzuIeh2Hik4Jf%2BHtuJPppSyv7' 'gaNY%2FplvblHZRe1JVMv3XGj9fST8ppx62lArQ%3D%3D') param_dict = { 'msg_signature': 'fa5e779b1eeb709358f9742db4704ff932754a45', 'timestamp': '1450093931', 'nonce': '112775', 'echostr': urllib.unquote(echo_str), } with mock.patch('flask.request') as mock_request: type(mock_request).method = mock.PropertyMock(return_value='GET') type(mock_request).args = mock.PropertyMock( return_value=param_dict) type(mock_request).data = mock.PropertyMock(return_value='') config = utils.get_config('config_test.ini') token = '8wdYqOgJWQlFRE13FaBAUOU2FxXVtGr' aes_key = config.get('demo', 'encoding_aes_key') corp_id = config.get('demo', 'corpid') server = easy_wechat.WeChatServer('demo', 'config_test.ini') server.wxcpt = utils.WXBizMsgCrypt(token, aes_key, corp_id) self.assertIsInstance(server.callback(), str)
def test_verify_OK(self): """ 测试是否能够正确完成接口验证 @return: None """ echo_str = ('JJbZng5xDFUaE4UhtGVct3ksIzuIeh2Hik4Jf%2BHtuJPppSyv7' 'gaNY%2FplvblHZRe1JVMv3XGj9fST8ppx62lArQ%3D%3D') param_dict = { 'msg_signature': 'fa5e779b1eeb709358f9742db4704ff932754a45', 'timestamp': '1450093931', 'nonce': '112775', 'echostr': urllib.unquote(echo_str), } with mock.patch('flask.request') as mock_request: type(mock_request).method = mock.PropertyMock(return_value='GET') type(mock_request).args = mock.PropertyMock(return_value=param_dict) type(mock_request).data = mock.PropertyMock(return_value='') config = utils.get_config('config_test.ini') token = '8wdYqOgJWQlFRE13FaBAUOU2FxXVtGr' aes_key = config.get('demo', 'encoding_aes_key') corp_id = config.get('demo', 'corpid') server = easy_wechat.WeChatServer('demo', 'config_test.ini') server.wxcpt = utils.WXBizMsgCrypt(token, aes_key, corp_id) self.assertIsInstance(server.callback(), str)