本文整理匯總了Python中google.appengine.ext.testbed.Testbed.get_stub方法的典型用法代碼示例。如果您正苦於以下問題:Python Testbed.get_stub方法的具體用法?Python Testbed.get_stub怎麽用?Python Testbed.get_stub使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類google.appengine.ext.testbed.Testbed
的用法示例。
在下文中一共展示了Testbed.get_stub方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestCase
# 需要導入模塊: from google.appengine.ext.testbed import Testbed [as 別名]
# 或者: from google.appengine.ext.testbed.Testbed import get_stub [as 別名]
#.........這裏部分代碼省略.........
self.testbed.setup_env(
oauth_error_code=str(UserServiceError.OAUTH_INVALID_REQUEST),
oauth_error_detail='',
oauth_last_scope='https://www.googleapis.com/auth/userinfo.email')
def be_normal_oauth_user(self, name=None):
"""Log in as a non-admin OAuth user.
Arguments:
name: A string to distinguish this user from others. Users with
different names will be distinct, and the same name will always
refer to the same user. Admin users have a separate namespace from
non-admin users.
"""
try: del os.environ['OAUTH_ERROR_CODE']
except KeyError: pass
self.set_oauth_user(self.normal_user(name))
def be_admin_oauth_user(self, name=None):
"""Log in as an admin OAuth user.
Arguments:
name: A string to distinguish this user from others. Users with
different names will be distinct, and the same name will always
refer to the same user. Admin users have a separate namespace from
non-admin users.
"""
try: del os.environ['OAUTH_ERROR_CODE']
except KeyError: pass
self.set_oauth_user(self.admin_user(name))
def set_oauth_user(self, user):
"""Set the user that is logged in via OAuth."""
self.testbed.get_stub(USER_SERVICE_NAME).SetOAuthUser(
email=user.email(),
user_id=user.user_id() or '0',
is_admin=user.email().startswith('test-admin'))
def create_package(self, name, version):
"""Create and save a package object with a version."""
Package.new(name=name, uploaders=[users.get_current_user()]).put()
self.set_latest_version(name, version)
def set_latest_version(self, package_name, version):
"""Set the latest version of the given package."""
package = Package.get_by_key_name(package_name)
package.latest_version = self.package_version(package, version)
package.latest_version.put()
package.put()
def package_version(self, package, version,
**additional_pubspec_fields):
"""Create a package version object.
This constructs the package archive based on the other information
passed in. The archive contains only the pubspec.
"""
pubspec = Pubspec(name=package.name, version=version)
pubspec.update(additional_pubspec_fields)
return PackageVersion.new(
version=version,
package=package,
pubspec=pubspec,
uploader=package.uploaders[0])
def tar_package(self, pubspec, files={}):