Python google.appengine.ext.testbed.TASKQUEUE_SERVICE_NAME Examples

The following are 30 code examples of google.appengine.ext.testbed.TASKQUEUE_SERVICE_NAME(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module google.appengine.ext.testbed , or try the search function .
Example #1
Source File: pullcounter_test.py    From python-docs-samples with Apache License 2.0 7 votes vote down vote up
def test_app(testbed):
    key_name = 'foo'

    testbed.init_taskqueue_stub(root_path=os.path.dirname(__file__))

    app = webtest.TestApp(main.app)
    app.post('/', {'key': key_name})

    tq_stub = testbed.get_stub(gaetestbed.TASKQUEUE_SERVICE_NAME)
    tasks = tq_stub.get_filtered_tasks()
    assert len(tasks) == 1
    assert tasks[0].name == 'task1'

    with mock.patch('main.update_counter') as mock_update:
        # Force update to fail, otherwise the loop will go forever.
        mock_update.side_effect = RuntimeError()

        app.get('/_ah/start', status=500)

        assert mock_update.called 
Example #2
Source File: __init__.py    From sndlatr with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        self.testbed = testbed.Testbed()

        self.testbed.activate()
        self.testbed.init_user_stub()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_urlfetch_stub()
        self.testbed.init_mail_stub()
        self.testbed.init_taskqueue_stub(
            root_path=os.path.join(os.path.dirname(__file__), '..'))
        self.addCleanup(self.testbed.deactivate)

        self.taskqueue_stub = self.testbed.get_stub(
            testbed.TASKQUEUE_SERVICE_NAME)
        self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)

        urlfetch = self.testbed.get_stub('urlfetch')
        urlfetch._RetrieveURL = self.retrieve_mock
        self._response_queue = []
        self.patch_xsrf() 
Example #3
Source File: base_test.py    From graphene-gae with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUp(self):
        super(BaseTest, self).setUp()

        root_path = '.'
        application_id = 'graphene-gae-test'

        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.setup_env(app_id=application_id, overwrite=True)
        policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=self.datastore_probability)
        self.testbed.init_datastore_v3_stub(root_path=root_path, consistency_policy=policy, require_indexes=True)
        self.testbed.init_app_identity_stub()
        self.testbed.init_blobstore_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub(root_path=root_path)
        self.testbed.init_urlfetch_stub()
        self.storage = cloudstorage_stub.CloudStorageStub(self.testbed.get_stub('blobstore').storage)
        self.testbed.init_mail_stub()
        self.testbed.init_user_stub()
        self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)

        ndb.get_context().clear_cache()
        ndb.get_context().set_cache_policy(lambda x: True) 
Example #4
Source File: bigquery_handler_test.py    From gcp-census with Apache License 2.0 5 votes vote down vote up
def init_webtest(self):
        self.under_test = webtest.TestApp(routes.app)
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_memcache_stub()

        path = os.path.join(os.path.dirname(__file__), '../config')
        logging.debug("queue.yaml path: %s", path)
        self.testbed.init_taskqueue_stub(root_path=path)
        self.taskqueue_stub = self.testbed.get_stub(
            testbed.TASKQUEUE_SERVICE_NAME)
        self.testbed.init_app_identity_stub() 
Example #5
Source File: appengine.py    From python-repo-tools with Apache License 2.0 5 votes vote down vote up
def setup_testbed():
    """Sets up the GAE testbed and enables common stubs."""
    from google.appengine.datastore import datastore_stub_util
    from google.appengine.ext import testbed as gaetestbed

    # Setup the datastore and memcache stub.
    # First, create an instance of the Testbed class.
    tb = gaetestbed.Testbed()
    # Then activate the testbed, which prepares the service stubs for
    # use.
    tb.activate()
    # Create a consistency policy that will simulate the High
    # Replication consistency model.
    policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
        probability=1.0)
    # Initialize the datastore stub with this policy.
    tb.init_datastore_v3_stub(
        datastore_file=tempfile.mkstemp()[1],
        consistency_policy=policy)
    tb.init_memcache_stub()

    # Setup remaining stubs.
    tb.init_urlfetch_stub()
    tb.init_app_identity_stub()
    tb.init_blobstore_stub()
    tb.init_user_stub()
    tb.init_logservice_stub()
    # tb.init_taskqueue_stub(root_path='tests/resources')
    tb.init_taskqueue_stub()
    tb.taskqueue_stub = tb.get_stub(gaetestbed.TASKQUEUE_SERVICE_NAME)

    return tb 
Example #6
Source File: appengine_helper.py    From python-docs-samples with Apache License 2.0 5 votes vote down vote up
def setup_testbed():
    """Sets up the GAE testbed and enables common stubs."""
    from google.appengine.datastore import datastore_stub_util
    from google.appengine.ext import testbed as gaetestbed

    # Setup the datastore and memcache stub.
    # First, create an instance of the Testbed class.
    tb = gaetestbed.Testbed()
    # Then activate the testbed, which prepares the service stubs for
    # use.
    tb.activate()
    # Create a consistency policy that will simulate the High
    # Replication consistency model.
    policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
        probability=1.0)
    # Initialize the datastore stub with this policy.
    tb.init_datastore_v3_stub(
        datastore_file=tempfile.mkstemp()[1],
        consistency_policy=policy)
    tb.init_memcache_stub()

    # Setup remaining stubs.
    tb.init_urlfetch_stub()
    tb.init_app_identity_stub()
    tb.init_blobstore_stub()
    tb.init_user_stub()
    tb.init_logservice_stub()
    # tb.init_taskqueue_stub(root_path='tests/resources')
    tb.init_taskqueue_stub()
    tb.taskqueue_stub = tb.get_stub(gaetestbed.TASKQUEUE_SERVICE_NAME)

    return tb 
Example #7
Source File: task_queue_test.py    From python-docs-samples with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()

        # root_path must be set the the location of queue.yaml.
        # Otherwise, only the 'default' queue will be available.
        self.testbed.init_taskqueue_stub(
            root_path=os.path.join(os.path.dirname(__file__), 'resources'))
        self.taskqueue_stub = self.testbed.get_stub(
            testbed.TASKQUEUE_SERVICE_NAME) 
Example #8
Source File: loanertest.py    From loaner with Apache License 2.0 5 votes vote down vote up
def setUp(self):
    """Set up the environment for testing."""
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_user_stub()
    self.testbed.init_search_stub()
    self.testbed.init_taskqueue_stub()
    self.login_user()

    taskqueue_patcher = mock.patch.object(taskqueue, 'add')
    self.addCleanup(taskqueue_patcher.stop)
    self.taskqueue_add = taskqueue_patcher.start()
    self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)

    # The events.raise_event method raises an exception if there are no events
    # in datastore. It's called often in the model methods, many of which are
    # used in testing. When you want to test raise_event specifically, first run
    # stop() on this patcher; be sure to run start() again before end of test.
    def side_effect(event_name, device=None, shelf=None):
      """Side effect for raise_event that returns the model."""
      del event_name  # Unused.
      if device:
        return device
      else:
        return shelf

    self.testbed.mock_raiseevent = mock.Mock(side_effect=side_effect)
    self.testbed.raise_event_patcher = mock.patch.object(
        events, 'raise_event', self.testbed.mock_raiseevent)
    self.addCleanup(self.testbed.raise_event_patcher.stop)
    self.testbed.raise_event_patcher.start() 
Example #9
Source File: test_scheduler.py    From example_dataproc_twitter with MIT License 5 votes vote down vote up
def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_taskqueue_stub('./gae/')
        self.taskqueue_stub = self.testbed.get_stub(
            testbed.TASKQUEUE_SERVICE_NAME) 
Example #10
Source File: main_test.py    From professional-services with Apache License 2.0 5 votes vote down vote up
def setUp(self):
    self.app = webtest.TestApp(main.app)
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_taskqueue_stub(
      root_path=os.path.join(os.path.dirname(__file__), '../'))
    self.taskqueue_stub = self.testbed.get_stub(
      testbed.TASKQUEUE_SERVICE_NAME) 
Example #11
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #12
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #13
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #14
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #15
Source File: basetest.py    From upvote with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the App Engine stubs."""
    # Evil os-environ patching which mirrors dev_appserver and production.
    # This patch turns os.environ into a thread-local object, which also happens
    # to support storing more than just strings. This patch must come first.
    self._old_os_environ = os.environ.copy()
    request_environment.current_request.Clear()
    request_environment.PatchOsEnviron()
    os.environ.update(self._old_os_environ)

    # Setup and activate the testbed.
    self.InitTestbed()

    # Register the search stub (until included in init_all_stubs).
    if (simple_search_stub and
        apiproxy_stub_map.apiproxy.GetStub('search') is None):
      self.search_stub = simple_search_stub.SearchServiceStub()
      apiproxy_stub_map.apiproxy.RegisterStub('search', self.search_stub)

    # Fake an always strongly-consistent HR datastore.
    policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
    self.testbed.init_datastore_v3_stub(consistency_policy=policy)
    self.datastore_stub = self.testbed.get_stub(testbed.DATASTORE_SERVICE_NAME)

    # Save the taskqueue_stub for use in RunDeferredTasks.
    self.testbed.init_taskqueue_stub(_all_queues_valid=True)
    self.taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)

    # Save other stubs for use in helper methods and tests.
    self.users_stub = self.testbed.get_stub(testbed.USER_SERVICE_NAME)
    self.channel_stub = self.testbed.get_stub(testbed.CHANNEL_SERVICE_NAME)

    # Each time setUp is called, treat it like a different request to a
    # different app instance.
    request_id_hash = ''.join(random.sample(string.letters + string.digits, 26))
    instance_id = ''.join(random.sample(string.letters + string.digits, 26))
    # More like the production environment: "testbed-version.123123123", rather
    # than the default "testbed-version".
    current_version_id = 'testbed-version.%s' % random.randint(1, 1000000000000)
    self.testbed.setup_env(
        request_id_hash=request_id_hash, instance_id=instance_id,
        current_version_id=current_version_id, overwrite=True)

    self.Logout()
    super(AppEngineTestCase, self).setUp() 
Example #16
Source File: testutil.py    From appengine-mapreduce with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    unittest.TestCase.setUp(self)
    self.mox = mox.Mox()

    self.appid = "testapp"
    self.major_version_id = "1"
    self.version_id = self.major_version_id + ".23456789"
    self.module_id = "foo_module"
    self.host = "%s.%s.%s" % (
        self.major_version_id, self.module_id, "testapp.appspot.com")

    self.testbed = testbed.Testbed()
    self.testbed.activate()

    os.environ["APPLICATION_ID"] = self.appid
    os.environ["CURRENT_VERSION_ID"] = self.version_id
    os.environ["CURRENT_MODULE_ID"] = self.module_id
    os.environ["DEFAULT_VERSION_HOSTNAME"] = "%s.appspot.com" % self.appid
    os.environ["HTTP_HOST"] = self.host

    self.testbed.init_app_identity_stub()
    self.testbed.init_blobstore_stub()
    # HRD with no eventual consistency.
    policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
    self.testbed.init_datastore_v3_stub(consistency_policy=policy)
    self.testbed.init_logservice_stub()
    self.testbed.init_files_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_taskqueue_stub()
    self.testbed.init_urlfetch_stub()

    # For backwards compatibility, maintain easy references to some stubs
    self.taskqueue = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)

    self.taskqueue.queue_yaml_parser = (
        # pylint: disable=g-long-lambda
        lambda x: queueinfo.LoadSingleQueue(
            "queue:\n"
            "- name: default\n"
            "  rate: 10/s\n"
            "- name: crazy-queue\n"
            "  rate: 2000/d\n"
            "  bucket_size: 10\n")) 
Example #17
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #18
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #19
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #20
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #21
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #22
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #23
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #24
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #25
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #26
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #27
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #28
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #29
Source File: test_case.py    From luci-py with Apache License 2.0 4 votes vote down vote up
def setUp(self):
    """Initializes the commonly used stubs.

    Using init_all_stubs() costs ~10ms more to run all the tests so only enable
    the ones known to be required. Test cases requiring more stubs can enable
    them in their setUp() function.
    """
    super(TestCase, self).setUp()
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    # If you have a NeedIndexError, here is the switch you need to flip to make
    # the new required indexes to be automatically added. Change
    # train_index_yaml to True to have index.yaml automatically updated, then
    # run your test case. Do not forget to put it back to False.
    train_index_yaml = False

    if self.SKIP_INDEX_YAML_CHECK:
      # See comment for skip_index_yaml_check above.
      self.assertIsNone(self.APP_DIR)

    self.testbed.init_app_identity_stub()
    self.testbed.init_datastore_v3_stub(
        require_indexes=not train_index_yaml and not self.SKIP_INDEX_YAML_CHECK,
        root_path=self.APP_DIR,
        consistency_policy=datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1))
    self.testbed.init_logservice_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_modules_stub()

    # Use mocked time in memcache.
    memcache = self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME)
    memcache._gettime = lambda: int(utils.time_time())

    # Email support.
    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
    self.old_send_to_admins = self.mock(
        self.mail_stub, '_Dynamic_SendToAdmins', self._SendToAdmins)

    self.testbed.init_taskqueue_stub()
    self._taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    self._taskqueue_stub._root_path = self.APP_DIR

    self.testbed.init_user_stub() 
Example #30
Source File: nosegae.py    From NoseGAE with BSD 2-Clause "Simplified" License 4 votes vote down vote up
def startTest(self, test):
        """Initializes Testbed stubs based off of attributes of the executing test

        allow tests to register and configure stubs by setting properties like
        nosegae_<stub_name> and nosegae_<stub_name>_kwargs

        Example

        class MyTest(unittest.TestCase):
            nosegae_datastore_v3 = True
            nosegae_datastore_v3_kwargs = {
              'datastore_file': '/tmp/nosegae.sqlite3,
              'use_sqlite': True
            }

            def test_something(self):
               entity = MyModel(name='NoseGAE')
               entity.put()
               self.assertNotNone(entity.key.id())

        Args
            :param test: The unittest.TestCase being run
            :type test: unittest.TestCase
        """
        from google.appengine.ext import testbed

        self._add_missing_stubs(testbed)

        self.testbed = testbed.Testbed()
        self.testbed.activate()
        # Give the test access to the active testbed
        the_test = test.test
        if isinstance(the_test, FunctionTestCase):
            the_test = the_test.test
        the_test.testbed = self.testbed

        for stub_name, stub_init in testbed.INIT_STUB_METHOD_NAMES.iteritems():
            if not getattr(the_test, 'nosegae_%s' % stub_name, False):
                continue
            stub_kwargs = getattr(the_test, 'nosegae_%s_kwargs' % stub_name, {})
            if stub_name == testbed.TASKQUEUE_SERVICE_NAME:
                self._init_taskqueue_stub(**stub_kwargs)
            elif stub_name == testbed.DATASTORE_SERVICE_NAME:
                if not self.testbed.get_stub(testbed.MEMCACHE_SERVICE_NAME):
                    # ndb requires memcache so enable it as well as the datastore_v3
                    self.testbed.init_memcache_stub()
                self._init_datastore_v3_stub(**stub_kwargs)
            elif stub_name == testbed.USER_SERVICE_NAME:
                self._init_user_stub(**stub_kwargs)
            elif stub_name == testbed.MODULES_SERVICE_NAME:
                self._init_modules_stub(**stub_kwargs)
            else:
                self._init_stub(stub_init, **stub_kwargs)

        if self.is_doctests:
            self._doctest_compat(the_test)
        self.the_test = the_test