示例#1
0
    def testGetAuthorizationUrl(self):
        with self.assertRaises(pyfacebook.PyFacebookException):
            api = BaseApi(long_term_token="token")
            api.get_authorization_url()

        api = BaseApi(app_id="appId", app_secret="appSecret", long_term_token="token")

        url, state = api.get_authorization_url()
        self.assertEqual(state, "PyFacebook")
        self.assertTrue(url)
示例#2
0
    def testExchangeAccessToken(self):
        api = BaseApi(app_id="appId", app_secret="appSecret", long_term_token="token")
        _, state = api.get_authorization_url()

        response = "https://localhost/?code=code&state=PyFacebook#_=_"
        with responses.RequestsMock() as m:
            m.add("POST", api.exchange_access_token_url, json=self.LONG_TERM_TOKEN)

            r1 = api.exchange_access_token(response=response, return_json=True)
            self.assertEqual(r1["access_token"], "token")

            r2 = api.exchange_access_token(response=response)
            self.assertEqual(r2.access_token, "token")
            self.assertEqual(r2.token_type, "bearer")