diff options
author | dlorenc <lorenc.d@gmail.com> | 2016-01-19 12:46:48 -0800 |
---|---|---|
committer | dlorenc <dlorenc@google.com> | 2016-01-27 09:51:39 -0800 |
commit | 8df4379bd802e22ff31506bcfe90e177df4192b0 (patch) | |
tree | ab31f0116beec3eafc40546a8a66afc621dc901e /tests/test_client.py | |
parent | 8f8df1f5977ec76d50cb3dca9a31044cfd1fb9b4 (diff) | |
download | oauth2client-8df4379bd802e22ff31506bcfe90e177df4192b0.tar.gz |
Add to/from json methods to Credentials classes
This adds to_json and from_json methods to GoogleCredentials
and _ServiceAccountCredentials classes. This allows them to
be serialized by multistore_file.
Resolves: #384
Diffstat (limited to 'tests/test_client.py')
-rw-r--r-- | tests/test_client.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test_client.py b/tests/test_client.py index ef9d633..131e72e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -618,6 +618,35 @@ class GoogleCredentialsTests(unittest2.TestCase): self.get_a_google_credentials_object().from_stream, credentials_file) + def test_to_from_json_authorized_user(self): + credentials_file = datafile( + os.path.join('gcloud', 'application_default_credentials_authorized_user.json')) + creds = GoogleCredentials.from_stream(credentials_file) + json = creds.to_json() + creds2 = GoogleCredentials.from_json(json) + + self.assertEqual(creds.__dict__, creds2.__dict__) + + def test_to_from_json_service_account(self): + self.maxDiff=None + credentials_file = datafile( + os.path.join('gcloud', _WELL_KNOWN_CREDENTIALS_FILE)) + creds = GoogleCredentials.from_stream(credentials_file) + + json = creds.to_json() + creds2 = GoogleCredentials.from_json(json) + + self.assertEqual(creds.__dict__, creds2.__dict__) + + def test_parse_expiry(self): + dt = datetime.datetime(2016, 1, 1) + parsed_expiry = client._parse_expiry(dt) + self.assertEqual('2016-01-01T00:00:00Z', parsed_expiry) + + def test_bad_expiry(self): + dt = object() + parsed_expiry = client._parse_expiry(dt) + self.assertEqual(None, parsed_expiry) class DummyDeleteStorage(Storage): delete_called = False @@ -774,6 +803,12 @@ class BasicCredentialsTests(unittest2.TestCase): instance = OAuth2Credentials.from_json(json.dumps(data)) self.assertTrue(isinstance(instance, OAuth2Credentials)) + def test_from_json_bad_token_expiry(self): + data = json.loads(self.credentials.to_json()) + data['token_expiry'] = 'foobar' + instance = OAuth2Credentials.from_json(json.dumps(data)) + self.assertTrue(isinstance(instance, OAuth2Credentials)) + def test_unicode_header_checks(self): access_token = u'foo' client_id = u'some_client_id' |