本文整理汇总了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()
示例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)
示例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
示例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)
示例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()
示例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]
示例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)])
示例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()
示例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()
示例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)
示例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)()
示例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()
示例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)
示例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
示例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)