fixtures.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:pytest-web2py.wip 作者: matclab 项目源码 文件源码
def gaebed(gae, gae_sdk_path, gae_probability, mocker):
    """ Prepare GAE testbed environment if necessary """
    if gae:
        if gae_sdk_path not in sys.path:
            sys.path.insert(0, gae_sdk_path)
        try:
            import appengine_config
        except ImportError:
            pass

        mocker.patch('google.appengine.api.mail.send_mail', autospec=True)
        APP_ID = 'lostre-test-1637'
        os.environ['APPLICATION_ID'] = APP_ID
        from google.appengine.api import apiproxy_stub_map, datastore_file_stub
        from google.appengine.datastore import datastore_stub_util
        from google.appengine.api.memcache import memcache_stub
        from google.appengine.api import urlfetch_stub

        policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=gae_probability)
        apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
        stub = datastore_file_stub.DatastoreFileStub(
            APP_ID, datastore_file=None, consistency_policy=policy)
        apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
        apiproxy_stub_map.apiproxy.RegisterStub(
            'memcache', memcache_stub.MemcacheServiceStub())
        apiproxy_stub_map.apiproxy.RegisterStub(
            'urlfetch', urlfetch_stub.URLFetchServiceStub())

        import google.appengine.tools.os_compat
        from google.appengine.ext import testbed
        from google.appengine.api import memcache
        from google.appengine.ext import ndb
        bed = testbed.Testbed()
        bed.activate()
        bed.init_datastore_v3_stub()
        bed.init_taskqueue_stub(True)
        bed.init_memcache_stub()
        bed.init_user_stub()
        bed.init_urlfetch_stub()
        bed.init_app_identity_stub(enable=True)
        ndb.get_context().clear_cache()
        from google.appengine.tools.devappserver2 import application_configuration
        # get the app id out of your app.yaml and stuff
        configuration = application_configuration.ApplicationConfiguration(
            ['.'])
        return bed
    else:
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号