Skip to content

Commit 53ca4e9

Browse files
kraju3Kiran Rajumrashed-dev
authored
Adding optional parameter for token-info endpoint (#256)
Allow token_info parameter to pass in an account_id so the call to GET /accounts doesn't throw 401. This is how the actual endpoint behaves. --------- Co-authored-by: Kiran Raju <[email protected]@Kirans-MacBook-Pro-2.local> Co-authored-by: Mostafa Rashed <[email protected]>
1 parent 5ed1367 commit 53ca4e9

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

nylas/client/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,16 @@ def ip_addresses(self):
289289
_validate(resp).json()
290290
return resp.json()
291291

292-
def token_info(self):
293-
token_info_url = self.token_info_url.format(
294-
client_id=self.client_id, account_id=self.account.id
295-
)
292+
def token_info(self, account_id=None):
293+
token_info_url = ""
294+
if account_id is not None:
295+
token_info_url = self.token_info_url.format(
296+
client_id=self.client_id, account_id=account_id
297+
)
298+
else:
299+
token_info_url = self.token_info_url.format(
300+
client_id=self.client_id, account_id=self.account.id
301+
)
296302
headers = {"Content-Type": "application/json"}
297303
headers.update(self.admin_session.headers)
298304
resp = self.admin_session.post(

tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,9 +1955,7 @@ def mock_ip_addresses(mocked_responses, api_url, client_id):
19551955

19561956
@pytest.fixture
19571957
def mock_token_info(mocked_responses, api_url, account_id, client_id):
1958-
token_info_url = "{base}/a/{client_id}/accounts/{id}/token-info".format(
1959-
base=api_url, id=account_id, client_id=client_id
1960-
)
1958+
token_info_url = re.compile(api_url + "/a/.*/accounts/.*/token-info")
19611959
mocked_responses.add(
19621960
responses.POST,
19631961
token_info_url,

tests/test_accounts.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def test_token_info(api_client_with_client_id):
3838
assert "scopes" in result
3939

4040

41+
@pytest.mark.usefixtures("mock_token_info", "mock_account")
42+
def test_token_info_with_account_id(api_client_with_client_id):
43+
result = api_client_with_client_id.token_info(
44+
account_id="anvkhwelkfdoehdflhdjkfhe1"
45+
)
46+
assert isinstance(result, dict)
47+
assert "updated_at" in result
48+
assert "scopes" in result
49+
50+
4151
@pytest.mark.usefixtures("mock_account")
4252
def test_account_datetime(api_client):
4353
account = api_client.account

0 commit comments

Comments
 (0)