Clean up imports (#625)
* Treat `tests` as part of the local package * Import modules instead of objects Some imports that slipped by last time this was cleaned up.
This commit is contained in:
parent
e4ad1beeb4
commit
c6b30bf420
|
@ -38,7 +38,7 @@ import oauth2client
|
|||
from oauth2client import client
|
||||
from oauth2client import clientsecrets
|
||||
from oauth2client.contrib import appengine
|
||||
from ... import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||
|
||||
|
|
|
@ -18,18 +18,18 @@ import copy
|
|||
|
||||
from django import http
|
||||
import django.conf
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
from django.contrib.auth import models as django_models
|
||||
import mock
|
||||
from six.moves import http_client
|
||||
from six.moves import reload_module
|
||||
from six.moves.urllib import parse
|
||||
from tests.contrib.django_util import TestWithDjangoEnvironment
|
||||
|
||||
import oauth2client.contrib.django_util
|
||||
from oauth2client.contrib.django_util import decorators
|
||||
from tests.contrib import django_util as tests_django_util
|
||||
|
||||
|
||||
class OAuth2EnabledDecoratorTest(TestWithDjangoEnvironment):
|
||||
class OAuth2EnabledDecoratorTest(tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(OAuth2EnabledDecoratorTest, self).setUp()
|
||||
|
@ -39,7 +39,7 @@ class OAuth2EnabledDecoratorTest(TestWithDjangoEnvironment):
|
|||
# at import time, so in order for us to reload the settings
|
||||
# we need to reload the module
|
||||
reload_module(oauth2client.contrib.django_util)
|
||||
self.user = User.objects.create_user(
|
||||
self.user = django_models.User.objects.create_user(
|
||||
username='bill', email='bill@example.com', password='hunter2')
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -106,14 +106,14 @@ class OAuth2EnabledDecoratorTest(TestWithDjangoEnvironment):
|
|||
self.assertFalse(request.oauth.has_credentials())
|
||||
|
||||
|
||||
class OAuth2RequiredDecoratorTest(TestWithDjangoEnvironment):
|
||||
class OAuth2RequiredDecoratorTest(tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(OAuth2RequiredDecoratorTest, self).setUp()
|
||||
self.save_settings = copy.deepcopy(django.conf.settings)
|
||||
|
||||
reload_module(oauth2client.contrib.django_util)
|
||||
self.user = User.objects.create_user(
|
||||
self.user = django_models.User.objects.create_user(
|
||||
username='bill', email='bill@example.com', password='hunter2')
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -195,7 +195,8 @@ class OAuth2RequiredDecoratorTest(TestWithDjangoEnvironment):
|
|||
response.status_code, django.http.HttpResponseRedirect.status_code)
|
||||
|
||||
|
||||
class OAuth2RequiredDecoratorStorageModelTest(TestWithDjangoEnvironment):
|
||||
class OAuth2RequiredDecoratorStorageModelTest(
|
||||
tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(OAuth2RequiredDecoratorStorageModelTest, self).setUp()
|
||||
|
@ -209,7 +210,7 @@ class OAuth2RequiredDecoratorStorageModelTest(TestWithDjangoEnvironment):
|
|||
django.conf.settings.GOOGLE_OAUTH2_STORAGE_MODEL = STORAGE_MODEL
|
||||
|
||||
reload_module(oauth2client.contrib.django_util)
|
||||
self.user = User.objects.create_user(
|
||||
self.user = django_models.User.objects.create_user(
|
||||
username='bill', email='bill@example.com', password='hunter2')
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -219,7 +220,7 @@ class OAuth2RequiredDecoratorStorageModelTest(TestWithDjangoEnvironment):
|
|||
def test_redirects_anonymous_to_login(self):
|
||||
request = self.factory.get('/test')
|
||||
request.session = self.session
|
||||
request.user = AnonymousUser()
|
||||
request.user = django_models.AnonymousUser()
|
||||
|
||||
@decorators.oauth_required
|
||||
def test_view(request):
|
||||
|
@ -233,7 +234,7 @@ class OAuth2RequiredDecoratorStorageModelTest(TestWithDjangoEnvironment):
|
|||
def test_redirects_user_to_oauth_authorize(self):
|
||||
request = self.factory.get('/test')
|
||||
request.session = self.session
|
||||
request.user = User.objects.create_user(
|
||||
request.user = django_models.User.objects.create_user(
|
||||
username='bill3', email='bill@example.com', password='hunter2')
|
||||
|
||||
@decorators.oauth_required
|
||||
|
|
|
@ -21,20 +21,19 @@ import base64
|
|||
import pickle
|
||||
import unittest
|
||||
|
||||
from tests.contrib.django_util.models import CredentialsModel
|
||||
|
||||
from oauth2client import _helpers
|
||||
from oauth2client.client import Credentials
|
||||
from oauth2client.contrib.django_util.models import CredentialsField
|
||||
from oauth2client import client
|
||||
from oauth2client.contrib.django_util import models
|
||||
from tests.contrib.django_util import models as tests_models
|
||||
|
||||
|
||||
class TestCredentialsField(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.fake_model = CredentialsModel()
|
||||
self.fake_model = tests_models.CredentialsModel()
|
||||
self.fake_model_field = self.fake_model._meta.get_field('credentials')
|
||||
self.field = CredentialsField(null=True)
|
||||
self.credentials = Credentials()
|
||||
self.field = models.CredentialsField(null=True)
|
||||
self.credentials = client.Credentials()
|
||||
self.pickle_str = _helpers._from_bytes(
|
||||
base64.b64encode(pickle.dumps(self.credentials)))
|
||||
|
||||
|
@ -43,11 +42,11 @@ class TestCredentialsField(unittest.TestCase):
|
|||
|
||||
def test_field_unpickled(self):
|
||||
self.assertIsInstance(
|
||||
self.field.to_python(self.pickle_str), Credentials)
|
||||
self.field.to_python(self.pickle_str), client.Credentials)
|
||||
|
||||
def test_field_already_unpickled(self):
|
||||
self.assertIsInstance(
|
||||
self.field.to_python(self.credentials), Credentials)
|
||||
self.field.to_python(self.credentials), client.Credentials)
|
||||
|
||||
def test_none_field_unpickled(self):
|
||||
self.assertIsNone(self.field.to_python(None))
|
||||
|
@ -55,7 +54,7 @@ class TestCredentialsField(unittest.TestCase):
|
|||
def test_from_db_value(self):
|
||||
value = self.field.from_db_value(
|
||||
self.pickle_str, None, None, None)
|
||||
self.assertIsInstance(value, Credentials)
|
||||
self.assertIsInstance(value, client.Credentials)
|
||||
|
||||
def test_field_unpickled_none(self):
|
||||
self.assertEqual(self.field.to_python(None), None)
|
||||
|
@ -76,11 +75,11 @@ class TestCredentialsField(unittest.TestCase):
|
|||
self.assertIsNone(value_str)
|
||||
|
||||
def test_credentials_without_null(self):
|
||||
credentials = CredentialsField()
|
||||
credentials = models.CredentialsField()
|
||||
self.assertTrue(credentials.null)
|
||||
|
||||
|
||||
class CredentialWithSetStore(CredentialsField):
|
||||
class CredentialWithSetStore(models.CredentialsField):
|
||||
def __init__(self):
|
||||
self.model = CredentialWithSetStore
|
||||
|
||||
|
@ -95,4 +94,4 @@ class FakeCredentialsModelMock(object):
|
|||
|
||||
class FakeCredentialsModelMockNoSet(object):
|
||||
|
||||
credentials = CredentialsField()
|
||||
credentials = models.CredentialsField()
|
||||
|
|
|
@ -19,16 +19,15 @@ import unittest
|
|||
|
||||
import django.conf
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.auth import models as django_models
|
||||
from django.core import exceptions
|
||||
import mock
|
||||
from six.moves import reload_module
|
||||
from tests.contrib.django_util import TestWithDjangoEnvironment
|
||||
|
||||
from oauth2client.contrib import django_util
|
||||
import oauth2client.contrib.django_util
|
||||
from oauth2client.contrib.django_util import (
|
||||
_CREDENTIALS_KEY, get_storage, site, UserOAuth2)
|
||||
from oauth2client.contrib.django_util import site
|
||||
from tests.contrib import django_util as tests_django_util
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
|
@ -135,7 +134,7 @@ class MockObjectWithSession(object):
|
|||
self.session = session
|
||||
|
||||
|
||||
class SessionStorageTest(TestWithDjangoEnvironment):
|
||||
class SessionStorageTest(tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(SessionStorageTest, self).setUp()
|
||||
|
@ -147,19 +146,19 @@ class SessionStorageTest(TestWithDjangoEnvironment):
|
|||
django.conf.settings = copy.deepcopy(self.save_settings)
|
||||
|
||||
def test_session_delete(self):
|
||||
self.session[_CREDENTIALS_KEY] = "test_val"
|
||||
self.session[django_util._CREDENTIALS_KEY] = "test_val"
|
||||
request = MockObjectWithSession(self.session)
|
||||
django_storage = get_storage(request)
|
||||
django_storage = django_util.get_storage(request)
|
||||
django_storage.delete()
|
||||
self.assertIsNone(self.session.get(_CREDENTIALS_KEY))
|
||||
self.assertIsNone(self.session.get(django_util._CREDENTIALS_KEY))
|
||||
|
||||
def test_session_delete_nothing(self):
|
||||
request = MockObjectWithSession(self.session)
|
||||
django_storage = get_storage(request)
|
||||
django_storage = django_util.get_storage(request)
|
||||
django_storage.delete()
|
||||
|
||||
|
||||
class TestUserOAuth2Object(TestWithDjangoEnvironment):
|
||||
class TestUserOAuth2Object(tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(TestUserOAuth2Object, self).setUp()
|
||||
|
@ -181,6 +180,6 @@ class TestUserOAuth2Object(TestWithDjangoEnvironment):
|
|||
request = self.factory.get('oauth2/oauth2authorize',
|
||||
data={'return_url': '/return_endpoint'})
|
||||
request.session = self.session
|
||||
request.user = AnonymousUser()
|
||||
oauth2 = UserOAuth2(request)
|
||||
request.user = django_models.AnonymousUser()
|
||||
oauth2 = django_util.UserOAuth2(request)
|
||||
self.assertIsNone(oauth2.credentials)
|
||||
|
|
|
@ -20,27 +20,26 @@ import json
|
|||
import django
|
||||
from django import http
|
||||
import django.conf
|
||||
from django.contrib.auth.models import AnonymousUser, User
|
||||
from django.contrib.auth import models as django_models
|
||||
import mock
|
||||
from six.moves import reload_module
|
||||
|
||||
from tests.contrib.django_util import TestWithDjangoEnvironment
|
||||
from tests.contrib.django_util.models import CredentialsModel
|
||||
|
||||
from oauth2client.client import FlowExchangeError, OAuth2WebServerFlow
|
||||
from oauth2client import client
|
||||
import oauth2client.contrib.django_util
|
||||
from oauth2client.contrib.django_util import views
|
||||
from oauth2client.contrib.django_util.models import CredentialsField
|
||||
from oauth2client.contrib.django_util import models
|
||||
from tests.contrib import django_util as tests_django_util
|
||||
from tests.contrib.django_util import models as tests_models
|
||||
|
||||
|
||||
class OAuth2AuthorizeTest(TestWithDjangoEnvironment):
|
||||
class OAuth2AuthorizeTest(tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(OAuth2AuthorizeTest, self).setUp()
|
||||
self.save_settings = copy.deepcopy(django.conf.settings)
|
||||
reload_module(oauth2client.contrib.django_util)
|
||||
self.user = User.objects.create_user(
|
||||
username='bill', email='bill@example.com', password='hunter2')
|
||||
self.user = django_models.User.objects.create_user(
|
||||
username='bill', email='bill@example.com', password='hunter2')
|
||||
|
||||
def tearDown(self):
|
||||
django.conf.settings = copy.deepcopy(self.save_settings)
|
||||
|
@ -55,7 +54,7 @@ class OAuth2AuthorizeTest(TestWithDjangoEnvironment):
|
|||
def test_authorize_anonymous_user(self):
|
||||
request = self.factory.get('oauth2/oauth2authorize')
|
||||
request.session = self.session
|
||||
request.user = AnonymousUser()
|
||||
request.user = django_models.AnonymousUser()
|
||||
response = views.oauth2_authorize(request)
|
||||
self.assertIsInstance(response, http.HttpResponseRedirect)
|
||||
|
||||
|
@ -68,7 +67,8 @@ class OAuth2AuthorizeTest(TestWithDjangoEnvironment):
|
|||
self.assertIsInstance(response, http.HttpResponseRedirect)
|
||||
|
||||
|
||||
class Oauth2AuthorizeStorageModelTest(TestWithDjangoEnvironment):
|
||||
class Oauth2AuthorizeStorageModelTest(
|
||||
tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(Oauth2AuthorizeStorageModelTest, self).setUp()
|
||||
|
@ -85,7 +85,7 @@ class Oauth2AuthorizeStorageModelTest(TestWithDjangoEnvironment):
|
|||
# at import time, so in order for us to reload the settings
|
||||
# we need to reload the module
|
||||
reload_module(oauth2client.contrib.django_util)
|
||||
self.user = User.objects.create_user(
|
||||
self.user = django_models.User.objects.create_user(
|
||||
username='bill', email='bill@example.com', password='hunter2')
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -103,7 +103,7 @@ class Oauth2AuthorizeStorageModelTest(TestWithDjangoEnvironment):
|
|||
def test_authorize_anonymous_user_redirects_login(self):
|
||||
request = self.factory.get('oauth2/oauth2authorize')
|
||||
request.session = self.session
|
||||
request.user = AnonymousUser()
|
||||
request.user = django_models.AnonymousUser()
|
||||
response = views.oauth2_authorize(request)
|
||||
self.assertIsInstance(response, http.HttpResponseRedirect)
|
||||
# redirects to Django login
|
||||
|
@ -122,11 +122,11 @@ class Oauth2AuthorizeStorageModelTest(TestWithDjangoEnvironment):
|
|||
data={'return_url': '/return_endpoint'})
|
||||
request.session = self.session
|
||||
|
||||
authorized_user = User.objects.create_user(
|
||||
authorized_user = django_models.User.objects.create_user(
|
||||
username='bill2', email='bill@example.com', password='hunter2')
|
||||
credentials = CredentialsField()
|
||||
credentials = models.CredentialsField()
|
||||
|
||||
CredentialsModel.objects.create(
|
||||
tests_models.CredentialsModel.objects.create(
|
||||
user_id=authorized_user,
|
||||
credentials=credentials)
|
||||
|
||||
|
@ -135,7 +135,7 @@ class Oauth2AuthorizeStorageModelTest(TestWithDjangoEnvironment):
|
|||
self.assertIsInstance(response, http.HttpResponseRedirect)
|
||||
|
||||
|
||||
class Oauth2CallbackTest(TestWithDjangoEnvironment):
|
||||
class Oauth2CallbackTest(tests_django_util.TestWithDjangoEnvironment):
|
||||
|
||||
def setUp(self):
|
||||
super(Oauth2CallbackTest, self).setUp()
|
||||
|
@ -149,7 +149,7 @@ class Oauth2CallbackTest(TestWithDjangoEnvironment):
|
|||
'return_url': self.RETURN_URL,
|
||||
'scopes': django.conf.settings.GOOGLE_OAUTH2_SCOPES
|
||||
}
|
||||
self.user = User.objects.create_user(
|
||||
self.user = django_models.User.objects.create_user(
|
||||
username='bill', email='bill@example.com', password='hunter2')
|
||||
|
||||
@mock.patch('oauth2client.contrib.django_util.views.pickle')
|
||||
|
@ -161,7 +161,7 @@ class Oauth2CallbackTest(TestWithDjangoEnvironment):
|
|||
|
||||
self.session['google_oauth2_csrf_token'] = self.CSRF_TOKEN
|
||||
|
||||
flow = OAuth2WebServerFlow(
|
||||
flow = client.OAuth2WebServerFlow(
|
||||
client_id='clientid',
|
||||
client_secret='clientsecret',
|
||||
scope=['email'],
|
||||
|
@ -190,7 +190,7 @@ class Oauth2CallbackTest(TestWithDjangoEnvironment):
|
|||
|
||||
self.session['google_oauth2_csrf_token'] = self.CSRF_TOKEN
|
||||
|
||||
flow = OAuth2WebServerFlow(
|
||||
flow = client.OAuth2WebServerFlow(
|
||||
client_id='clientid',
|
||||
client_secret='clientsecret',
|
||||
scope=['email'],
|
||||
|
@ -201,7 +201,7 @@ class Oauth2CallbackTest(TestWithDjangoEnvironment):
|
|||
self.session[session_key] = pickle.dumps(flow)
|
||||
|
||||
def local_throws(code):
|
||||
raise FlowExchangeError('test')
|
||||
raise client.FlowExchangeError('test')
|
||||
|
||||
flow.step2_exchange = local_throws
|
||||
pickle.loads.return_value = flow
|
||||
|
|
|
@ -28,7 +28,7 @@ import oauth2client
|
|||
from oauth2client import client
|
||||
from oauth2client import clientsecrets
|
||||
from oauth2client.contrib import flask_util
|
||||
from .. import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
|
||||
__author__ = 'jonwayne@google.com (Jon Wayne Parrott)'
|
||||
|
|
|
@ -24,7 +24,7 @@ from six.moves import http_client
|
|||
from oauth2client import client
|
||||
from oauth2client.contrib import _metadata
|
||||
from oauth2client.contrib import gce
|
||||
from .. import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
|
||||
SERVICE_ACCOUNT_INFO = {
|
||||
|
|
|
@ -20,7 +20,7 @@ import mock
|
|||
from six.moves import http_client
|
||||
|
||||
from oauth2client.contrib import _metadata
|
||||
from .. import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
|
||||
PATH = 'instance/service-accounts/default'
|
||||
|
|
|
@ -29,8 +29,7 @@ from six.moves import urllib_parse
|
|||
|
||||
from oauth2client import client
|
||||
from oauth2client.contrib import multiprocess_file_storage
|
||||
|
||||
from .. import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
|
@ -36,7 +36,7 @@ from oauth2client import client
|
|||
from oauth2client import clientsecrets
|
||||
from oauth2client import service_account
|
||||
from oauth2client import transport
|
||||
from . import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ from oauth2client import _helpers
|
|||
from oauth2client import client
|
||||
from oauth2client import file as file_module
|
||||
from oauth2client import transport
|
||||
from . import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
try:
|
||||
# Python2
|
||||
|
|
|
@ -28,7 +28,7 @@ from oauth2client import crypt
|
|||
from oauth2client import file as file_module
|
||||
from oauth2client import service_account
|
||||
from oauth2client import transport
|
||||
from . import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
|
||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||
|
|
|
@ -32,7 +32,7 @@ from oauth2client import client
|
|||
from oauth2client import crypt
|
||||
from oauth2client import service_account
|
||||
from oauth2client import transport
|
||||
from . import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
|
||||
def data_filename(filename):
|
||||
|
|
|
@ -19,7 +19,7 @@ import mock
|
|||
|
||||
from oauth2client import client
|
||||
from oauth2client import transport
|
||||
from . import http_mock
|
||||
from tests import http_mock
|
||||
|
||||
|
||||
class TestMemoryCache(unittest.TestCase):
|
||||
|
|
Loading…
Reference in New Issue