forked from googleapis/oauth2client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved unit-test line coverage and quality.
In particular - Upgraded some unit test modules to `unittest2`. - Got to 100% line coverage in `test_jwt`, `test_clientsecrets`, and `test_service_account` by using `self.assertRaises` instead of `self.fail()` - In some places used `self.assertRaises` as a context manager so the thrown exception can be inspected / compared against. This is done instead of manually catching the exception and holding on to it (`unittest2` backports this feature from `unittest` that was not available in Python 2.6) - Added license to `test_multistore_file` - Removed legacy `python2.4` hashbang from `test_jwt` and `test_service_account` - Added `unittest2` as a test dependency in `tox.ini` - Updated `test_clientsecrets.test_load_by_filename_missing_file` to use the `self.assertRaises` context manager (this was a problem in googleapis#349 and googleapis#350) - Updated `test_jwt` module docstring to reflect actual purpose
- Loading branch information
Showing
5 changed files
with
57 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
#!/usr/bin/python2.4 | ||
# | ||
# Copyright 2014 Google Inc. All rights reserved. | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -14,15 +12,12 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Oauth2client tests | ||
Unit tests for oauth2client. | ||
""" | ||
"""Unit tests for JWT related methods in oauth2client.""" | ||
|
||
import os | ||
import tempfile | ||
import time | ||
import unittest | ||
import unittest2 | ||
|
||
from .http_mock import HttpMockSequence | ||
from oauth2client.client import Credentials | ||
|
@@ -45,7 +40,7 @@ def datafile(filename): | |
return data | ||
|
||
|
||
class CryptTests(unittest.TestCase): | ||
class CryptTests(unittest2.TestCase): | ||
|
||
def setUp(self): | ||
self.format = 'p12' | ||
|
@@ -83,11 +78,12 @@ def _check_jwt_failure(self, jwt, expected_error): | |
certs = {'foo': public_key} | ||
audience = ('https://www.googleapis.com/auth/id?client_id=' | ||
'[email protected]') | ||
try: | ||
|
||
with self.assertRaises(crypt.AppIdentityError) as exc_manager: | ||
crypt.verify_signed_jwt_with_certs(jwt, certs, audience) | ||
self.fail() | ||
except crypt.AppIdentityError as e: | ||
self.assertTrue(expected_error in str(e)) | ||
|
||
caught_exception = exc_manager.exception | ||
self.assertTrue(expected_error in str(caught_exception)) | ||
|
||
def _create_signed_jwt(self): | ||
private_key = datafile('privatekey.%s' % self.format) | ||
|
@@ -216,7 +212,7 @@ def setUp(self): | |
self.verifier = crypt.OpenSSLVerifier | ||
|
||
|
||
class SignedJwtAssertionCredentialsTests(unittest.TestCase): | ||
class SignedJwtAssertionCredentialsTests(unittest2.TestCase): | ||
|
||
def setUp(self): | ||
self.format = 'p12' | ||
|
@@ -310,7 +306,7 @@ def setUp(self): | |
crypt.Signer = crypt.PyCryptoSigner | ||
|
||
|
||
class PKCSSignedJwtAssertionCredentialsPyCryptoTests(unittest.TestCase): | ||
class PKCSSignedJwtAssertionCredentialsPyCryptoTests(unittest2.TestCase): | ||
|
||
def test_for_failure(self): | ||
crypt.Signer = crypt.PyCryptoSigner | ||
|
@@ -320,19 +316,17 @@ def test_for_failure(self): | |
private_key, | ||
scope='read+write', | ||
sub='[email protected]') | ||
try: | ||
credentials._generate_assertion() | ||
self.fail() | ||
except NotImplementedError: | ||
pass | ||
|
||
self.assertRaises(NotImplementedError, | ||
credentials._generate_assertion) | ||
|
||
|
||
class TestHasOpenSSLFlag(unittest.TestCase): | ||
class TestHasOpenSSLFlag(unittest2.TestCase): | ||
|
||
def test_true(self): | ||
self.assertEqual(True, HAS_OPENSSL) | ||
self.assertEqual(True, HAS_CRYPTO) | ||
|
||
|
||
if __name__ == '__main__': # pragma: NO COVER | ||
unittest.main() | ||
unittest2.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ basedeps = keyring | |
webtest | ||
nose | ||
flask | ||
unittest2 | ||
deps = {[testenv]basedeps} | ||
django | ||
setenv = | ||
|