def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post("https://api.weibo.com/oauth2/access_token",
                    json={"access_token": "weibo"})
        mocker.start()
        self.addCleanup(mocker.stop)

        weibo = OAuth2Session("someclientid", redirect_uri="https://i.b")
        self.session = weibo_compliance_fix(weibo)
    def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post(
            "https://api.weibo.com/oauth2/access_token", json={"access_token": "weibo"}
        )
        mocker.start()
        self.addCleanup(mocker.stop)

        weibo = OAuth2Session("someclientid", redirect_uri="https://i.b")
        self.session = weibo_compliance_fix(weibo)
    def test_fetch_access_token(self):
        weibo = OAuth2Session('foo', redirect_uri='https://i.b')
        weibo = weibo_compliance_fix(weibo)

        weibo.post = mock.MagicMock()
        response = requests.Response()
        response.status_code = 200
        response._content = '{"access_token":"weibo"}'.encode('UTF-8')
        weibo.post.return_value = response

        token = weibo.fetch_token('https://mocked.out',
                                     client_secret='bar',
                                     authorization_response='https://i.b/?code=hello')
        self.assertEqual(token, {'access_token': 'weibo', 'token_type': 'Bearer'})
    def test_fetch_access_token(self):
        weibo = OAuth2Session("foo", redirect_uri="https://i.b")
        weibo = weibo_compliance_fix(weibo)

        weibo.post = mock.MagicMock()
        response = requests.Response()
        response.status_code = 200
        response.request = mock.MagicMock()
        response._content = '{"access_token":"weibo"}'.encode("UTF-8")
        weibo.post.return_value = response

        token = weibo.fetch_token(
            "https://mocked.out", client_secret="bar", authorization_response="https://i.b/?code=hello"
        )
        self.assertEqual(token, {"access_token": "weibo", "token_type": "Bearer"})
示例#5
0
    def test_fetch_access_token(self):
        weibo = OAuth2Session('foo', redirect_uri='https://i.b')
        weibo = weibo_compliance_fix(weibo)

        weibo.post = mock.MagicMock()
        response = requests.Response()
        response.status_code = 200
        response.request = mock.MagicMock()
        response._content = '{"access_token":"weibo"}'.encode('UTF-8')
        weibo.post.return_value = response

        token = weibo.fetch_token(
            'https://mocked.out',
            client_secret='bar',
            authorization_response='https://i.b/?code=hello')
        self.assertEqual(token, {
            'access_token': 'weibo',
            'token_type': 'Bearer'
        })