示例#1
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'])

    def test_get_wxa_template_list(self):
        with HTTMock(wechat_api_mock):
            result = self.client.get_wxa_template_list()
            self.assertEqual(0, result['errcode'])
            self.assertIn('template_list', result)

    def test_get_wxa_draft_list(self):
        with HTTMock(wechat_api_mock):
            result = self.client.get_wxa_draft_list()
            self.assertEqual(0, result['errcode'])
            self.assertIn('draft_list', result)

    def test_delete_wxa_template(self):
        with HTTMock(wechat_api_mock):
            result = self.client.delete_wxa_template(12)
            self.assertEqual(0, result['errcode'])

    def test_add_to_wxa_templatee(self):
        with HTTMock(wechat_api_mock):
            result = self.client.add_to_wxa_template(12)
            self.assertEqual(0, result['errcode'])