Skip to content

Commit

Permalink
fix to incorrect error message when wrong refresh token is passed in
Browse files Browse the repository at this point in the history
  • Loading branch information
senseiseun committed Nov 20, 2023
1 parent 929027c commit 6c8c218
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pinterest/utils/refresh_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def get_new_access_token(
body="Authentication error. " +
"Kindly check if the following variables are correct: [PINTEREST_ACCESS_TOKEN] or " +
"[PINTEREST_APP_ID, PINTEREST_APP_SECRET, PINTEREST_REFRESH_ACCESS_TOKEN]. " +
f"Response from server: {response.body}"
f"Response from server: {response.data}",
http_resp=response
)
if response.status != 200:
raise SdkException(http_resp=response)
Expand Down
35 changes: 35 additions & 0 deletions tests/src/pinterest/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,38 @@ def test_set_default_refresh_token(self, load_dotenv_mock):
self.assertEqual(refresh_token, PINTEREST_REFRESH_ACCESS_TOKEN)
self.assertEqual(app_id, PINTEREST_APP_ID)
self.assertEqual(app_secret, PINTEREST_APP_SECRET)

@mock.patch.dict(
os.environ,
{
"PINTEREST_APP_ID": "test_app_id",
"PINTEREST_APP_SECRET": "test_app_secret",
},
clear=True
)
@patch('dotenv.load_dotenv')
def test_set_bad_refresh_token(self, load_dotenv_mock):
load_dotenv_mock.return_value = None
refresh_token = 'refresh_token'
app_id = '12345'
app_secret = '123456asdfg'

from pinterest.config import PINTEREST_REFRESH_ACCESS_TOKEN
from pinterest.config import PINTEREST_APP_ID
from pinterest.config import PINTEREST_APP_SECRET
self.assertNotEqual(refresh_token, PINTEREST_REFRESH_ACCESS_TOKEN)
self.assertNotEqual(app_id, PINTEREST_APP_ID)
self.assertNotEqual(app_secret, PINTEREST_APP_SECRET)

PinterestSDKClient._get_access_token(
refresh_token=refresh_token,
app_id=app_id,
app_secret=app_secret
)

from pinterest.config import PINTEREST_REFRESH_ACCESS_TOKEN
from pinterest.config import PINTEREST_APP_ID
from pinterest.config import PINTEREST_APP_SECRET
self.assertEqual(refresh_token, PINTEREST_REFRESH_ACCESS_TOKEN)
self.assertEqual(app_id, PINTEREST_APP_ID)
self.assertEqual(app_secret, PINTEREST_APP_SECRET)

0 comments on commit 6c8c218

Please sign in to comment.