本文整理匯總了Python中google.appengine.api.users.User方法的典型用法代碼示例。如果您正苦於以下問題:Python users.User方法的具體用法?Python users.User怎麽用?Python users.User使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.api.users
的用法示例。
在下文中一共展示了users.User方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def setUp(self):
super(LoanerEndpointsTest, self).setUp()
self.service = FakeApiPermissionChecks()
self.request = message_types.VoidMessage()
user_model.Role.create(
'technical_admin',
role_permissions=[permissions.Permissions.AUDIT_SHELF],
associated_group=loanertest.TECHNICAL_ADMIN_EMAIL)
user_model.User(
id=loanertest.SUPER_ADMIN_EMAIL, superadmin=True).put()
user_model.User(
id=loanertest.TECHNICAL_ADMIN_EMAIL,
roles=[ndb.Key(user_model.Role, 'technical_admin')]).put()
user_model.User(id=loanertest.USER_EMAIL).put()
示例2: call_test_as
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def call_test_as(self, api_name, user):
"""Makes a call FakeApiPermissionChecks APIs with different users.
Args:
api_name: str, the name of the test API to call.
user: users.User obj, the App Engine API users object being checked.
Returns:
True if permission or user auth passed the call to the API.
"""
with mock.patch.object(
xsrf, 'validate_request') as mock_validate_request:
mock_validate_request.return_value = True
with mock.patch.object(users, 'get_current_user') as mock_user:
mock_user.return_value = user
api_method = getattr(self.service, api_name)
if api_method(self.request) == message_types.VoidMessage():
return True
示例3: test_loaner_endpoints_auth_method__api_for_any_authenticated_user
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def test_loaner_endpoints_auth_method__api_for_any_authenticated_user(
self, mock_config):
# Test api_with_permission with a user.
user = users.User(email=loanertest.USER_EMAIL)
self.assertTrue(self.call_test_as('api_for_any_authenticated_user', user))
# Test api_for_any_authenticated_user with permission.
user = users.User(email=loanertest.TECHNICAL_ADMIN_EMAIL)
self.assertTrue(self.call_test_as('api_for_any_authenticated_user', user))
# Test api_for_any_authenticated_user with the superadmin.
user = users.User(email=loanertest.SUPER_ADMIN_EMAIL)
self.assertTrue(self.call_test_as('api_for_any_authenticated_user', user))
# Test invalid domain.
user = users.User(email='userl@fakedomain.com')
with self.assertRaises(endpoints.UnauthorizedException):
self.call_test_as('api_for_any_authenticated_user', user)
示例4: VerifyIdToken
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def VerifyIdToken(self, cls, *args):
with mock.patch.object(users_id_token, 'time') as mock_time,\
mock.patch.object(users_id_token, '_get_id_token_user') as mock_get:
mock_time.time.return_value = 1001
mock_get.return_value = users.User('test@gmail.com')
os.environ['HTTP_AUTHORIZATION'] = ('Bearer ' + self._SAMPLE_TOKEN)
if args:
cls.method(*args)
else:
users_id_token._maybe_set_current_user_vars(cls.method)
mock_time.time.assert_called_once_with()
mock_get.assert_called_once_with(
self._SAMPLE_TOKEN,
users_id_token._DEFAULT_GOOGLE_ISSUER,
self._SAMPLE_AUDIENCES,
(constants.API_EXPLORER_CLIENT_ID,) + self._SAMPLE_ALLOWED_CLIENT_IDS,
1001,
memcache,
)
示例5: __init__
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def __init__(self, model, key_name, property_name, cache=None, user=None):
"""Constructor for Storage.
Args:
model: db.Model or ndb.Model, model class
key_name: string, key name for the entity that has the credentials
property_name: string, name of the property that is a CredentialsProperty
or CredentialsNDBProperty.
cache: memcache, a write-through cache to put in front of the datastore.
If the model you are using is an NDB model, using a cache will be
redundant since the model uses an instance cache and memcache for you.
user: users.User object, optional. Can be used to grab user ID as a
key_name if no key name is specified.
"""
if key_name is None:
if user is None:
raise ValueError('StorageByKeyName called with no key name or user.')
key_name = user.user_id()
self._model = model
self._key_name = key_name
self._property_name = property_name
self._cache = cache
示例6: _build_state_value
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def _build_state_value(request_handler, user):
"""Composes the value for the 'state' parameter.
Packs the current request URI and an XSRF token into an opaque string that
can be passed to the authentication server via the 'state' parameter.
Args:
request_handler: webapp.RequestHandler, The request.
user: google.appengine.api.users.User, The current user.
Returns:
The state value as a string.
"""
uri = request_handler.request.url
token = xsrfutil.generate_token(xsrf_secret_key(), user.user_id(),
action_id=str(uri))
return uri + ':' + token
示例7: _parse_state_value
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def _parse_state_value(state, user):
"""Parse the value of the 'state' parameter.
Parses the value and validates the XSRF token in the state parameter.
Args:
state: string, The value of the state parameter.
user: google.appengine.api.users.User, The current user.
Raises:
InvalidXsrfTokenError: if the XSRF token is invalid.
Returns:
The redirect URI.
"""
uri, token = state.rsplit(':', 1)
if not xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(),
action_id=uri):
raise InvalidXsrfTokenError()
return uri
示例8: _build_state_value
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def _build_state_value(request_handler, user):
"""Composes the value for the 'state' parameter.
Packs the current request URI and an XSRF token into an opaque string that
can be passed to the authentication server via the 'state' parameter.
Args:
request_handler: webapp.RequestHandler, The request.
user: google.appengine.api.users.User, The current user.
Returns:
The state value as a string.
"""
uri = request_handler.request.url
token = xsrfutil.generate_token(xsrf_secret_key(), user.user_id(),
action_id=str(uri))
return uri + ':' + token
示例9: _parse_state_value
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def _parse_state_value(state, user):
"""Parse the value of the 'state' parameter.
Parses the value and validates the XSRF token in the state parameter.
Args:
state: string, The value of the state parameter.
user: google.appengine.api.users.User, The current user.
Raises:
InvalidXsrfTokenError: if the XSRF token is invalid.
Returns:
The redirect URI.
"""
uri, token = state.rsplit(':', 1)
if not xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(),
action_id=uri):
raise InvalidXsrfTokenError()
return uri
示例10: _parse_state_value
# 需要導入模塊: from google.appengine.api import users [as 別名]
# 或者: from google.appengine.api.users import User [as 別名]
def _parse_state_value(state, user):
"""Parse the value of the 'state' parameter.
Parses the value and validates the XSRF token in the state parameter.
Args:
state: string, The value of the state parameter.
user: google.appengine.api.users.User, The current user.
Returns:
The redirect URI, or None if XSRF token is not valid.
"""
uri, token = state.rsplit(':', 1)
if xsrfutil.validate_token(xsrf_secret_key(), token, user.user_id(),
action_id=uri):
return uri
else:
return None