@@ -1,7 +0,0 @@
|
|||||||
oauth2client.appengine module
|
|
||||||
=============================
|
|
||||||
|
|
||||||
.. automodule:: oauth2client.appengine
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
7
docs/source/oauth2client.contrib.appengine.rst
Normal file
7
docs/source/oauth2client.contrib.appengine.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
oauth2client.contrib.appengine module
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
.. automodule:: oauth2client.contrib.appengine
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
7
docs/source/oauth2client.contrib.django_orm.rst
Normal file
7
docs/source/oauth2client.contrib.django_orm.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
oauth2client.contrib.django_orm module
|
||||||
|
======================================
|
||||||
|
|
||||||
|
.. automodule:: oauth2client.contrib.django_orm
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
7
docs/source/oauth2client.contrib.flask_util.rst
Normal file
7
docs/source/oauth2client.contrib.flask_util.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
oauth2client.contrib.flask_util module
|
||||||
|
======================================
|
||||||
|
|
||||||
|
.. automodule:: oauth2client.contrib.flask_util
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
7
docs/source/oauth2client.contrib.keyring_storage.rst
Normal file
7
docs/source/oauth2client.contrib.keyring_storage.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
oauth2client.contrib.keyring_storage module
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
.. automodule:: oauth2client.contrib.keyring_storage
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
7
docs/source/oauth2client.contrib.locked_file.rst
Normal file
7
docs/source/oauth2client.contrib.locked_file.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
oauth2client.contrib.locked_file module
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
.. automodule:: oauth2client.contrib.locked_file
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
7
docs/source/oauth2client.contrib.multistore_file.rst
Normal file
7
docs/source/oauth2client.contrib.multistore_file.rst
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
oauth2client.contrib.multistore_file module
|
||||||
|
===========================================
|
||||||
|
|
||||||
|
.. automodule:: oauth2client.contrib.multistore_file
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
@@ -8,6 +8,18 @@ Subpackages
|
|||||||
|
|
||||||
oauth2client.contrib.django_util
|
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
|
Module contents
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
oauth2client.django_orm module
|
|
||||||
==============================
|
|
||||||
|
|
||||||
.. automodule:: oauth2client.django_orm
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
oauth2client.flask_util module
|
|
||||||
==============================
|
|
||||||
|
|
||||||
.. automodule:: oauth2client.flask_util
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
oauth2client.keyring_storage module
|
|
||||||
===================================
|
|
||||||
|
|
||||||
.. automodule:: oauth2client.keyring_storage
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
oauth2client.locked_file module
|
|
||||||
===============================
|
|
||||||
|
|
||||||
.. automodule:: oauth2client.locked_file
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
oauth2client.multistore_file module
|
|
||||||
===================================
|
|
||||||
|
|
||||||
.. automodule:: oauth2client.multistore_file
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@@ -13,18 +13,12 @@ Submodules
|
|||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
|
||||||
oauth2client.appengine
|
|
||||||
oauth2client.client
|
oauth2client.client
|
||||||
oauth2client.clientsecrets
|
oauth2client.clientsecrets
|
||||||
oauth2client.crypt
|
oauth2client.crypt
|
||||||
oauth2client.devshell
|
oauth2client.devshell
|
||||||
oauth2client.django_orm
|
|
||||||
oauth2client.file
|
oauth2client.file
|
||||||
oauth2client.flask_util
|
|
||||||
oauth2client.gce
|
oauth2client.gce
|
||||||
oauth2client.keyring_storage
|
|
||||||
oauth2client.locked_file
|
|
||||||
oauth2client.multistore_file
|
|
||||||
oauth2client.service_account
|
oauth2client.service_account
|
||||||
oauth2client.tools
|
oauth2client.tools
|
||||||
oauth2client.util
|
oauth2client.util
|
||||||
|
|||||||
@@ -163,9 +163,6 @@ oauth2_authorized signal:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
import django.conf
|
import django.conf
|
||||||
from django.core import exceptions
|
from django.core import exceptions
|
||||||
from django.core import urlresolvers
|
from django.core import urlresolvers
|
||||||
@@ -235,7 +232,7 @@ class OAuth2Settings(object):
|
|||||||
_get_oauth2_client_id_and_secret(settings_instance)
|
_get_oauth2_client_id_and_secret(settings_instance)
|
||||||
|
|
||||||
if ('django.contrib.sessions.middleware.SessionMiddleware'
|
if ('django.contrib.sessions.middleware.SessionMiddleware'
|
||||||
not in settings_instance.MIDDLEWARE_CLASSES):
|
not in settings_instance.MIDDLEWARE_CLASSES):
|
||||||
raise exceptions.ImproperlyConfigured(
|
raise exceptions.ImproperlyConfigured(
|
||||||
"The Google OAuth2 Helper requires session middleware to "
|
"The Google OAuth2 Helper requires session middleware to "
|
||||||
"be installed. Edit your MIDDLEWARE_CLASSES setting"
|
"be installed. Edit your MIDDLEWARE_CLASSES setting"
|
||||||
@@ -292,8 +289,8 @@ class UserOAuth2(object):
|
|||||||
def has_credentials(self):
|
def has_credentials(self):
|
||||||
"""Returns True if there are valid credentials for the current user
|
"""Returns True if there are valid credentials for the current user
|
||||||
and required scopes."""
|
and required scopes."""
|
||||||
return self.credentials and not self.credentials.invalid \
|
return (self.credentials and not self.credentials.invalid
|
||||||
and self.credentials.has_scopes(self.scopes)
|
and self.credentials.has_scopes(self.scopes))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def credentials(self):
|
def credentials(self):
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import sys
|
|||||||
# Django 1.7+ only supports Python 2.7+
|
# Django 1.7+ only supports Python 2.7+
|
||||||
if sys.hexversion >= 0x02070000: # pragma: NO COVER
|
if sys.hexversion >= 0x02070000: # pragma: NO COVER
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
class GoogleOAuth2HelperConfig(AppConfig):
|
class GoogleOAuth2HelperConfig(AppConfig):
|
||||||
""" App Config for Django Helper"""
|
""" App Config for Django Helper"""
|
||||||
name = 'oauth2client.django_util'
|
name = 'oauth2client.django_util'
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ apiui/credential>`__.
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from oauth2client.flask_util import UserOAuth2
|
from oauth2client.contrib.flask_util import UserOAuth2
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@@ -218,10 +218,11 @@ class UserOAuth2(object):
|
|||||||
file, obtained from the credentials screen in the Google Developers
|
file, obtained from the credentials screen in the Google Developers
|
||||||
console.
|
console.
|
||||||
* ``GOOGLE_OAUTH2_CLIENT_ID`` the oauth2 credentials' client ID. This
|
* ``GOOGLE_OAUTH2_CLIENT_ID`` the oauth2 credentials' client ID. This
|
||||||
is only needed if ``GOOGLE_OAUTH2_CLIENT_SECRETS_JSON`` is not specified.
|
is only needed if ``GOOGLE_OAUTH2_CLIENT_SECRETS_JSON`` is not
|
||||||
* ``GOOGLE_OAUTH2_CLIENT_SECRET`` the oauth2 credentials' client
|
|
||||||
secret. This is only needed if ``GOOGLE_OAUTH2_CLIENT_SECRETS_JSON`` is not
|
|
||||||
specified.
|
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.
|
If app is specified, all arguments will be passed along to init_app.
|
||||||
|
|
||||||
@@ -243,7 +244,8 @@ class UserOAuth2(object):
|
|||||||
app: A Flask application.
|
app: A Flask application.
|
||||||
scopes: Optional list of scopes to authorize.
|
scopes: Optional list of scopes to authorize.
|
||||||
client_secrets_file: Path to a file containing client secrets. You
|
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
|
client_id: If not specifying a client secrets file, specify the
|
||||||
OAuth2 client id. You can also specify the
|
OAuth2 client id. You can also specify the
|
||||||
GOOGLE_OAUTH2_CLIENT_ID config value. You must also provide a
|
GOOGLE_OAUTH2_CLIENT_ID config value. You must also provide a
|
||||||
@@ -53,7 +53,7 @@ import threading
|
|||||||
from oauth2client.client import Credentials
|
from oauth2client.client import Credentials
|
||||||
from oauth2client.client import Storage as BaseStorage
|
from oauth2client.client import Storage as BaseStorage
|
||||||
from oauth2client import util
|
from oauth2client import util
|
||||||
from oauth2client.locked_file import LockedFile
|
from oauth2client.contrib.locked_file import LockedFile
|
||||||
|
|
||||||
|
|
||||||
__author__ = 'jbeda@google.com (Joe Beda)'
|
__author__ = 'jbeda@google.com (Joe Beda)'
|
||||||
0
tests/contrib/__init__.py
Normal file
0
tests/contrib/__init__.py
Normal file
@@ -34,7 +34,7 @@ dev_appserver.fix_sys_path()
|
|||||||
import mock
|
import mock
|
||||||
import webapp2
|
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
|
||||||
from google.appengine.api import apiproxy_stub_map
|
from google.appengine.api import apiproxy_stub_map
|
||||||
from google.appengine.api import app_identity
|
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 db
|
||||||
from google.appengine.ext import ndb
|
from google.appengine.ext import ndb
|
||||||
from google.appengine.ext import testbed
|
from google.appengine.ext import testbed
|
||||||
from oauth2client import appengine
|
from oauth2client.contrib import appengine
|
||||||
from oauth2client import GOOGLE_TOKEN_URI
|
from oauth2client import GOOGLE_TOKEN_URI
|
||||||
from oauth2client.clientsecrets import _loadfile
|
from oauth2client.clientsecrets import _loadfile
|
||||||
from oauth2client.clientsecrets import InvalidClientSecretsError
|
from oauth2client.clientsecrets import InvalidClientSecretsError
|
||||||
from oauth2client.appengine import AppAssertionCredentials
|
from oauth2client.contrib.appengine import AppAssertionCredentials
|
||||||
from oauth2client.appengine import CredentialsModel
|
from oauth2client.contrib.appengine import CredentialsModel
|
||||||
from oauth2client.appengine import CredentialsNDBModel
|
from oauth2client.contrib.appengine import CredentialsNDBModel
|
||||||
from oauth2client.appengine import FlowNDBProperty
|
from oauth2client.contrib.appengine import FlowNDBProperty
|
||||||
from oauth2client.appengine import FlowProperty
|
from oauth2client.contrib.appengine import FlowProperty
|
||||||
from oauth2client.appengine import OAuth2Decorator
|
from oauth2client.contrib.appengine import OAuth2Decorator
|
||||||
from oauth2client.appengine import OAuth2DecoratorFromClientSecrets
|
from oauth2client.contrib.appengine import OAuth2DecoratorFromClientSecrets
|
||||||
from oauth2client.appengine import StorageByKeyName
|
from oauth2client.contrib.appengine import StorageByKeyName
|
||||||
from oauth2client.client import _CLOUDSDK_CONFIG_ENV_VAR
|
from oauth2client.client import _CLOUDSDK_CONFIG_ENV_VAR
|
||||||
from oauth2client.client import AccessTokenRefreshError
|
from oauth2client.client import AccessTokenRefreshError
|
||||||
from oauth2client.client import Credentials
|
from oauth2client.client import Credentials
|
||||||
@@ -67,7 +67,7 @@ from webtest import TestApp
|
|||||||
|
|
||||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
__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):
|
def datafile(filename):
|
||||||
@@ -29,11 +29,11 @@ import unittest
|
|||||||
# Mock a Django environment
|
# Mock a Django environment
|
||||||
from django.conf import global_settings
|
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
|
from django.conf import settings
|
||||||
|
|
||||||
settings.SECRET_KEY = 'this string is not a real Django SECRET_KEY'
|
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
|
import django
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
class DjangoOrmTestApp(AppConfig):
|
class DjangoOrmTestApp(AppConfig):
|
||||||
"""App Config for Django Helper."""
|
"""App Config for Django Helper."""
|
||||||
name = 'oauth2client.tests.test_django_orm'
|
name = 'oauth2client.tests.contrib.test_django_orm'
|
||||||
verbose_name = "Django Test App"
|
verbose_name = "Django Test App"
|
||||||
|
|
||||||
|
|
||||||
@@ -52,9 +52,9 @@ from oauth2client._helpers import _from_bytes
|
|||||||
from oauth2client.client import Credentials
|
from oauth2client.client import Credentials
|
||||||
from oauth2client.client import Flow
|
from oauth2client.client import Flow
|
||||||
from oauth2client.client import OAuth2Credentials
|
from oauth2client.client import OAuth2Credentials
|
||||||
from oauth2client.django_orm import CredentialsField
|
from oauth2client.contrib.django_orm import CredentialsField
|
||||||
from oauth2client.django_orm import FlowField
|
from oauth2client.contrib.django_orm import FlowField
|
||||||
from oauth2client.django_orm import Storage
|
from oauth2client.contrib.django_orm import Storage
|
||||||
from oauth2client import GOOGLE_TOKEN_URI
|
from oauth2client import GOOGLE_TOKEN_URI
|
||||||
|
|
||||||
__author__ = 'conleyo@google.com (Conley Owens)'
|
__author__ = 'conleyo@google.com (Conley Owens)'
|
||||||
@@ -31,4 +31,4 @@ GOOGLE_OAUTH2_CLIENT_ID = 'client_id2'
|
|||||||
GOOGLE_OAUTH2_CLIENT_SECRET = 'hunter2'
|
GOOGLE_OAUTH2_CLIENT_SECRET = 'hunter2'
|
||||||
GOOGLE_OAUTH2_SCOPES = ('https://www.googleapis.com/auth/cloud-platform',)
|
GOOGLE_OAUTH2_SCOPES = ('https://www.googleapis.com/auth/cloud-platform',)
|
||||||
|
|
||||||
ROOT_URLCONF = 'tests.test_django_util'
|
ROOT_URLCONF = 'tests.contrib.test_django_util'
|
||||||
@@ -65,8 +65,11 @@ class OAuth2SetupTest(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertRaises(ValueError, django_util.OAuth2Settings.__init__,
|
self.assertRaises(
|
||||||
object.__new__(django_util.OAuth2Settings), django.conf.settings)
|
ValueError,
|
||||||
|
django_util.OAuth2Settings.__init__,
|
||||||
|
object.__new__(django_util.OAuth2Settings),
|
||||||
|
django.conf.settings)
|
||||||
|
|
||||||
@mock.patch("oauth2client.contrib.django_util.clientsecrets")
|
@mock.patch("oauth2client.contrib.django_util.clientsecrets")
|
||||||
def test_no_settings(self, clientsecrets):
|
def test_no_settings(self, clientsecrets):
|
||||||
@@ -74,18 +77,22 @@ class OAuth2SetupTest(unittest.TestCase):
|
|||||||
django.conf.settings.GOOGLE_OAUTH2_CLIENT_SECRET = None
|
django.conf.settings.GOOGLE_OAUTH2_CLIENT_SECRET = None
|
||||||
django.conf.settings.GOOGLE_OAUTH2_CLIENT_ID = None
|
django.conf.settings.GOOGLE_OAUTH2_CLIENT_ID = None
|
||||||
|
|
||||||
self.assertRaises(exceptions.ImproperlyConfigured, django_util.OAuth2Settings.__init__,
|
self.assertRaises(
|
||||||
object.__new__(django_util.OAuth2Settings), django.conf.settings)
|
exceptions.ImproperlyConfigured,
|
||||||
|
django_util.OAuth2Settings.__init__,
|
||||||
|
object.__new__(django_util.OAuth2Settings),
|
||||||
|
django.conf.settings)
|
||||||
|
|
||||||
@mock.patch("oauth2client.contrib.django_util.clientsecrets")
|
@mock.patch("oauth2client.contrib.django_util.clientsecrets")
|
||||||
def test_no_session_middleware(self, clientsecrets):
|
def test_no_session_middleware(self, clientsecrets):
|
||||||
old_classes = django.conf.settings.MIDDLEWARE_CLASSES
|
old_classes = django.conf.settings.MIDDLEWARE_CLASSES
|
||||||
django.conf.settings.MIDDLEWARE_CLASSES = ()
|
django.conf.settings.MIDDLEWARE_CLASSES = ()
|
||||||
|
|
||||||
self.assertRaises(exceptions.ImproperlyConfigured,
|
self.assertRaises(
|
||||||
django_util.OAuth2Settings.__init__, object.__new__(
|
exceptions.ImproperlyConfigured,
|
||||||
django_util.OAuth2Settings),
|
django_util.OAuth2Settings.__init__,
|
||||||
django.conf.settings)
|
object.__new__(django_util.OAuth2Settings),
|
||||||
|
django.conf.settings)
|
||||||
django.conf.settings.MIDDLEWARE_CLASSES = old_classes
|
django.conf.settings.MIDDLEWARE_CLASSES = old_classes
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +121,6 @@ class OAuth2EnabledDecoratorTest(TestWithSession):
|
|||||||
self.assertFalse(request.oauth.has_credentials())
|
self.assertFalse(request.oauth.has_credentials())
|
||||||
self.assertIsNone(request.oauth.http)
|
self.assertIsNone(request.oauth.http)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("oauth2client.client.OAuth2Credentials")
|
@mock.patch("oauth2client.client.OAuth2Credentials")
|
||||||
def test_has_credentials_in_storage(self, OAuth2Credentials):
|
def test_has_credentials_in_storage(self, OAuth2Credentials):
|
||||||
request = self.factory.get('/test')
|
request = self.factory.get('/test')
|
||||||
@@ -170,7 +176,8 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
|
|||||||
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
||||||
self.assertEquals(parse.urlparse(response['Location']).path,
|
self.assertEquals(parse.urlparse(response['Location']).path,
|
||||||
"/oauth2/oauth2authorize/")
|
"/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)
|
self.assertEquals(response.status_code, 302)
|
||||||
|
|
||||||
@@ -179,7 +186,6 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
|
|||||||
request = self.factory.get('/test')
|
request = self.factory.get('/test')
|
||||||
request.session = mock.MagicMock()
|
request.session = mock.MagicMock()
|
||||||
|
|
||||||
|
|
||||||
@decorators.oauth_required
|
@decorators.oauth_required
|
||||||
def test_view(request):
|
def test_view(request):
|
||||||
return http.HttpResponse("test")
|
return http.HttpResponse("test")
|
||||||
@@ -198,7 +204,8 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
|
|||||||
request = self.factory.get('/test')
|
request = self.factory.get('/test')
|
||||||
|
|
||||||
request.session = mock.MagicMock()
|
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
|
credentials_mock.has_scopes.return_value = False
|
||||||
|
|
||||||
OAuth2Credentials.from_json.return_value = credentials_mock
|
OAuth2Credentials.from_json.return_value = credentials_mock
|
||||||
@@ -215,13 +222,14 @@ class OAuth2RequiredDecoratorTest(TestWithSession):
|
|||||||
request = self.factory.get('/test')
|
request = self.factory.get('/test')
|
||||||
request.session = mock.MagicMock()
|
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
|
credentials_mock.has_scopes = False
|
||||||
OAuth2Credentials.from_json.return_value = credentials_mock
|
OAuth2Credentials.from_json.return_value = credentials_mock
|
||||||
|
|
||||||
@decorators.oauth_required(scopes=['additional-scope'])
|
@decorators.oauth_required(scopes=['additional-scope'])
|
||||||
def test_view(request):
|
def test_view(request):
|
||||||
return http.HttpResponse("hello world") # pragma: NO COVER
|
return http.HttpResponse("hello world") # pragma: NO COVER
|
||||||
|
|
||||||
response = test_view(request)
|
response = test_view(request)
|
||||||
self.assertEquals(response.status_code, 302)
|
self.assertEquals(response.status_code, 302)
|
||||||
@@ -243,6 +251,7 @@ class Oauth2AuthorizeTest(TestWithSession):
|
|||||||
response = views.oauth2_authorize(request)
|
response = views.oauth2_authorize(request)
|
||||||
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
self.assertTrue(isinstance(response, http.HttpResponseRedirect))
|
||||||
|
|
||||||
|
|
||||||
class Oauth2CallbackTest(TestWithSession):
|
class Oauth2CallbackTest(TestWithSession):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@@ -331,7 +340,8 @@ class Oauth2CallbackTest(TestWithSession):
|
|||||||
request.session = self.session
|
request.session = self.session
|
||||||
response = views.oauth2_callback(request)
|
response = views.oauth2_callback(request)
|
||||||
self.assertTrue(isinstance(response, http.HttpResponseBadRequest))
|
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):
|
def test_missing_state_returns_bad_request(self):
|
||||||
request = self.factory.get('oauth2/oauth2callback', data={
|
request = self.factory.get('oauth2/oauth2callback', data={
|
||||||
@@ -26,8 +26,8 @@ import six.moves.urllib.parse as urlparse
|
|||||||
from oauth2client import GOOGLE_AUTH_URI
|
from oauth2client import GOOGLE_AUTH_URI
|
||||||
from oauth2client import GOOGLE_TOKEN_URI
|
from oauth2client import GOOGLE_TOKEN_URI
|
||||||
from oauth2client import clientsecrets
|
from oauth2client import clientsecrets
|
||||||
from oauth2client.flask_util import _get_flow_for_token
|
from oauth2client.contrib.flask_util import _get_flow_for_token
|
||||||
from oauth2client.flask_util import UserOAuth2 as FlaskOAuth2
|
from oauth2client.contrib.flask_util import UserOAuth2 as FlaskOAuth2
|
||||||
from oauth2client.client import OAuth2Credentials
|
from oauth2client.client import OAuth2Credentials
|
||||||
|
|
||||||
|
|
||||||
@@ -12,10 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
"""Tests for oauth2client.keyring_storage tests.
|
"""Tests for oauth2client.contrib.keyring_storage."""
|
||||||
|
|
||||||
Unit tests for oauth2client.keyring_storage.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import keyring
|
import keyring
|
||||||
@@ -26,7 +23,7 @@ import mock
|
|||||||
|
|
||||||
from oauth2client import GOOGLE_TOKEN_URI
|
from oauth2client import GOOGLE_TOKEN_URI
|
||||||
from oauth2client.client import OAuth2Credentials
|
from oauth2client.client import OAuth2Credentials
|
||||||
from oauth2client.keyring_storage import Storage
|
from oauth2client.contrib.keyring_storage import Storage
|
||||||
|
|
||||||
|
|
||||||
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
|
||||||
@@ -67,8 +64,8 @@ class KeyringStorageTests(unittest.TestCase):
|
|||||||
with mock.patch.object(keyring, 'get_password',
|
with mock.patch.object(keyring, 'get_password',
|
||||||
return_value=mock_content,
|
return_value=mock_content,
|
||||||
autospec=True) as get_password:
|
autospec=True) as get_password:
|
||||||
with mock.patch(
|
class_name = 'oauth2client.contrib.keyring_storage.Credentials'
|
||||||
'oauth2client.keyring_storage.Credentials') as MockCreds:
|
with mock.patch(class_name) as MockCreds:
|
||||||
MockCreds.new_from_json = new_from_json = mock.MagicMock(
|
MockCreds.new_from_json = new_from_json = mock.MagicMock(
|
||||||
name='new_from_json', return_value=mock_return_creds)
|
name='new_from_json', return_value=mock_return_creds)
|
||||||
store = Storage(service_name, user_name)
|
store = Storage(service_name, user_name)
|
||||||
@@ -9,8 +9,8 @@ import unittest
|
|||||||
|
|
||||||
from oauth2client import util
|
from oauth2client import util
|
||||||
from oauth2client.client import OAuth2Credentials
|
from oauth2client.client import OAuth2Credentials
|
||||||
from oauth2client import locked_file
|
from oauth2client.contrib import locked_file
|
||||||
from oauth2client import multistore_file
|
from oauth2client.contrib import multistore_file
|
||||||
|
|
||||||
_filehandle, FILENAME = tempfile.mkstemp('oauth2client_test.data')
|
_filehandle, FILENAME = tempfile.mkstemp('oauth2client_test.data')
|
||||||
os.close(_filehandle)
|
os.close(_filehandle)
|
||||||
@@ -239,6 +239,7 @@ class OAuth2ClientFileTests(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertNotEquals(None, credentials)
|
self.assertNotEquals(None, credentials)
|
||||||
self.assertEquals('foo', credentials.access_token)
|
self.assertEquals('foo', credentials.access_token)
|
||||||
|
|
||||||
self.assertTrue(os.path.exists(FILENAME))
|
self.assertTrue(os.path.exists(FILENAME))
|
||||||
|
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
|
|||||||
16
tox.ini
16
tox.ini
@@ -14,7 +14,7 @@ deps = {[testenv]basedeps}
|
|||||||
django
|
django
|
||||||
setenv =
|
setenv =
|
||||||
pypy: with_gmp=no
|
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}
|
commands = nosetests --ignore-files=test_appengine\.py {posargs}
|
||||||
|
|
||||||
[coverbase]
|
[coverbase]
|
||||||
@@ -27,18 +27,18 @@ commands =
|
|||||||
--cover-erase \
|
--cover-erase \
|
||||||
--cover-tests \
|
--cover-tests \
|
||||||
--cover-branches \
|
--cover-branches \
|
||||||
--ignore-files=test_appengine\.py
|
--ignore-files=contrib/test_appengine\.py
|
||||||
nosetests \
|
nosetests \
|
||||||
--with-coverage \
|
--with-coverage \
|
||||||
--cover-package=oauth2client.appengine \
|
--cover-package=oauth2client.contrib.appengine \
|
||||||
--cover-package=tests.test_appengine \
|
--cover-package=tests.contrib.test_appengine \
|
||||||
--with-gae \
|
--with-gae \
|
||||||
--cover-tests \
|
--cover-tests \
|
||||||
--cover-branches \
|
--cover-branches \
|
||||||
--gae-application=tests/data \
|
--gae-application=tests/data \
|
||||||
--gae-lib-root={env:GAE_PYTHONPATH} \
|
--gae-lib-root={env:GAE_PYTHONPATH} \
|
||||||
--logging-level=INFO \
|
--logging-level=INFO \
|
||||||
tests/test_appengine.py
|
tests/contrib/test_appengine.py
|
||||||
deps = {[testenv]deps}
|
deps = {[testenv]deps}
|
||||||
coverage
|
coverage
|
||||||
nosegae
|
nosegae
|
||||||
@@ -106,7 +106,11 @@ basepython = python2.7
|
|||||||
deps = {[testenv]basedeps}
|
deps = {[testenv]basedeps}
|
||||||
nosegae
|
nosegae
|
||||||
commands =
|
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:
|
setenv:
|
||||||
PYTHONPATH={env:GAE_PYTHONPATH:}
|
PYTHONPATH={env:GAE_PYTHONPATH:}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user