diff options
author | Hiranya Jayathilaka <hiranya911@gmail.com> | 2017-12-05 09:29:59 -0800 |
---|---|---|
committer | Jon Wayne Parrott <jonwayne@google.com> | 2017-12-05 09:29:59 -0800 |
commit | 23c88f755653df352bcff3d49cd077e9944accc6 (patch) | |
tree | 7dc77144d053dc1ecd675530487397425c4e7dea /tests | |
parent | f682cb29ac0dc14e1e1e39d4224e4656ac36f02c (diff) | |
download | google-auth-library-python-23c88f755653df352bcff3d49cd077e9944accc6.tar.gz |
Add google.oauth2.credentials.Credentials.from_authorized_user_file (#226)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/oauth2/test_credentials.py | 49 | ||||
-rw-r--r-- | tests/test__cloud_sdk.py | 3 |
2 files changed, 51 insertions, 1 deletions
diff --git a/tests/oauth2/test_credentials.py b/tests/oauth2/test_credentials.py index 5e09d6f..9064363 100644 --- a/tests/oauth2/test_credentials.py +++ b/tests/oauth2/test_credentials.py @@ -13,6 +13,8 @@ # limitations under the License. import datetime +import json +import os import mock @@ -21,6 +23,14 @@ from google.auth import transport from google.oauth2 import credentials +DATA_DIR = os.path.join(os.path.dirname(__file__), '..', 'data') + +AUTH_USER_JSON_FILE = os.path.join(DATA_DIR, 'authorized_user.json') + +with open(AUTH_USER_JSON_FILE, 'r') as fh: + AUTH_USER_INFO = json.load(fh) + + class TestCredentials(object): TOKEN_URI = 'https://example.com/oauth2/token' REFRESH_TOKEN = 'refresh_token' @@ -84,3 +94,42 @@ class TestCredentials(object): # Check that the credentials are valid (have a token and are not # expired) assert credentials.valid + + def test_from_authorized_user_info(self): + info = AUTH_USER_INFO.copy() + + creds = credentials.Credentials.from_authorized_user_info(info) + assert creds.client_secret == info['client_secret'] + assert creds.client_id == info['client_id'] + assert creds.refresh_token == info['refresh_token'] + assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT + assert creds.scopes is None + + scopes = ['email', 'profile'] + creds = credentials.Credentials.from_authorized_user_info( + info, scopes) + assert creds.client_secret == info['client_secret'] + assert creds.client_id == info['client_id'] + assert creds.refresh_token == info['refresh_token'] + assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT + assert creds.scopes == scopes + + def test_from_authorized_user_file(self): + info = AUTH_USER_INFO.copy() + + creds = credentials.Credentials.from_authorized_user_file( + AUTH_USER_JSON_FILE) + assert creds.client_secret == info['client_secret'] + assert creds.client_id == info['client_id'] + assert creds.refresh_token == info['refresh_token'] + assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT + assert creds.scopes is None + + scopes = ['email', 'profile'] + creds = credentials.Credentials.from_authorized_user_file( + AUTH_USER_JSON_FILE, scopes) + assert creds.client_secret == info['client_secret'] + assert creds.client_id == info['client_id'] + assert creds.refresh_token == info['refresh_token'] + assert creds.token_uri == credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT + assert creds.scopes == scopes diff --git a/tests/test__cloud_sdk.py b/tests/test__cloud_sdk.py index c14fc20..58c7270 100644 --- a/tests/test__cloud_sdk.py +++ b/tests/test__cloud_sdk.py @@ -145,7 +145,8 @@ def test_load_authorized_user_credentials(): assert credentials._client_id == AUTHORIZED_USER_FILE_DATA['client_id'] assert (credentials._client_secret == AUTHORIZED_USER_FILE_DATA['client_secret']) - assert credentials._token_uri == _cloud_sdk._GOOGLE_OAUTH2_TOKEN_ENDPOINT + assert (credentials._token_uri == + google.oauth2.credentials._GOOGLE_OAUTH2_TOKEN_ENDPOINT) def test_load_authorized_user_credentials_bad_format(): |