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


Python testbed.Testbed方法代碼示例

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


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

示例1: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
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() 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:23,代碼來源:__init__.py

示例2: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
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) 
開發者ID:graphql-python,項目名稱:graphene-gae,代碼行數:26,代碼來源:base_test.py

示例3: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
    SetupLogging()
    self._testbed = testbed.Testbed()
    self._testbed.activate()
    self._testbed.setup_env(overwrite=True, USER_EMAIL=_ADMIN_USER_EMAIL,
                            USER_ID='1', USER_IS_ADMIN='1')
    self._testbed.init_user_stub()
    self._testbed.init_memcache_stub()

    # Fake the admin checks.
    frontend_views._CacheUserEmailBillingEnabled(_ADMIN_USER_EMAIL)
    frontend_views._CacheUserEmailAsAdmin(_ADMIN_USER_EMAIL)

    # Derived classes need to set this as follows for tests:
    #
    #   self._testapp = webtest.TestApp(webapp2.WSGIApplication([
    #       (r'/about', frontend_views.AboutPageHandler),
    #       ], debug=True))
    self._testapp = None 
開發者ID:google,項目名稱:googleapps-message-recall,代碼行數:21,代碼來源:app_handler_test_base.py

示例4: main

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def main():
  utils.tweak_logging()  # Interpret -v and -q flags.

  tb = testbed.Testbed()
  tb.activate()
  tb.init_datastore_v3_stub()
  tb.init_memcache_stub()

  n = 1000
  for arg in sys.argv[1:]:
    try:
      n = int(arg)
      break
    except Exception:
      pass

  populate(n)

  profiler(bench, n) 
開發者ID:GoogleCloudPlatform,項目名稱:datastore-ndb-python,代碼行數:21,代碼來源:dbench.py

示例5: cause_problem

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def cause_problem():
  tb = testbed.Testbed()
  tb.activate()
  tb.init_datastore_v3_stub()
  tb.init_memcache_stub()
  ctx = tasklets.make_default_context()
  tasklets.set_context(ctx)
  ctx.set_datastore_policy(True)
  ctx.set_cache_policy(False)
  ctx.set_memcache_policy(True)

  @tasklets.tasklet
  def problem_tasklet():
    class Foo(model.Model):
      pass
    key = yield ctx.put(Foo())
    yield ctx.get(key)  # Trigger get_tasklet that does not complete...
    yield ctx.delete(key)  # ... by the time this delete_tasklet starts.
    a = yield ctx.get(key)
    assert a is None, '%r is not None' % a

  problem_tasklet().check_success()
  print 'No problem yet...'
  tb.deactivate() 
開發者ID:GoogleCloudPlatform,項目名稱:datastore-ndb-python,代碼行數:26,代碼來源:gettaskletrace.py

示例6: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        # Clear ndb's in-context cache between tests.
        # This prevents data from leaking between tests.
        # Alternatively, you could disable caching by
        # using ndb.get_context().set_cache_policy(False)
        ndb.get_context().clear_cache()

# [END datastore_example_test]

    # [START datastore_example_teardown] 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:19,代碼來源:datastore_test.py

示例7: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.app = webapp2.WSGIApplication([('/', DummyHandler),
                                        ('/ajax', DummyAjaxHandler),
                                        ('/cron', DummyCronHandler),
                                        ('/task', DummyTaskHandler)]) 
開發者ID:google,項目名稱:gae-secure-scaffold-python,代碼行數:11,代碼來源:handlers_test.py

示例8: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
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() 
開發者ID:google,項目名稱:loaner,代碼行數:36,代碼來源:loanertest.py

示例9: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub() 
開發者ID:google,項目名稱:gae-secure-scaffold-python,代碼行數:6,代碼來源:models_test.py

示例10: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
    # Wrap the app with WebTest's TestApp.
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_memcache_stub()
    self.testbed.init_datastore_v3_stub()
    from main import app
    self.testapp = TestApp(app) 
開發者ID:lipis,項目名稱:github-stats,代碼行數:10,代碼來源:quick_test.py

示例11: _SetupStubs

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def _SetupStubs():
  tb = testbed.Testbed()
  tb.setup_env(CURRENT_VERSION_ID='1.0')
  tb.activate()
  for k, v in testbed.INIT_STUB_METHOD_NAMES.iteritems():
    # The old stub initialization code didn't support the image service at all
    # so we just ignore it here.
    if k != 'images':
      getattr(tb, v)() 
開發者ID:cloudendpoints,項目名稱:endpoints-python,代碼行數:11,代碼來源:_endpointscfg_impl.py

示例12: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
    # First, create an instance of the Testbed class.
    self.testbed = testbed.Testbed()
    # Then activate the testbed, which prepares the service stubs for use.
    self.testbed.activate()
    # Next, declare which service stubs you want to use.
    self.testbed.init_datastore_v3_stub() 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:9,代碼來源:test_Model.py

示例13: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()

    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.testbed.init_urlfetch_stub()

    self.testbed.init_mail_stub()
    self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)

    self.mockery = mox.Mox()
    self.stripe = self.mockery.CreateMock(handlers.StripeBackend)
    self.mailing_list_subscriber = self.mockery.CreateMock(
      handlers.MailingListSubscriber)
    self.mail_sender = env.MailSender(defer=False)

    self.env = handlers.Environment(
      app_name='unittest',
      stripe_public_key='pubkey1234',
      stripe_backend=self.stripe,
      mailing_list_subscriber=self.mailing_list_subscriber,
      mail_sender=self.mail_sender)

    from main import HANDLERS  # main import must come after other init
    self.wsgi_app = webapp2.WSGIApplication(HANDLERS + handlers.HANDLERS,
                                            config=dict(env=self.env))

    self.app = webtest.TestApp(self.wsgi_app) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:31,代碼來源:test_e2e.py

示例14: setup_module

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setup_module():
    """Set up tests (used by e.g. nosetests) for the module - loaded once"""
    from google.appengine.ext import testbed
    global _appengine_testbed
    tb = testbed.Testbed()
    tb.activate()
    tb.setup_env()
    tb.init_datastore_v3_stub()
    tb.init_memcache_stub()

    _appengine_testbed = tb 
開發者ID:Schibum,項目名稱:sndlatr,代碼行數:13,代碼來源:__init__.py

示例15: setUp

# 需要導入模塊: from google.appengine.ext import testbed [as 別名]
# 或者: from google.appengine.ext.testbed import Testbed [as 別名]
def setUp(self):
    #logging.basicConfig(level=logging.DEBUG)
    self.testbed = testbed.Testbed()
    self.testbed.setup_env(app_id='_')
    self.testbed.activate()
    self.testbed.init_all_stubs()
    main.UseLocalGCS()
    self.LoadTestData()
    app = webapp2.WSGIApplication([('/objectChangeNotification',
                                    main.ObjectChangeNotification)])
    self.testapp = webtest.TestApp(app) 
開發者ID:googlearchive,項目名稱:billing-export-python,代碼行數:13,代碼來源:test.py


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