本文整理汇总了Python中google.appengine.api.apiproxy_stub_map.apiproxy方法的典型用法代码示例。如果您正苦于以下问题:Python apiproxy_stub_map.apiproxy方法的具体用法?Python apiproxy_stub_map.apiproxy怎么用?Python apiproxy_stub_map.apiproxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google.appengine.api.apiproxy_stub_map
的用法示例。
在下文中一共展示了apiproxy_stub_map.apiproxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ResetModules
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def ResetModules(self):
"""Clear modules so that when request is run they are reloaded."""
lib_config._default_registry.reset()
self._modules.clear()
self._modules.update(self._default_modules)
sys.path_hooks[:] = self._save_path_hooks
sys.meta_path = []
apiproxy_stub_map.apiproxy.GetPreCallHooks().Clear()
apiproxy_stub_map.apiproxy.GetPostCallHooks().Clear()
示例2: _convert_datastore_file_stub_data_to_sqlite
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def _convert_datastore_file_stub_data_to_sqlite(app_id, datastore_path):
logging.info('Converting datastore stub data to sqlite.')
previous_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3')
try:
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
datastore_stub = datastore_file_stub.DatastoreFileStub(
app_id, datastore_path, trusted=True, save_changes=False)
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore_stub)
entities = _fetch_all_datastore_entities()
sqlite_datastore_stub = datastore_sqlite_stub.DatastoreSqliteStub(
app_id, datastore_path + '.sqlite', trusted=True)
apiproxy_stub_map.apiproxy.ReplaceStub('datastore_v3',
sqlite_datastore_stub)
datastore.Put(entities)
sqlite_datastore_stub.Close()
finally:
apiproxy_stub_map.apiproxy.ReplaceStub('datastore_v3', previous_stub)
shutil.copy(datastore_path, datastore_path + '.filestub')
os.remove(datastore_path)
shutil.move(datastore_path + '.sqlite', datastore_path)
logging.info('Datastore conversion complete. File stub data has been backed '
'up in %s', datastore_path + '.filestub')
示例3: activate
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def activate(self):
"""Activates the testbed.
Invoking this method will also assign default values to environment
variables that are required by App Engine services, such as
`os.environ['APPLICATION_ID']`. You can set custom values with
`setup_env()`.
"""
self._orig_env = dict(os.environ)
self.setup_env()
self._original_stub_map = apiproxy_stub_map.apiproxy
self._test_stub_map = apiproxy_stub_map.APIProxyStubMap()
internal_map = self._original_stub_map._APIProxyStubMap__stub_map
self._test_stub_map._APIProxyStubMap__stub_map = dict(internal_map)
apiproxy_stub_map.apiproxy = self._test_stub_map
self._activated = True
示例4: deactivate
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def deactivate(self):
"""Deactivates the testbed.
This method will restore the API proxy and environment variables to the
state they were in before `activate()` was called.
Raises:
NotActivatedError: If called before `activate()` was called.
"""
if not self._activated:
raise NotActivatedError('The testbed is not activated.')
for service_name, deactivate_callback in self._enabled_stubs.iteritems():
if deactivate_callback:
deactivate_callback(self._test_stub_map.GetStub(service_name))
apiproxy_stub_map.apiproxy = self._original_stub_map
self._enabled_stubs = {}
os.environ.clear()
os.environ.update(self._orig_env)
self._blob_storage = None
self._activated = False
示例5: testRawEntityTypeFromOtherApp
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def testRawEntityTypeFromOtherApp(self):
"""Test reading from other app."""
OTHER_KIND = "bar"
OTHER_APP = "foo"
apiproxy_stub_map.apiproxy.GetStub("datastore_v3").SetTrusted(True)
expected_keys = [str(i) for i in range(10)]
for k in expected_keys:
datastore.Put(datastore.Entity(OTHER_KIND, name=k, _app=OTHER_APP))
params = {
"entity_kind": OTHER_KIND,
"_app": OTHER_APP,
}
mapper_spec = model.MapperSpec(
"FooHandler",
"RawDatastoreInputReader",
params, 1)
itr = self.reader_cls.split_input(mapper_spec)[0]
self._assertEquals_splitInput(itr, expected_keys)
apiproxy_stub_map.apiproxy.GetStub("datastore_v3").SetTrusted(False)
示例6: setUp
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def setUp(self):
unittest.TestCase.setUp(self)
self.app_id = "myapp"
self.mapper_spec = model.MapperSpec.from_json({
"mapper_handler_spec": "FooHandler",
"mapper_input_reader": NamespaceInputReaderTest.MAPREDUCE_READER_SPEC,
"mapper_params": {"batch_size": 2},
"mapper_shard_count": 10})
os.environ["APPLICATION_ID"] = self.app_id
self.datastore = datastore_file_stub.DatastoreFileStub(
self.app_id, "/dev/null", "/dev/null")
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub("datastore_v3", self.datastore)
示例7: ResetApiProxyStubMap
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def ResetApiProxyStubMap(self):
"""Reset the proxy stub-map.
Args:
force: When True, always reset the stubs regardless of their status.
Must be called before stubs can be configured.
Every time a new test is created, it is necessary to run with a brand new
stub. The problem is that RegisterStub won't allow stubs to be replaced.
If the global instance is not reset, it raises an exception when a run a
new test gets run that wants to use a new stub.
Calling this method more than once per APITest instance will only cause
a new stub-map to be created once. Therefore it is called automatically
during each Configure method.
"""
if self.__apiproxy_initialized:
return
self.__apiproxy_initialized = True
apiproxy_stub_map.apiproxy = apiproxy_stub_map.GetDefaultAPIProxy()
示例8: _run_test_suite
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def _run_test_suite(runner, suite):
"""Run the test suite.
Preserve the current development apiproxy, create a new apiproxy and
replace the datastore with a temporary one that will be used for this
test suite, run the test suite, and restore the development apiproxy.
This isolates the test datastore from the development datastore.
"""
original_apiproxy = apiproxy_stub_map.apiproxy
try:
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy.RegisterStub(
'datastore',
datastore_file_stub.DatastoreFileStub(
'GAEUnitDataStore', datastore_file=None, trusted=True))
apiproxy_stub_map.apiproxy.RegisterStub(
'memcache',
memcache_stub.MemcacheServiceStub())
apiproxy_stub_map.apiproxy.RegisterStub(
'taskqueue',
TestingTaskQueueService(root_path='.'))
# Allow the other services to be used as-is for tests.
for name in ('user', 'urlfetch', 'mail', 'images'):
apiproxy_stub_map.apiproxy.RegisterStub(
name, original_apiproxy.GetStub(name))
# TODO(slamm): add coverage tool here.
runner.run(suite)
finally:
apiproxy_stub_map.apiproxy = original_apiproxy
示例9: setUp
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def setUp(self):
"""Configure test harness."""
# Configure os.environ to make it look like the relevant parts of the
# CGI environment that the stub relies on.
self.original_environ = dict(os.environ)
os.environ.update({
'APPLICATION_ID': 'app',
'SERVER_NAME': 'localhost',
'SERVER_PORT': '8080',
'AUTH_DOMAIN': 'abcxyz.com',
'USER_EMAIL': 'user@abcxyz.com',
})
# Set up mox.
self.mox = mox.Mox()
# Use a fresh file datastore stub.
self.tmpdir = tempfile.mkdtemp()
self.datastore_file = os.path.join(self.tmpdir, 'datastore_v3')
self.history_file = os.path.join(self.tmpdir, 'history')
for filename in [self.datastore_file, self.history_file]:
if os.access(filename, os.F_OK):
os.remove(filename)
self.stub = datastore_file_stub.DatastoreFileStub(
'app', self.datastore_file, self.history_file, use_atexit=False)
self.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy = self.apiproxy
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.stub)
示例10: setUp
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def setUp(self):
"""Configure test harness."""
# Configure os.environ to make it look like the relevant parts of the
# CGI environment that the stub relies on.
self.original_environ = dict(os.environ)
os.environ.update({
'APPLICATION_ID': 'app',
'SERVER_NAME': 'localhost',
'SERVER_PORT': '8080',
'AUTH_DOMAIN': 'abcxyz.com',
'USER_EMAIL': 'user@abcxyz.com',
})
# Set up testing blobstore files.
self.tmpdir = tempfile.mkdtemp()
storage_directory = os.path.join(self.tmpdir, 'blob_storage')
self.blob_storage = file_blob_storage.FileBlobStorage(storage_directory,
'appid1')
self.blobstore_stub = blobstore_stub.BlobstoreServiceStub(self.blob_storage)
# Use a fresh file datastore stub.
self.datastore_file = os.path.join(self.tmpdir, 'datastore_v3')
self.history_file = os.path.join(self.tmpdir, 'history')
for filename in [self.datastore_file, self.history_file]:
if os.access(filename, os.F_OK):
os.remove(filename)
self.datastore_stub = datastore_file_stub.DatastoreFileStub(
'app', self.datastore_file, self.history_file, use_atexit=False)
self.apiproxy = apiproxy_stub_map.APIProxyStubMap()
apiproxy_stub_map.apiproxy = self.apiproxy
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.datastore_stub)
apiproxy_stub_map.apiproxy.RegisterStub('blobstore', self.blobstore_stub)
示例11: cleanup_stubs
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def cleanup_stubs():
"""Do any necessary stub cleanup e.g. saving data."""
# Saving datastore
logging.info('Applying all pending transactions and saving the datastore')
datastore_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3')
datastore_stub.Write()
logging.info('Saving search indexes')
apiproxy_stub_map.apiproxy.GetStub('search').Write()
apiproxy_stub_map.apiproxy.GetStub('taskqueue').Shutdown()
示例12: TearDownStubs
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def TearDownStubs():
"""Clean up any stubs that need cleanup."""
datastore_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3')
if isinstance(datastore_stub, datastore_stub_util.BaseTransactionManager):
logging.info('Applying all pending transactions and saving the datastore')
datastore_stub.Write()
search_stub = apiproxy_stub_map.apiproxy.GetStub('search')
if isinstance(search_stub, simple_search_stub.SearchServiceStub):
logging.info('Saving search indexes')
search_stub.Write()
示例13: PortAllEntities
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def PortAllEntities(datastore_path):
"""Copies entities from a DatastoreFileStub to an SQLite stub.
Args:
datastore_path: Path to the file to store Datastore file stub data is.
"""
previous_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3')
try:
app_id = os.environ['APPLICATION_ID']
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
datastore_stub = datastore_file_stub.DatastoreFileStub(
app_id, datastore_path, trusted=True)
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore_stub)
entities = FetchAllEntitites()
sqlite_datastore_stub = datastore_sqlite_stub.DatastoreSqliteStub(app_id,
datastore_path + '.sqlite', trusted=True)
apiproxy_stub_map.apiproxy.ReplaceStub('datastore_v3',
sqlite_datastore_stub)
PutAllEntities(entities)
sqlite_datastore_stub.Close()
finally:
apiproxy_stub_map.apiproxy.ReplaceStub('datastore_v3', previous_stub)
shutil.copy(datastore_path, datastore_path + '.filestub')
_RemoveFile(datastore_path)
shutil.move(datastore_path + '.sqlite', datastore_path)
示例14: setUp
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def setUp(self):
# fix enviroment
app_id = 'myapp'
os.environ['APPLICATION_ID'] = app_id
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
stub = datastore_file_stub.DatastoreFileStub(app_id, '/dev/null', '/')
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
# activate mock services
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_user_stub()
self.testbed.init_memcache_stub()
示例15: MaybeInvokeAuthentication
# 需要导入模块: from google.appengine.api import apiproxy_stub_map [as 别名]
# 或者: from google.appengine.api.apiproxy_stub_map import apiproxy [as 别名]
def MaybeInvokeAuthentication():
"""Sends an empty request through to the configured end-point.
If authentication is necessary, this will cause the rpc_server to invoke
interactive authentication.
"""
datastore_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3')
if isinstance(datastore_stub, RemoteStub):
datastore_stub._server.Send(datastore_stub._path, payload=None)
else:
raise ConfigurationError('remote_api is not configured.')