Python oauth2client 模块,contrib() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用oauth2client.contrib()

项目:deb-python-oauth2client    作者:openstack    | 项目源码 | 文件源码
def test_decorator_from_client_secrets_with_optional_settings(self):
        # Test that the decorator works with the absense of a revoke_uri in
        # the client secrets.
        loadfile_patch = mock.patch(
            'oauth2client.contrib.appengine.clientsecrets.loadfile')
        with loadfile_patch as loadfile_mock:
            loadfile_mock.return_value = (clientsecrets.TYPE_WEB, {
                'client_id': 'foo_client_id',
                'client_secret': 'foo_client_secret',
                'redirect_uris': [],
                'auth_uri': oauth2client.GOOGLE_AUTH_URI,
                'token_uri': oauth2client.GOOGLE_TOKEN_URI,
                # No revoke URI
            })

            decorator = appengine.OAuth2DecoratorFromClientSecrets(
                'doesntmatter.json',
                scope=['foo_scope', 'bar_scope'])

        self.assertEqual(decorator._revoke_uri, oauth2client.GOOGLE_REVOKE_URI)
        # This is never set, but it's consistent with other tests.
        self.assertFalse(decorator._in_error)
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def test_decorator_from_client_secrets_with_optional_settings(self):
        # Test that the decorator works with the absense of a revoke_uri in
        # the client secrets.
        loadfile_patch = mock.patch(
            'oauth2client.contrib.appengine.clientsecrets.loadfile')
        with loadfile_patch as loadfile_mock:
            loadfile_mock.return_value = (clientsecrets.TYPE_WEB, {
                'client_id': 'foo_client_id',
                'client_secret': 'foo_client_secret',
                'redirect_uris': [],
                'auth_uri': oauth2client.GOOGLE_AUTH_URI,
                'token_uri': oauth2client.GOOGLE_TOKEN_URI,
                # No revoke URI
            })

            decorator = appengine.OAuth2DecoratorFromClientSecrets(
                'doesntmatter.json',
                scope=['foo_scope', 'bar_scope'])

        self.assertEqual(decorator._revoke_uri, oauth2client.GOOGLE_REVOKE_URI)
        # This is never set, but it's consistent with other tests.
        self.assertFalse(decorator._in_error)
项目:deb-python-oauth2client    作者:openstack    | 项目源码 | 文件源码
def test_decorator_from_client_secrets_toplevel(self):
        decorator_patch = mock.patch(
            'oauth2client.contrib.appengine.OAuth2DecoratorFromClientSecrets')

        with decorator_patch as decorator_mock:
            filename = datafile('client_secrets.json')
            appengine.oauth2decorator_from_clientsecrets(
                filename, scope='foo_scope')
            decorator_mock.assert_called_once_with(
                filename,
                'foo_scope',
                cache=None,
                message=None)
项目:deb-python-oauth2client    作者:openstack    | 项目源码 | 文件源码
def test_decorator_from_client_secrets_bad_type(self):
        # NOTE: this code path is not currently reachable, as the only types
        # that oauth2client.clientsecrets can load is web and installed, so
        # this test forces execution of this code path. Despite not being
        # normally reachable, this should remain in case future types of
        # credentials are added.

        loadfile_patch = mock.patch(
            'oauth2client.contrib.appengine.clientsecrets.loadfile')
        with loadfile_patch as loadfile_mock:
            loadfile_mock.return_value = ('badtype', None)
            with self.assertRaises(clientsecrets.InvalidClientSecretsError):
                appengine.OAuth2DecoratorFromClientSecrets(
                    'doesntmatter.json',
                    scope=['foo_scope', 'bar_scope'])
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def test_decorator_from_client_secrets_toplevel(self):
        decorator_patch = mock.patch(
            'oauth2client.contrib.appengine.OAuth2DecoratorFromClientSecrets')

        with decorator_patch as decorator_mock:
            filename = datafile('client_secrets.json')
            appengine.oauth2decorator_from_clientsecrets(
                filename, scope='foo_scope')
            decorator_mock.assert_called_once_with(
                filename,
                'foo_scope',
                cache=None,
                message=None)
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def test_decorator_from_client_secrets_bad_type(self):
        # NOTE: this code path is not currently reachable, as the only types
        # that oauth2client.clientsecrets can load is web and installed, so
        # this test forces execution of this code path. Despite not being
        # normally reachable, this should remain in case future types of
        # credentials are added.

        loadfile_patch = mock.patch(
            'oauth2client.contrib.appengine.clientsecrets.loadfile')
        with loadfile_patch as loadfile_mock:
            loadfile_mock.return_value = ('badtype', None)
            with self.assertRaises(clientsecrets.InvalidClientSecretsError):
                appengine.OAuth2DecoratorFromClientSecrets(
                    'doesntmatter.json',
                    scope=['foo_scope', 'bar_scope'])