當前位置: 首頁>>代碼示例>>Python>>正文


Python Testbed.init_blobstore_stub方法代碼示例

本文整理匯總了Python中google.appengine.ext.testbed.Testbed.init_blobstore_stub方法的典型用法代碼示例。如果您正苦於以下問題:Python Testbed.init_blobstore_stub方法的具體用法?Python Testbed.init_blobstore_stub怎麽用?Python Testbed.init_blobstore_stub使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在google.appengine.ext.testbed.Testbed的用法示例。


在下文中一共展示了Testbed.init_blobstore_stub方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestCase

# 需要導入模塊: from google.appengine.ext.testbed import Testbed [as 別名]
# 或者: from google.appengine.ext.testbed.Testbed import init_blobstore_stub [as 別名]
class TestCase(unittest.TestCase):
    """Utility methods for testing.

    This class should be used as the superclass of all other test classes. It
    sets up the necessary test stubs and provides various utility methods to use
    in tests.
    """

    def setUp(self):
        """Initialize stubs for testing.

        This initializes the following fields:
          self.testbed: An App Engine Testbed used for mocking App Engine
            services. This is activated, and any necessary stubs are
            initialized.
          self.testapp: A webtest.TestApp wrapping the CherryPy application.

        Subclasses that define their own setUp method should be sure to call
        this one as well.
        """

        self.__users = {}
        self.__admins = {}

        self.testbed = Testbed()
        self.testbed.activate()
        self.testbed.init_app_identity_stub()
        self.testbed.init_blobstore_stub()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_files_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub()
        self.testbed.init_user_stub()

        self.testapp = webtest.TestApp(Application())

        # Pretend we are running on AppEngine so that things like the error
        # page that behave differently when run locally act like they do in
        # production.
        os.environ['SERVER_SOFTWARE'] = 'Google App Engine/TESTING'

        # This private key is not actually used for anything other than testing.
        PrivateKey.set('''-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,CEB8C6541017AC8B

q1SgqAfgHXK5cQvtdIF8rkSlbAS6a92T5tYMVKJIW24giF5cw+1++X7X6S5ECykC
/iECExP7WfVlPDVoJMZpWGsYLMPhxncnKfUDICbVgwsO4KKeEv8lYTrvkY1sCZIx
kSja/lGAWpyxBnmxwoLh0LbLJBGUxUgn2Uqv/8Iid+w0m3NlgrllV+kOo4gUYF9q
bestH4nEQj6F0CeI8VPW0FxzMwn0vreHFBT5hul6xbNdB1vnRcz6ed4FiGXoAB5K
/8/Q2qyy1UPe2Hr9IoC6wo4h2kXq7pmhy/rtzU9/gjsGPD33ByavbgHAen0ajY5p
RmCx0AGidK9T6/SNoyDD9CMq7ypL+0JWoCeVoAEw2aZqN4rMJNbKMgPH+ajgiAXe
AWuMVjWN6uTL5+QJmWQct6a6TF8GPKdTcOZfNIXU5U9drHB2hggLcy6XkCYGjVJv
MvLascE4oAtOHnwz7WhrpcmX6F6Fww+TPnFzjk+IGJrnBUnAArEcM13IjiDUgg9B
iLuKimwrqasdBBY3Ua3SRMoG8PJoNKdsk1hDGlpxLnqOVUCvPKZuz4QnFusnUJrR
kiv+aqVBpZYymMh2Q1MWcogA7rL7LIowAkyLzS8dNwDhyk9jbO+1uoFSHKr5BTNv
cMJfCVm8pqhXwCVx3uYnhUzvth7mcEseXh5Dcg1RHka5rCXUz4eVxTkj1u3FOy9o
9jgARPpnDYsXH1lESxmiNZucHa50qI/ezNvQx8CbNa1/+JWoZ77yqM9qnDlXUwDY
1Sxqx9+4kthG9oyCzzUwFvhf1kTEHd0RfIapgjJ16HBQmzLnEPtjPA==
-----END RSA PRIVATE KEY-----''')

        self.dont_be_oauth_user()

    def tearDown(self):
        """Deactivates the stubs initialized in setUp.

        Subclasses that define their own tearDown method should be sure to call
        this one as well.
        """
        self.testbed.deactivate()

    def normal_user(self, name = None):
        """Constructs a non-admin user object.

        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.

        Returns: The user object.
        """

        if self.__users.has_key(name):
            return self.__users[name]

        email = '[email protected]'
        if name:
            email = 'test-user-%[email protected]' % name

        self.__users[name] = users.User(email = email)
        return self.__users[name]

    def admin_user(self, name = None):
        """Constructs an admin user object.

        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
#.........這裏部分代碼省略.........
開發者ID:kaisellgren,項目名稱:pub-dartlang,代碼行數:103,代碼來源:testcase.py

示例2: StubManager

# 需要導入模塊: from google.appengine.ext.testbed import Testbed [as 別名]
# 或者: from google.appengine.ext.testbed.Testbed import init_blobstore_stub [as 別名]
class StubManager(object):
    def __init__(self):
        self.testbed = None
        self.active_stubs = None
        self.pre_test_stubs = None

    def setup_stubs(self, connection):
        if self.active_stubs is not None:
            return
        if not have_appserver:
            self.activate_stubs(connection)

    def activate_stubs(self, connection):
        try:
            from google.appengine.tools import dev_appserver_main

            self.setup_local_stubs(connection)
        except ImportError:
            self.activate_test_stubs(connection)

    def reset_stubs(self, connection, datastore_path=None):
        if self.active_stubs == "test":
            self.deactivate_test_stubs()
            self.activate_test_stubs(connection, datastore_path)

        elif self.active_stubs == "local":
            self.setup_local_stubs(connection)

        elif self.active_stubs == "remote":
            self.setup_remote_stubs(connection)

    def activate_test_stubs(self, connection, datastore_path=None):
        if self.active_stubs == "test":
            return

        if self.testbed is None:
            from google.appengine.ext.testbed import Testbed

            self.testbed = Testbed()

        self.testbed.activate()
        self.pre_test_stubs = self.active_stubs
        self.active_stubs = "test"

        os.environ["APPLICATION_ID"] = "dev~" + appid
        os.environ["HTTP_HOST"] = "%s.appspot.com" % appid

        appserver_opts = connection.settings_dict.get("DEV_APPSERVER_OPTIONS", {})
        high_replication = appserver_opts.get("high_replication", False)
        require_indexes = appserver_opts.get("require_indexes", False)
        use_sqlite = appserver_opts.get("use_sqlite", False)

        datastore_opts = {"require_indexes": require_indexes, "use_sqlite": use_sqlite}

        if high_replication:
            from google.appengine.datastore import datastore_stub_util

            datastore_opts["consistency_policy"] = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)

        self.testbed.init_datastore_v3_stub(datastore_file=datastore_path, **datastore_opts)
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub(auto_task_running=True, root_path=PROJECT_DIR)
        self.testbed.init_urlfetch_stub()
        self.testbed.init_user_stub()
        self.testbed.init_xmpp_stub()
        self.testbed.init_channel_stub()
        self.testbed.init_app_identity_stub()
        self.testbed.init_blobstore_stub()
        self.testbed.init_files_stub()
        self.testbed.init_images_stub()

    def deactivate_test_stubs(self):
        if self.active_stubs == "test":
            self.testbed.deactivate()
            self.active_stubs = self.pre_test_stubs

    def setup_local_stubs(self, connection):
        if self.active_stubs == "local":
            return

        from .base import get_datastore_paths
        from google.appengine.tools import dev_appserver_main

        args = dev_appserver_main.DEFAULT_ARGS.copy()
        args.update(get_datastore_paths(connection.settings_dict))
        args.update(connection.settings_dict.get("DEV_APPSERVER_OPTIONS", {}))
        log_level = logging.getLogger().getEffectiveLevel()
        logging.getLogger().setLevel(logging.WARNING)

        try:
            from google.appengine.tools import dev_appserver
        except ImportError:
            from google.appengine.tools import old_dev_appserver as dev_appserver
        dev_appserver.SetupStubs("dev~" + appid, **args)
        logging.getLogger().setLevel(log_level)
        self.active_stubs = "local"

    def setup_remote_stubs(self, connection):
        if self.active_stubs == "remote":
            return
#.........這裏部分代碼省略.........
開發者ID:JohnDevitt,項目名稱:cloud_3.0,代碼行數:103,代碼來源:stubs.py


注:本文中的google.appengine.ext.testbed.Testbed.init_blobstore_stub方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。