当前位置: 首页>>代码示例>>Python>>正文


Python Testbed.get_stub方法代码示例

本文整理汇总了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={}):
开发者ID:kaisellgren,项目名称:pub-dartlang,代码行数:70,代码来源:testcase.py


注:本文中的google.appengine.ext.testbed.Testbed.get_stub方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。