Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Update unittest to unittest2
Browse files Browse the repository at this point in the history
Using unittest2 for extended unit test capabilities in python 2.6.
  • Loading branch information
pferate committed Jul 5, 2016
1 parent 617f441 commit 3bd019f
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions scripts/run_gce_system_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import json
import unittest
import unittest2

import httplib2
from six.moves import http_client
Expand All @@ -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()
Expand Down Expand Up @@ -53,4 +53,4 @@ def test_token_info(self):


if __name__ == '__main__':
unittest.main()
unittest2.main()
10 changes: 5 additions & 5 deletions tests/contrib/test_devshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import os
import socket
import threading
import unittest
import unittest2

import mock

Expand All @@ -46,7 +46,7 @@
])


class TestCredentialInfoResponse(unittest.TestCase):
class TestCredentialInfoResponse(unittest2.TestCase):

def test_constructor_with_non_list(self):
json_non_list = '{}'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -273,4 +273,4 @@ def test_serialization_data(self):


if __name__ == '__main__': # pragma: NO COVER
unittest.main()
unittest2.main()
10 changes: 5 additions & 5 deletions tests/contrib/test_django_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import os
import pickle
import sys
import unittest
import unittest2
# Mock a Django environment
from django.conf import global_settings

Expand Down Expand Up @@ -60,7 +60,7 @@ class DjangoOrmTestApp(AppConfig):
__author__ = '[email protected] (Conley Owens)'


class TestCredentialsField(unittest.TestCase):
class TestCredentialsField(unittest2.TestCase):

def setUp(self):
self.fake_model = FakeCredentialsModel()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -320,4 +320,4 @@ def __init__(self, set_store=False, *args, **kwargs):


if __name__ == '__main__': # pragma: NO COVER
unittest.main()
unittest2.main()
4 changes: 2 additions & 2 deletions tests/contrib/test_django_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tests/contrib/test_keyring_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import datetime
import keyring
import threading
import unittest
import unittest2

import mock

Expand All @@ -29,7 +29,7 @@
__author__ = '[email protected] (Joe Gregorio)'


class KeyringStorageTests(unittest.TestCase):
class KeyringStorageTests(unittest2.TestCase):

def test_constructor(self):
service_name = 'my_unit_test'
Expand Down Expand Up @@ -172,4 +172,4 @@ def release(self):


if __name__ == '__main__': # pragma: NO COVER
unittest.main()
unittest2.main()
10 changes: 5 additions & 5 deletions tests/contrib/test_xsrfutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Tests for oauth2client.contrib.xsrfutil."""

import base64
import unittest
import unittest2

import mock

Expand All @@ -37,7 +37,7 @@
__author__ = '[email protected] (Joe Gregorio)'


class Test_generate_token(unittest.TestCase):
class Test_generate_token(unittest2.TestCase):

def test_bad_positional(self):
# Need 2 positional arguments.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -294,4 +294,4 @@ def testGenerateAndValidateToken(self):


if __name__ == '__main__': # pragma: NO COVER
unittest.main()
unittest2.main()
16 changes: 8 additions & 8 deletions tests/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -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'

Expand All @@ -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'
Expand All @@ -120,4 +120,4 @@ def test_bad_input(self):


if __name__ == '__main__': # pragma: NO COVER
unittest.main()
unittest2.main()
16 changes: 8 additions & 8 deletions tests/test_crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import base64
import os
import unittest
import unittest2

import mock

Expand All @@ -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)
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -313,4 +313,4 @@ def test_success(self, verify_sig, verify_time, check_aud):


if __name__ == '__main__': # pragma: NO COVER
unittest.main()
unittest2.main()

0 comments on commit 3bd019f

Please sign in to comment.