Move non-core modules to contrib.

Fixes #352
This commit is contained in:
Jon Wayne Parrott
2015-12-04 13:19:56 -08:00
parent 7a0029ef68
commit 41eb75578f
32 changed files with 128 additions and 110 deletions

View File

@@ -1,7 +0,0 @@
oauth2client.appengine module
=============================
.. automodule:: oauth2client.appengine
:members:
:undoc-members:
:show-inheritance:

View File

@@ -0,0 +1,7 @@
oauth2client.contrib.appengine module
=====================================
.. automodule:: oauth2client.contrib.appengine
:members:
:undoc-members:
:show-inheritance:

View File

@@ -0,0 +1,7 @@
oauth2client.contrib.django_orm module
======================================
.. automodule:: oauth2client.contrib.django_orm
:members:
:undoc-members:
:show-inheritance:

View File

@@ -0,0 +1,7 @@
oauth2client.contrib.flask_util module
======================================
.. automodule:: oauth2client.contrib.flask_util
:members:
:undoc-members:
:show-inheritance:

View File

@@ -0,0 +1,7 @@
oauth2client.contrib.keyring_storage module
===========================================
.. automodule:: oauth2client.contrib.keyring_storage
:members:
:undoc-members:
:show-inheritance:

View File

@@ -0,0 +1,7 @@
oauth2client.contrib.locked_file module
=======================================
.. automodule:: oauth2client.contrib.locked_file
:members:
:undoc-members:
:show-inheritance:

View File

@@ -0,0 +1,7 @@
oauth2client.contrib.multistore_file module
===========================================
.. automodule:: oauth2client.contrib.multistore_file
:members:
:undoc-members:
:show-inheritance:

View File

@@ -8,6 +8,18 @@ Subpackages
oauth2client.contrib.django_util
Submodules
----------
.. toctree::
oauth2client.contrib.appengine
oauth2client.contrib.django_orm
oauth2client.contrib.flask_util
oauth2client.contrib.keyring_storage
oauth2client.contrib.locked_file
oauth2client.contrib.multistore_file
Module contents
---------------

View File

@@ -1,7 +0,0 @@
oauth2client.django_orm module
==============================
.. automodule:: oauth2client.django_orm
:members:
:undoc-members:
:show-inheritance:

View File

@@ -1,7 +0,0 @@
oauth2client.flask_util module
==============================
.. automodule:: oauth2client.flask_util
:members:
:undoc-members:
:show-inheritance:

View File

@@ -1,7 +0,0 @@
oauth2client.keyring_storage module
===================================
.. automodule:: oauth2client.keyring_storage
:members:
:undoc-members:
:show-inheritance:

View File

@@ -1,7 +0,0 @@
oauth2client.locked_file module
===============================
.. automodule:: oauth2client.locked_file
:members:
:undoc-members:
:show-inheritance:

View File

@@ -1,7 +0,0 @@
oauth2client.multistore_file module
===================================
.. automodule:: oauth2client.multistore_file
:members:
:undoc-members:
:show-inheritance:

View File

@@ -13,18 +13,12 @@ Submodules
.. toctree::
oauth2client.appengine
oauth2client.client
oauth2client.clientsecrets
oauth2client.crypt
oauth2client.devshell
oauth2client.django_orm
oauth2client.file
oauth2client.flask_util
oauth2client.gce
oauth2client.keyring_storage
oauth2client.locked_file
oauth2client.multistore_file
oauth2client.service_account
oauth2client.tools
oauth2client.util

View File

@@ -163,9 +163,6 @@ oauth2_authorized signal:
"""
import sys
import django.conf
from django.core import exceptions
from django.core import urlresolvers
@@ -292,8 +289,8 @@ class UserOAuth2(object):
def has_credentials(self):
"""Returns True if there are valid credentials for the current user
and required scopes."""
return self.credentials and not self.credentials.invalid \
and self.credentials.has_scopes(self.scopes)
return (self.credentials and not self.credentials.invalid
and self.credentials.has_scopes(self.scopes))
@property
def credentials(self):

View File

@@ -25,6 +25,7 @@ import sys
# Django 1.7+ only supports Python 2.7+
if sys.hexversion >= 0x02070000: # pragma: NO COVER
from django.apps import AppConfig
class GoogleOAuth2HelperConfig(AppConfig):
""" App Config for Django Helper"""
name = 'oauth2client.django_util'

View File

@@ -29,7 +29,7 @@ apiui/credential>`__.
.. code-block:: python
from oauth2client.flask_util import UserOAuth2
from oauth2client.contrib.flask_util import UserOAuth2
app = Flask(__name__)
@@ -218,10 +218,11 @@ class UserOAuth2(object):
file, obtained from the credentials screen in the Google Developers
console.
* ``GOOGLE_OAUTH2_CLIENT_ID`` the oauth2 credentials' client ID. This
is only needed if ``GOOGLE_OAUTH2_CLIENT_SECRETS_JSON`` is not specified.
* ``GOOGLE_OAUTH2_CLIENT_SECRET`` the oauth2 credentials' client
secret. This is only needed if ``GOOGLE_OAUTH2_CLIENT_SECRETS_JSON`` is not
is only needed if ``GOOGLE_OAUTH2_CLIENT_SECRETS_JSON`` is not
specified.
* ``GOOGLE_OAUTH2_CLIENT_SECRET`` the oauth2 credentials' client
secret. This is only needed if ``GOOGLE_OAUTH2_CLIENT_SECRETS_JSON``
is not specified.
If app is specified, all arguments will be passed along to init_app.
@@ -243,7 +244,8 @@ class UserOAuth2(object):
app: A Flask application.
scopes: Optional list of scopes to authorize.
client_secrets_file: Path to a file containing client secrets. You
can also specify the GOOGLE_OAUTH2_CLIENT_SECRETS_JSON config value.
can also specify the GOOGLE_OAUTH2_CLIENT_SECRETS_JSON config
value.
client_id: If not specifying a client secrets file, specify the
OAuth2 client id. You can also specify the
GOOGLE_OAUTH2_CLIENT_ID config value. You must also provide a

View File

@@ -53,7 +53,7 @@ import threading
from oauth2client.client import Credentials
from oauth2client.client import Storage as BaseStorage
from oauth2client import util
from oauth2client.locked_file import LockedFile
from oauth2client.contrib.locked_file import LockedFile
__author__ = 'jbeda@google.com (Joe Beda)'

View File

View File

@@ -34,7 +34,7 @@ dev_appserver.fix_sys_path()
import mock
import webapp2
from .http_mock import CacheMock
from ..http_mock import CacheMock
from google.appengine.api import apiproxy_stub
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import app_identity
@@ -44,18 +44,18 @@ from google.appengine.api.memcache import memcache_stub
from google.appengine.ext import db
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from oauth2client import appengine
from oauth2client.contrib import appengine
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client.clientsecrets import _loadfile
from oauth2client.clientsecrets import InvalidClientSecretsError
from oauth2client.appengine import AppAssertionCredentials
from oauth2client.appengine import CredentialsModel
from oauth2client.appengine import CredentialsNDBModel
from oauth2client.appengine import FlowNDBProperty
from oauth2client.appengine import FlowProperty
from oauth2client.appengine import OAuth2Decorator
from oauth2client.appengine import OAuth2DecoratorFromClientSecrets
from oauth2client.appengine import StorageByKeyName
from oauth2client.contrib.appengine import AppAssertionCredentials
from oauth2client.contrib.appengine import CredentialsModel
from oauth2client.contrib.appengine import CredentialsNDBModel
from oauth2client.contrib.appengine import FlowNDBProperty
from oauth2client.contrib.appengine import FlowProperty
from oauth2client.contrib.appengine import OAuth2Decorator
from oauth2client.contrib.appengine import OAuth2DecoratorFromClientSecrets
from oauth2client.contrib.appengine import StorageByKeyName
from oauth2client.client import _CLOUDSDK_CONFIG_ENV_VAR
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import Credentials
@@ -67,7 +67,7 @@ from webtest import TestApp
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
DATA_DIR = os.path.join(os.path.dirname(__file__), '..', 'data')
def datafile(filename):

View File

@@ -29,11 +29,11 @@ import unittest
# Mock a Django environment
from django.conf import global_settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_django_settings'
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.contrib.test_django_settings'
from django.conf import settings
settings.SECRET_KEY = 'this string is not a real Django SECRET_KEY'
settings.INSTALLED_APPS = ['tests.test_django_orm']
settings.INSTALLED_APPS = ['tests.contrib.test_django_orm']
import django
@@ -43,7 +43,7 @@ from django.apps import AppConfig
class DjangoOrmTestApp(AppConfig):
"""App Config for Django Helper."""
name = 'oauth2client.tests.test_django_orm'
name = 'oauth2client.tests.contrib.test_django_orm'
verbose_name = "Django Test App"
@@ -52,9 +52,9 @@ from oauth2client._helpers import _from_bytes
from oauth2client.client import Credentials
from oauth2client.client import Flow
from oauth2client.client import OAuth2Credentials
from oauth2client.django_orm import CredentialsField
from oauth2client.django_orm import FlowField
from oauth2client.django_orm import Storage
from oauth2client.contrib.django_orm import CredentialsField
from oauth2client.contrib.django_orm import FlowField
from oauth2client.contrib.django_orm import Storage
from oauth2client import GOOGLE_TOKEN_URI
__author__ = 'conleyo@google.com (Conley Owens)'

View File

@@ -31,4 +31,4 @@ GOOGLE_OAUTH2_CLIENT_ID = 'client_id2'
GOOGLE_OAUTH2_CLIENT_SECRET = 'hunter2'
GOOGLE_OAUTH2_SCOPES = ('https://www.googleapis.com/auth/cloud-platform',)
ROOT_URLCONF = 'tests.test_django_util'
ROOT_URLCONF = 'tests.contrib.test_django_util'

View File

@@ -65,8 +65,11 @@ class OAuth2SetupTest(unittest.TestCase):
}
)
self.assertRaises(ValueError, django_util.OAuth2Settings.__init__,
object.__new__(django_util.OAuth2Settings), django.conf.settings)
self.assertRaises(
ValueError,
django_util.OAuth2Settings.__init__,
object.__new__(django_util.OAuth2Settings),
django.conf.settings)
@mock.patch("oauth2client.contrib.django_util.clientsecrets")
def test_no_settings(self, clientsecrets):
@@ -74,17 +77,21 @@ class OAuth2SetupTest(unittest.TestCase):
django.conf.settings.GOOGLE_OAUTH2_CLIENT_SECRET = None
django.conf.settings.GOOGLE_OAUTH2_CLIENT_ID = None
self.assertRaises(exceptions.ImproperlyConfigured, django_util.OAuth2Settings.__init__,
object.__new__(django_util.OAuth2Settings), django.conf.settings)
self.assertRaises(
exceptions.ImproperlyConfigured,
django_util.OAuth2Settings.__init__,
object.__new__(django_util.OAuth2Settings),
django.conf.settings)
@mock.patch("oauth2client.contrib.django_util.clientsecrets")
def test_no_session_middleware(self, clientsecrets):
old_classes = django.conf.settings.MIDDLEWARE_CLASSES
django.conf.settings.MIDDLEWARE_CLASSES = ()
self.assertRaises(exceptions.ImproperlyConfigured,
django_util.OAuth2Settings.__init__, object.__new__(
django_util.OAuth2Settings),
self.assertRaises(
exceptions.ImproperlyConfigured,
django_util.OAuth2Settings.__init__,
object.__new__(django_util.OAuth2Settings),
django.conf.settings)
django.conf.settings.MIDDLEWARE_CLASSES = old_classes
@@ -114,7 +121,6 @@ class OAuth2EnabledDecoratorTest(TestWithSession):
self.assertFalse(request.oauth.has_credentials())
self.assertIsNone(request.oauth.http)
@mock.patch("oauth2client.client.OAuth2Credentials")
def test_has_credentials_in_storage(self, OAuth2Credentials):
request = self.factory.get('/test')
@@ -170,7 +176,8 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
self.assertEquals(parse.urlparse(response['Location']).path,
"/oauth2/oauth2authorize/")
self.assertTrue("return_url=%2Ftest" in parse.urlparse(response['Location']).query)
self.assertTrue(
"return_url=%2Ftest" in parse.urlparse(response['Location']).query)
self.assertEquals(response.status_code, 302)
@@ -179,7 +186,6 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
request = self.factory.get('/test')
request.session = mock.MagicMock()
@decorators.oauth_required
def test_view(request):
return http.HttpResponse("test")
@@ -198,7 +204,8 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
request = self.factory.get('/test')
request.session = mock.MagicMock()
credentials_mock = mock.Mock(scopes=set(django.conf.settings.GOOGLE_OAUTH2_SCOPES))
credentials_mock = mock.Mock(
scopes=set(django.conf.settings.GOOGLE_OAUTH2_SCOPES))
credentials_mock.has_scopes.return_value = False
OAuth2Credentials.from_json.return_value = credentials_mock
@@ -215,7 +222,8 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
request = self.factory.get('/test')
request.session = mock.MagicMock()
credentials_mock = mock.Mock(scopes=set(django.conf.settings.GOOGLE_OAUTH2_SCOPES))
credentials_mock = mock.Mock(
scopes=set(django.conf.settings.GOOGLE_OAUTH2_SCOPES))
credentials_mock.has_scopes = False
OAuth2Credentials.from_json.return_value = credentials_mock
@@ -243,6 +251,7 @@ class Oauth2AuthorizeTest(TestWithSession):
response = views.oauth2_authorize(request)
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
class Oauth2CallbackTest(TestWithSession):
def setUp(self):
@@ -331,7 +340,8 @@ class Oauth2CallbackTest(TestWithSession):
request.session = self.session
response = views.oauth2_callback(request)
self.assertTrue(isinstance(response, http.HttpResponseBadRequest))
self.assertEquals(response.content, b'No existing session for this flow.')
self.assertEquals(
response.content, b'No existing session for this flow.')
def test_missing_state_returns_bad_request(self):
request = self.factory.get('oauth2/oauth2callback', data={

View File

@@ -26,8 +26,8 @@ import six.moves.urllib.parse as urlparse
from oauth2client import GOOGLE_AUTH_URI
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client import clientsecrets
from oauth2client.flask_util import _get_flow_for_token
from oauth2client.flask_util import UserOAuth2 as FlaskOAuth2
from oauth2client.contrib.flask_util import _get_flow_for_token
from oauth2client.contrib.flask_util import UserOAuth2 as FlaskOAuth2
from oauth2client.client import OAuth2Credentials

View File

@@ -12,10 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for oauth2client.keyring_storage tests.
Unit tests for oauth2client.keyring_storage.
"""
"""Tests for oauth2client.contrib.keyring_storage."""
import datetime
import keyring
@@ -26,7 +23,7 @@ import mock
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client.client import OAuth2Credentials
from oauth2client.keyring_storage import Storage
from oauth2client.contrib.keyring_storage import Storage
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
@@ -67,8 +64,8 @@ class KeyringStorageTests(unittest.TestCase):
with mock.patch.object(keyring, 'get_password',
return_value=mock_content,
autospec=True) as get_password:
with mock.patch(
'oauth2client.keyring_storage.Credentials') as MockCreds:
class_name = 'oauth2client.contrib.keyring_storage.Credentials'
with mock.patch(class_name) as MockCreds:
MockCreds.new_from_json = new_from_json = mock.MagicMock(
name='new_from_json', return_value=mock_return_creds)
store = Storage(service_name, user_name)

View File

@@ -9,8 +9,8 @@ import unittest
from oauth2client import util
from oauth2client.client import OAuth2Credentials
from oauth2client import locked_file
from oauth2client import multistore_file
from oauth2client.contrib import locked_file
from oauth2client.contrib import multistore_file
_filehandle, FILENAME = tempfile.mkstemp('oauth2client_test.data')
os.close(_filehandle)

View File

@@ -239,6 +239,7 @@ class OAuth2ClientFileTests(unittest.TestCase):
self.assertNotEquals(None, credentials)
self.assertEquals('foo', credentials.access_token)
self.assertTrue(os.path.exists(FILENAME))
if os.name == 'posix':

16
tox.ini
View File

@@ -14,7 +14,7 @@ deps = {[testenv]basedeps}
django
setenv =
pypy: with_gmp=no
DJANGO_SETTINGS_MODULE=tests.test_django_settings
DJANGO_SETTINGS_MODULE=tests.contrib.test_django_settings
commands = nosetests --ignore-files=test_appengine\.py {posargs}
[coverbase]
@@ -27,18 +27,18 @@ commands =
--cover-erase \
--cover-tests \
--cover-branches \
--ignore-files=test_appengine\.py
--ignore-files=contrib/test_appengine\.py
nosetests \
--with-coverage \
--cover-package=oauth2client.appengine \
--cover-package=tests.test_appengine \
--cover-package=oauth2client.contrib.appengine \
--cover-package=tests.contrib.test_appengine \
--with-gae \
--cover-tests \
--cover-branches \
--gae-application=tests/data \
--gae-lib-root={env:GAE_PYTHONPATH} \
--logging-level=INFO \
tests/test_appengine.py
tests/contrib/test_appengine.py
deps = {[testenv]deps}
coverage
nosegae
@@ -106,7 +106,11 @@ basepython = python2.7
deps = {[testenv]basedeps}
nosegae
commands =
nosetests --with-gae --gae-application=tests/data --logging-level=INFO tests/test_appengine.py
nosetests \
--with-gae \
--gae-application=tests/data \
--logging-level=INFO \
tests/contrib/test_appengine.py
setenv:
PYTHONPATH={env:GAE_PYTHONPATH:}