本文整理汇总了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={}):