Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to incorrect error message when wrong refresh token is passed in #123

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions integration_tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pinterest.organic.boards import Board
from pinterest.client import PinterestSDKClient
from integration_tests.base_test import BaseTestCase
from pinterest.utils.error_handling import SdkException


class ClientTest(BaseTestCase):
Expand Down Expand Up @@ -56,6 +57,18 @@ def test_good_setup_default_access_token(self):
PinterestSDKClient.set_default_access_token(access_token=good_access_token)
self.assertIsNotNone(Board.get_all())

def test_bad_refresh_token(self):
refresh_token = 'refresh_token'
app_id = '12345'
app_secret = '123456asdfg'
with self.assertRaises(SdkException):
PinterestSDKClient._get_access_token(
refresh_token=refresh_token,
app_id=app_id,
app_secret=app_secret
)





Expand Down
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
30 changes: 30 additions & 0 deletions tests/src/pinterest/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest.mock import patch
import unittest
import subprocess
from pinterest.utils.sdk_exceptions import SdkException

from pinterest.client import PinterestSDKClient

Expand Down Expand Up @@ -52,3 +53,32 @@ 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)
with self.assertRaises(SdkException):
PinterestSDKClient._get_access_token(
refresh_token=refresh_token,
app_id=app_id,
app_secret=app_secret
)

Loading