Exemple #1
0
    def test_get_token_raise_exception(self, mock_data):
        """Test get web access token failure."""
        mock_data.return_value = {
            "errcode": 40029,
            "errmsg": "invalid code",
            "requrl": 'requrl'
        }

        with self.assertRaises(WechatKitException) as error:
            WechatAPI.get_web_access_token(self.appid, self.appsecret, 'code',
                                           raise_exception=True)

        self.assertEqual(error.exception.error_info, '不合法的oauth_code')
Exemple #2
0
 def test_get_token_failure(self, mock_data):
     """Test get web access token failure."""
     mock_data.return_value = {
         "errcode": 40029,
         "errmsg": "invalid code",
         "requrl": 'requrl'
     }
     result = WechatAPI.get_web_access_token(self.appid, self.appsecret,
                                             'code')
     self.assertIn('errmsg', result)
     self.assertIn('requrl', result)
Exemple #3
0
    def test_get_web_token(self, mock_data):
        """Test get web access token success."""
        mock_data.return_value = {
            "access_token": "ACCESS_TOKEN",
            "expires_in": 7200,
            "refresh_token": "REFRESH_TOKEN",
            "openid": "OPENID",
            "scope": "SCOPE"
        }
        result = WechatAPI.get_web_access_token(
            self.appid, self.appsecret, 'code')

        self.assertEqual(result.get('access_token'), 'ACCESS_TOKEN')