Пример #1
0
    def init_with_config(self, config):
        session_interface = self._init_session(config)

        if config['WECHAT_TYPE'] == 17:
            from wechatpy.component import WeChatComponent
            self._is_component = True
            return WeChatComponent(
                config['WECHAT_APPID'],
                config['WECHAT_SECRET'],
                config['WECHAT_TOKEN'],
                config['WECHAT_AES_KEY'],
                session=session_interface,
            )

        if config['WECHAT_TYPE'] == 0:
            from wechatpy import WeChatClient
        else:
            from wechatpy.enterprise import WeChatClient

        return WeChatClient(
            config['WECHAT_APPID'],
            config['WECHAT_SECRET'],
            session=session_interface,
            timeout=config['WECHAT_TIMEOUT'],
            auto_retry=config['WECHAT_AUTO_RETRY'],
        )
Пример #2
0
class WeChatComponentTestCase(unittest.TestCase):
    app_id = '123456'
    app_secret = '123456'
    token = 'sdfusfsssdc'
    encoding_aes_key = 'yguy3495y79o34vod7843933902h9gb2834hgpB90rg'

    def setUp(self):
        self.client = WeChatComponent(self.app_id, self.app_secret, self.token,
                                      self.encoding_aes_key)

    def test_fetch_access_token(self):
        with HTTMock(wechat_api_mock):
            token = self.client.fetch_access_token()
            self.assertEqual('1234567890', token['component_access_token'])
            self.assertEqual(7200, token['expires_in'])
            self.assertEqual('1234567890', self.client.access_token)

    def test_create_preauthcode(self):
        with HTTMock(wechat_api_mock):
            result = self.client.create_preauthcode()
            self.assertEqual('1234567890', result['pre_auth_code'])
            self.assertEqual(600, result['expires_in'])

    def test_query_auth(self):
        authorization_code = '1234567890'
        with HTTMock(wechat_api_mock):
            result = self.client.query_auth(authorization_code)
            self.assertEqual('wxf8b4f85f3a794e77',
                             result['authorization_info']['authorizer_appid'])

    def test_refresh_authorizer_token(self):
        appid = 'appid'
        refresh_token = 'refresh_token'
        with HTTMock(wechat_api_mock):
            result = self.client.refresh_authorizer_token(appid, refresh_token)
            self.assertEqual('1234567890', result['authorizer_access_token'])
            self.assertEqual('123456789', result['authorizer_refresh_token'])
            self.assertEqual(7200, result['expires_in'])

    def test_get_authorizer_info(self):
        authorizer_appid = 'wxf8b4f85f3a794e77'
        with HTTMock(wechat_api_mock):
            result = self.client.get_authorizer_info(authorizer_appid)
            self.assertEqual('paytest01', result['authorizer_info']['alias'])

    def test_get_authorizer_option(self):
        with HTTMock(wechat_api_mock):
            appid = 'wxf8b4f85f3a794e77'
            result = self.client.get_authorizer_option(appid,
                                                       'voice_recognize')
            self.assertEqual('voice_recognize', result['option_name'])
            self.assertEqual('1', result['option_value'])

    def test_set_authorizer_option(self):
        with HTTMock(wechat_api_mock):
            appid = 'wxf8b4f85f3a794e77'
            result = self.client.set_authorizer_option(appid,
                                                       'voice_recognize', '0')
            self.assertEqual(0, result['errcode'])
Пример #3
0
class WeChatComponentTestCase(unittest.TestCase):
    app_id = "123456"
    app_secret = "123456"
    token = "sdfusfsssdc"
    encoding_aes_key = "yguy3495y79o34vod7843933902h9gb2834hgpB90rg"

    def setUp(self):
        self.client = WeChatComponent(self.app_id, self.app_secret, self.token, self.encoding_aes_key)

    def test_fetch_access_token_is_method(self):
        self.assertTrue(inspect.ismethod(self.client.fetch_access_token))

    def test_fetch_access_token(self):
        with HTTMock(wechat_api_mock):
            token = self.client.fetch_access_token()
            self.assertEqual("1234567890", token["component_access_token"])
            self.assertEqual(7200, token["expires_in"])
            self.assertEqual("1234567890", self.client.access_token)

    def test_create_preauthcode(self):
        with HTTMock(wechat_api_mock):
            result = self.client.create_preauthcode()
            self.assertEqual("1234567890", result["pre_auth_code"])
            self.assertEqual(600, result["expires_in"])

    def test_query_auth(self):
        authorization_code = "1234567890"
        with HTTMock(wechat_api_mock):
            result = self.client.query_auth(authorization_code)
            self.assertEqual("wxf8b4f85f3a794e77", result["authorization_info"]["authorizer_appid"])

    def test_refresh_authorizer_token(self):
        appid = "appid"
        refresh_token = "refresh_token"
        with HTTMock(wechat_api_mock):
            result = self.client.refresh_authorizer_token(appid, refresh_token)
            self.assertEqual("1234567890", result["authorizer_access_token"])
            self.assertEqual("123456789", result["authorizer_refresh_token"])
            self.assertEqual(7200, result["expires_in"])

    def test_get_authorizer_info(self):
        authorizer_appid = "wxf8b4f85f3a794e77"
        with HTTMock(wechat_api_mock):
            result = self.client.get_authorizer_info(authorizer_appid)
            self.assertEqual("paytest01", result["authorizer_info"]["alias"])

    def test_get_authorizer_option(self):
        with HTTMock(wechat_api_mock):
            appid = "wxf8b4f85f3a794e77"
            result = self.client.get_authorizer_option(appid, "voice_recognize")
            self.assertEqual("voice_recognize", result["option_name"])
            self.assertEqual("1", result["option_value"])

    def test_set_authorizer_option(self):
        with HTTMock(wechat_api_mock):
            appid = "wxf8b4f85f3a794e77"
            result = self.client.set_authorizer_option(appid, "voice_recognize", "0")
            self.assertEqual(0, result["errcode"])
Пример #4
0
class WeChatComponentTestCase(unittest.TestCase):
    app_id = '123456'
    app_secret = '123456'

    def setUp(self):
        self.client = WeChatComponent(self.app_id, self.app_secret)

    def test_fetch_access_token(self):
        with HTTMock(wechat_api_mock):
            token = self.client.fetch_access_token()
            self.assertEqual('1234567890', token['component_access_token'])
            self.assertEqual(7200, token['expires_in'])
            self.assertEqual('1234567890', self.client.access_token)

    def test_create_preauthcode(self):
        with HTTMock(wechat_api_mock):
            result = self.client.create_preauthcode()
            self.assertEqual('1234567890', result['pre_auth_code'])
            self.assertEqual(600, result['expires_in'])

    def test_query_auth(self):
        authorization_code = '1234567890'
        with HTTMock(wechat_api_mock):
            result = self.client.query_auth(authorization_code)
            self.assertEqual(
                'wxf8b4f85f3a794e77',
                result['authorization_info']['authorizer_appid']
            )

    def test_refresh_authorizer_token(self):
        appid = 'appid'
        refresh_token = 'refresh_token'
        with HTTMock(wechat_api_mock):
            result = self.client.refresh_authorizer_token(appid, refresh_token)
            self.assertEqual('1234567890', result['authorizer_access_token'])
            self.assertEqual('123456789', result['authorizer_refresh_token'])
            self.assertEqual(7200, result['expires_in'])

    def test_get_authorizer_info(self):
        authorizer_appid = 'wxf8b4f85f3a794e77'
        with HTTMock(wechat_api_mock):
            result = self.client.get_authorizer_info(authorizer_appid)
            self.assertEqual('paytest01', result['authorizer_info']['alias'])

    def test_get_authorizer_option(self):
        with HTTMock(wechat_api_mock):
            appid = 'wxf8b4f85f3a794e77'
            result = self.client.get_authorizer_option(appid, 'voice_recognize')
            self.assertEqual('voice_recognize', result['option_name'])
            self.assertEqual('1', result['option_value'])

    def test_set_authorizer_option(self):
        with HTTMock(wechat_api_mock):
            appid = 'wxf8b4f85f3a794e77'
            result = self.client.set_authorizer_option(
                appid, 'voice_recognize', '0'
            )
            self.assertEqual(0, result['errcode'])
Пример #5
0
 def setUp(self):
     component = WeChatComponent(
         self.component_appid,
         self.component_appsecret,
         self.component_token,
         self.encoding_aes_key,
     )
     self.oauth = ComponentOAuth(
         component,
         self.app_id,
     )
Пример #6
0
 def setUp(self):
     self.client = WeChatComponent(self.app_id, self.app_secret, self.token, self.encoding_aes_key)
Пример #7
0
 def setUp(self):
     self.client = WeChatComponent(self.app_id, self.app_secret)
Пример #8
0
 def setUp(self):
     self.client = WeChatComponent(self.app_id, self.app_secret)
Пример #9
0
 def setUp(self):
     self.client = WeChatComponent(
         self.app_id, self.app_secret, self.token, self.encoding_aes_key)