From 3bd019f4d95f304c6218e2de8a1023d02bd77f89 Mon Sep 17 00:00:00 2001 From: Pat Ferate Date: Tue, 5 Jul 2016 12:05:02 -0700 Subject: [PATCH] Update unittest to unittest2 Using unittest2 for extended unit test capabilities in python 2.6. --- scripts/run_gce_system_tests.py | 6 +++--- tests/contrib/test_devshell.py | 10 +++++----- tests/contrib/test_django_orm.py | 10 +++++----- tests/contrib/test_django_util.py | 4 ++-- tests/contrib/test_keyring_storage.py | 6 +++--- tests/contrib/test_xsrfutil.py | 10 +++++----- tests/test__helpers.py | 16 ++++++++-------- tests/test_crypt.py | 16 ++++++++-------- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/scripts/run_gce_system_tests.py b/scripts/run_gce_system_tests.py index aae8345a4..40c105ecd 100644 --- a/scripts/run_gce_system_tests.py +++ b/scripts/run_gce_system_tests.py @@ -13,7 +13,7 @@ # limitations under the License. import json -import unittest +import unittest2 import httplib2 from six.moves import http_client @@ -24,7 +24,7 @@ from oauth2client.contrib.gce import AppAssertionCredentials -class TestComputeEngine(unittest.TestCase): +class TestComputeEngine(unittest2.TestCase): def test_application_default(self): default_creds = GoogleCredentials.get_application_default() @@ -53,4 +53,4 @@ def test_token_info(self): if __name__ == '__main__': - unittest.main() + unittest2.main() diff --git a/tests/contrib/test_devshell.py b/tests/contrib/test_devshell.py index 0a04c1c86..b9b2496fb 100644 --- a/tests/contrib/test_devshell.py +++ b/tests/contrib/test_devshell.py @@ -19,7 +19,7 @@ import os import socket import threading -import unittest +import unittest2 import mock @@ -46,7 +46,7 @@ ]) -class TestCredentialInfoResponse(unittest.TestCase): +class TestCredentialInfoResponse(unittest2.TestCase): def test_constructor_with_non_list(self): json_non_list = '{}' @@ -79,7 +79,7 @@ def test_constructor_full_list(self): self.assertEqual(info_response.expires_in, expires_in) -class Test_SendRecv(unittest.TestCase): +class Test_SendRecv(unittest2.TestCase): def test_port_zero(self): with mock.patch('oauth2client.contrib.devshell.os') as os_mod: @@ -174,7 +174,7 @@ def run(self): s.close() -class DevshellCredentialsTests(unittest.TestCase): +class DevshellCredentialsTests(unittest2.TestCase): def test_signals_no_server(self): with self.assertRaises(NoDevshellServer): @@ -273,4 +273,4 @@ def test_serialization_data(self): if __name__ == '__main__': # pragma: NO COVER - unittest.main() + unittest2.main() diff --git a/tests/contrib/test_django_orm.py b/tests/contrib/test_django_orm.py index e15db08ed..57a9d6bb9 100644 --- a/tests/contrib/test_django_orm.py +++ b/tests/contrib/test_django_orm.py @@ -23,7 +23,7 @@ import os import pickle import sys -import unittest +import unittest2 # Mock a Django environment from django.conf import global_settings @@ -60,7 +60,7 @@ class DjangoOrmTestApp(AppConfig): __author__ = 'conleyo@google.com (Conley Owens)' -class TestCredentialsField(unittest.TestCase): +class TestCredentialsField(unittest2.TestCase): def setUp(self): self.fake_model = FakeCredentialsModel() @@ -112,7 +112,7 @@ def test_credentials_without_null(self): self.assertTrue(credentials.null) -class TestFlowField(unittest.TestCase): +class TestFlowField(unittest2.TestCase): class FakeFlowModel(models.Model): flow = FlowField() @@ -163,7 +163,7 @@ def test_flow_with_null(self): self.assertTrue(flow.null) -class TestStorage(unittest.TestCase): +class TestStorage(unittest2.TestCase): def setUp(self): access_token = 'foo' @@ -320,4 +320,4 @@ def __init__(self, set_store=False, *args, **kwargs): if __name__ == '__main__': # pragma: NO COVER - unittest.main() + unittest2.main() diff --git a/tests/contrib/test_django_util.py b/tests/contrib/test_django_util.py index a9231c6ed..18eab3017 100644 --- a/tests/contrib/test_django_util.py +++ b/tests/contrib/test_django_util.py @@ -13,7 +13,7 @@ # limitations under the License. import json -import unittest +import unittest2 from django.conf.urls import include, url from django.core import exceptions @@ -37,7 +37,7 @@ urlpatterns += [url(r'^oauth2/', include(site.urls))] -class OAuth2SetupTest(unittest.TestCase): +class OAuth2SetupTest(unittest2.TestCase): @mock.patch("oauth2client.contrib.django_util.clientsecrets") def test_settings_initialize(self, clientsecrets): diff --git a/tests/contrib/test_keyring_storage.py b/tests/contrib/test_keyring_storage.py index 500acad9d..d30ea87dd 100644 --- a/tests/contrib/test_keyring_storage.py +++ b/tests/contrib/test_keyring_storage.py @@ -17,7 +17,7 @@ import datetime import keyring import threading -import unittest +import unittest2 import mock @@ -29,7 +29,7 @@ __author__ = 'jcgregorio@google.com (Joe Gregorio)' -class KeyringStorageTests(unittest.TestCase): +class KeyringStorageTests(unittest2.TestCase): def test_constructor(self): service_name = 'my_unit_test' @@ -172,4 +172,4 @@ def release(self): if __name__ == '__main__': # pragma: NO COVER - unittest.main() + unittest2.main() diff --git a/tests/contrib/test_xsrfutil.py b/tests/contrib/test_xsrfutil.py index 9403ffecf..0f66edf2e 100644 --- a/tests/contrib/test_xsrfutil.py +++ b/tests/contrib/test_xsrfutil.py @@ -15,7 +15,7 @@ """Tests for oauth2client.contrib.xsrfutil.""" import base64 -import unittest +import unittest2 import mock @@ -37,7 +37,7 @@ __author__ = 'jcgregorio@google.com (Joe Gregorio)' -class Test_generate_token(unittest.TestCase): +class Test_generate_token(unittest2.TestCase): def test_bad_positional(self): # Need 2 positional arguments. @@ -111,7 +111,7 @@ def test_with_system_time(self): self.assertEqual(token, expected_token) -class Test_validate_token(unittest.TestCase): +class Test_validate_token(unittest2.TestCase): def test_bad_positional(self): # Need 3 positional arguments. @@ -218,7 +218,7 @@ def test_success(self): when=token_time) -class XsrfUtilTests(unittest.TestCase): +class XsrfUtilTests(unittest2.TestCase): """Test xsrfutil functions.""" def testGenerateAndValidateToken(self): @@ -294,4 +294,4 @@ def testGenerateAndValidateToken(self): if __name__ == '__main__': # pragma: NO COVER - unittest.main() + unittest2.main() diff --git a/tests/test__helpers.py b/tests/test__helpers.py index e316f9ac6..581b32eeb 100644 --- a/tests/test__helpers.py +++ b/tests/test__helpers.py @@ -13,7 +13,7 @@ # limitations under the License. """Unit tests for oauth2client._helpers.""" -import unittest +import unittest2 from oauth2client._helpers import _from_bytes from oauth2client._helpers import _json_encode @@ -23,7 +23,7 @@ from oauth2client._helpers import _urlsafe_b64encode -class Test__parse_pem_key(unittest.TestCase): +class Test__parse_pem_key(unittest2.TestCase): def test_valid_input(self): test_string = b'1234-----BEGIN FOO BAR BAZ' @@ -36,7 +36,7 @@ def test_bad_input(self): self.assertEqual(result, None) -class Test__json_encode(unittest.TestCase): +class Test__json_encode(unittest2.TestCase): def test_dictionary_input(self): # Use only a single key since dictionary hash order @@ -51,7 +51,7 @@ def test_list_input(self): self.assertEqual(result, '[42,1337]') -class Test__to_bytes(unittest.TestCase): +class Test__to_bytes(unittest2.TestCase): def test_with_bytes(self): value = b'bytes-val' @@ -68,7 +68,7 @@ def test_with_nonstring_type(self): _to_bytes(value) -class Test__from_bytes(unittest.TestCase): +class Test__from_bytes(unittest2.TestCase): def test_with_unicode(self): value = u'bytes-val' @@ -85,7 +85,7 @@ def test_with_nonstring_type(self): _from_bytes(value) -class Test__urlsafe_b64encode(unittest.TestCase): +class Test__urlsafe_b64encode(unittest2.TestCase): DEADBEEF_ENCODED = b'ZGVhZGJlZWY' @@ -100,7 +100,7 @@ def test_valid_input_unicode(self): self.assertEqual(result, self.DEADBEEF_ENCODED) -class Test__urlsafe_b64decode(unittest.TestCase): +class Test__urlsafe_b64decode(unittest2.TestCase): def test_valid_input_bytes(self): test_string = b'ZGVhZGJlZWY' @@ -120,4 +120,4 @@ def test_bad_input(self): if __name__ == '__main__': # pragma: NO COVER - unittest.main() + unittest2.main() diff --git a/tests/test_crypt.py b/tests/test_crypt.py index 085b5e339..d7dcc4fe3 100644 --- a/tests/test_crypt.py +++ b/tests/test_crypt.py @@ -14,7 +14,7 @@ import base64 import os -import unittest +import unittest2 import mock @@ -33,14 +33,14 @@ def datafile(filename): return file_obj.read() -class Test__bad_pkcs12_key_as_pem(unittest.TestCase): +class Test__bad_pkcs12_key_as_pem(unittest2.TestCase): def test_fails(self): with self.assertRaises(NotImplementedError): crypt._bad_pkcs12_key_as_pem() -class Test_pkcs12_key_as_pem(unittest.TestCase): +class Test_pkcs12_key_as_pem(unittest2.TestCase): def _make_svc_account_creds(self, private_key_file='privatekey.p12'): filename = data_filename(private_key_file) @@ -72,7 +72,7 @@ def test_succeeds_with_unicode_password(self): self._succeeds_helper(password) -class Test__verify_signature(unittest.TestCase): +class Test__verify_signature(unittest2.TestCase): def test_success_single_cert(self): cert_value = 'cert-value' @@ -144,7 +144,7 @@ def test_failure(self): verifier.verify.assert_called_once_with(message, signature) -class Test__check_audience(unittest.TestCase): +class Test__check_audience(unittest2.TestCase): def test_null_audience(self): result = crypt._check_audience(None, None) @@ -171,7 +171,7 @@ def test_wrong_aud(self): with self.assertRaises(crypt.AppIdentityError): crypt._check_audience(payload_dict, audience2) -class Test__verify_time_range(unittest.TestCase): +class Test__verify_time_range(unittest2.TestCase): def _exception_helper(self, payload_dict): exception_caught = None @@ -255,7 +255,7 @@ def test_success(self): self.assertEqual(exception_caught, None) -class Test_verify_signed_jwt_with_certs(unittest.TestCase): +class Test_verify_signed_jwt_with_certs(unittest2.TestCase): def test_jwt_no_segments(self): exception_caught = None @@ -313,4 +313,4 @@ def test_success(self, verify_sig, verify_time, check_aud): if __name__ == '__main__': # pragma: NO COVER - unittest.main() + unittest2.main()