def setUp(self): unittest.TestCase.setUp(self) namespace_range._setup_constants('abc', 3) self.app_id = 'testapp' 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) namespace_manager.set_namespace(None)
def setUp(self): """Setup test infrastructure.""" apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() self.datastore_stub = datastore_file_stub.DatastoreFileStub( 'test_app', '/dev/null', '/dev/null') self.datastore_stub.Clear() self.datastore_stub.SetAutoIdPolicy(datastore_stub_util.SEQUENTIAL) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.datastore_stub) os.environ['APPLICATION_ID'] = 'test_app' self.PopulateStatEntities()
def init_datastore_v3_stub(self, enable=True, datastore_file=None, use_sqlite=False, auto_id_policy=AUTO_ID_POLICY_SEQUENTIAL, **stub_kw_args): """Enable the datastore stub. The 'datastore_file' argument can be the path to an existing datastore file, or None (default) to use an in-memory datastore that is initially empty. If you use the sqlite stub and have 'datastore_file' defined, changes you apply in a test will be written to the file. If you use the default datastore stub, changes are _not_ saved to disk unless you set save_changes=True. Note that you can only access those entities of the datastore file which have the same application ID associated with them as the test run. You can change the application ID for a test with setup_env(). Args: enable: True if the fake service should be enabled, False if real service should be disabled. datastore_file: Filename of a dev_appserver datastore file. use_sqlite: True to use the Sqlite stub, False (default) for file stub. auto_id_policy: How datastore stub assigns auto IDs. Either AUTO_ID_POLICY_SEQUENTIAL or AUTO_ID_POLICY_SCATTERED. stub_kw_args: Keyword arguments passed on to the service stub. """ if not enable: self._disable_stub(DATASTORE_SERVICE_NAME) return if use_sqlite: if datastore_sqlite_stub is None: raise StubNotSupportedError( 'The sqlite stub is not supported in production.') stub = datastore_sqlite_stub.DatastoreSqliteStub( os.environ['APPLICATION_ID'], datastore_file, use_atexit=False, auto_id_policy=auto_id_policy, **stub_kw_args) else: stub_kw_args.setdefault('save_changes', False) stub = datastore_file_stub.DatastoreFileStub( os.environ['APPLICATION_ID'], datastore_file, use_atexit=False, auto_id_policy=auto_id_policy, **stub_kw_args) self._register_stub(DATASTORE_SERVICE_NAME, stub, self._deactivate_datastore_v3_stub)
def setUp(self): self.app = TestApp(application) os.environ['APPLICATION_ID'] = "temp" os.environ['USER_EMAIL'] = "*****@*****.**" os.environ['SERVER_NAME'] = "localhost" os.environ['SERVER_PORT'] = "8080" apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) stub = datastore_file_stub.DatastoreFileStub('temp', '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub)
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()
def setUp(self): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore_file_stub.DatastoreFileStub(u'myTemporaryDataStorage', '/dev/null', '/dev/null')) apiproxy_stub_map.apiproxy.RegisterStub('user', user_service_stub.UserServiceStub()) os.environ['AUTH_DOMAIN'] = 'gmail.com' os.environ['USER_EMAIL'] = '*****@*****.**' os.environ['SERVER_NAME'] = 'fakeserver.com' os.environ['SERVER_PORT'] = '9999'
def setUp(self): """Set up db test harness.""" self.original_kind_map = dict(db._kind_map) apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test_app', '/dev/null', '/dev/null') stub.Clear() apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) self.mox = mox.Mox() os.environ['APPLICATION_ID'] = 'test_app'
def setUp(self): """Set up the datastore.""" self.app_id = 'my-app' # Set environment variable for app id. os.environ['APPLICATION_ID'] = self.app_id # Don't use the filesystem with this stub. self.datastore_stub = datastore_file_stub.DatastoreFileStub( self.app_id, None) # Register stub. self.ResetApiProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.datastore_stub)
def testRunWithRpcs(self): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('_', None) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) record = [] def foo(arg): record.append(arg) eventloop.queue_call(0.1, foo, 42) conn = datastore_rpc.Connection() config = datastore_rpc.Configuration(on_completion=foo) rpc = conn.async_get(config, []) self.assertEqual(len(rpc.rpcs), 1) eventloop.queue_rpc(rpc) eventloop.run() self.assertEqual(record, [rpc.rpcs[0], 42]) self.assertEqual(rpc.state, 2) # TODO: Use apiproxy_rpc.RPC.FINISHING.
def setup_stub(): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test', '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'taskqueue', taskqueue_stub.TaskQueueServiceStub())
def get_dev_apiproxy(): _apiproxy = apiproxy_stub_map.APIProxyStubMap() _apiproxy.RegisterStub( 'datastore_v3', datastore_file_stub.DatastoreFileStub(APP_ID, None, None)) _apiproxy.RegisterStub('user', user_service_stub.UserServiceStub()) _apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub()) _apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) _apiproxy.RegisterStub('memcache', memcache_stub.MemcacheServiceStub()) _apiproxy.RegisterStub('taskqueue', taskqueue_stub.TaskQueueServiceStub()) try: _apiproxy.RegisterStub('images', images_stub.ImagesServiceStub()) except NameError: pass return _apiproxy
def setUp(self): """Set up test environment.""" from google.appengine.api import apiproxy_stub_map from google.appengine.api import datastore_file_stub os.environ['APPLICATION_ID'] = 'test' os.environ['AUTH_DOMAIN'] = "example.com" self.path = os.path.join(os.environ.get('TMPDIR', ''), 'test_datastore.db') if not apiproxy_stub_map.apiproxy.GetStub('datastore_v3'): # Initialize Datastore datastore = datastore_file_stub.DatastoreFileStub( 'test', self.path) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore)
def setUp(self): self.app = TestApp(application()) apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) stub = datastore_file_stub.DatastoreFileStub('temp', '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) os.environ['APPLICATION_ID'] = "temp"
def shell(datastore_path='', history_path='', useful_imports=True, use_ipython=True, use_sqlite=False): """ Start a new interactive python session.""" banner = 'Interactive Kay Shell' if useful_imports: namespace = create_useful_locals() else: namespace = {} appid = get_appid() os.environ['APPLICATION_ID'] = appid p = get_datastore_paths() if not datastore_path: datastore_path = p[0] if not history_path: history_path = p[1] apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() if use_sqlite: from google.appengine.datastore import datastore_sqlite_stub stub = datastore_sqlite_stub.DatastoreSqliteStub( appid, datastore_path, history_path) else: stub = datastore_file_stub.DatastoreFileStub(appid, datastore_path, history_path) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) if use_ipython: try: import IPython except ImportError: pass else: sh = IPython.Shell.IPShellEmbed(argv='', banner=banner) sh(global_ns={}, local_ns=namespace) return sys.ps1 = '%s> ' % appid if readline is not None: readline.parse_and_bind('tab: complete') atexit.register(lambda: readline.write_history_file(HISTORY_PATH)) if os.path.exists(HISTORY_PATH): readline.read_history_file(HISTORY_PATH) from code import interact interact(banner, local=namespace)
def setUp(self): os.environ['APPLICATION_ID'] = 'touch-login' datastore_file = '/dev/null' from google.appengine.api import apiproxy_stub_map, datastore_file_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('touch-login', datastore_file) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) #If you think I know what that ^ does, you're wrong, I've got no idea. User( email="*****@*****.**", firstName="Vanya", lastName="Vegner", # password = form.password.data, username="******").put() flask_app.config['TESTING'] = True self.app = flask_app.test_client()
def setUp(self): # Start with a fresh api proxy. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Use a fresh stub datastore. stub = datastore_file_stub.DatastoreFileStub(APP_ID, '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) # Use a fresh memcache stub. apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) # Use a fresh stub UserService. apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) os.environ['AUTH_DOMAIN'] = AUTH_DOMAIN os.environ['USER_EMAIL'] = LOGGED_IN_USER os.environ['APPLICATION_ID'] = APP_ID
def setUp(self): self.stubs = googletest.StubOutForTesting() self.app_id = 'test_app' os.environ['APPLICATION_ID'] = self.app_id os.environ['AUTH_DOMAIN'] = 'gmail.com' apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() self.datastore = datastore_file_stub.DatastoreFileStub(self.app_id, '/dev/null', '/dev/null', trusted=True) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.datastore) self.memcache = memcache_stub.MemcacheServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('memcache', self.memcache) self.capabilities = capability_stub.CapabilityServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('capability_service', self.capabilities)
def prepare_to_test(): import os from google.appengine.api import apiproxy_stub_map from google.appengine.api import datastore_file_stub from google.appengine.api import memcache from google.appengine.api.memcache import memcache_stub from google.appengine.api import taskqueue from google.appengine.api.taskqueue import taskqueue_stub from google.appengine.api import urlfetch_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() ds_stub = datastore_file_stub.DatastoreFileStub('_', None) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub) mc_stub = memcache_stub.MemcacheServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('memcache', mc_stub) tq_stub = taskqueue_stub.TaskQueueServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('taskqueue', tq_stub) uf_stub = urlfetch_stub.URLFetchServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', uf_stub) os.environ['APPLICATION_ID'] = '_'
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() temp_stub = datastore_file_stub.DatastoreFileStub('GAEUnitDataStore', None, None) apiproxy_stub_map.apiproxy.RegisterStub('datastore', temp_stub) # Allow the other services to be used as-is for tests. for name in ['user', 'urlfetch', 'mail', 'memcache', 'images']: apiproxy_stub_map.apiproxy.RegisterStub(name, original_apiproxy.GetStub(name)) runner.run(suite) finally: apiproxy_stub_map.apiproxy = original_apiproxy
def setUp(self): # Start with a fresh api proxy. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Use a fresh stub datastore. # From this point on in the tests, all calls to the Data Store, such as get and put, # will be to the temporary, in-memory datastore stub. stub = datastore_file_stub.DatastoreFileStub(u'myTemporaryDataStorage', '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) #User a memcache stub apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) # Use a fresh stub UserService. apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) os.environ['AUTH_DOMAIN'] = 'gmail.com' os.environ[ 'USER_EMAIL'] = '*****@*****.**' # set to '' for no logged in user os.environ['SERVER_NAME'] = 'testserver' os.environ['SERVER_PORT'] = '80' os.environ['USER_IS_ADMIN'] = '1' #admin user 0 | 1 os.environ['APPLICATION_ID'] = 'myTemporaryDataStorage' # Use a fresh urlfetch stub. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) # Use a fresh images stub. if not on_production_server: apiproxy_stub_map.apiproxy.RegisterStub( 'images', images_stub.ImagesServiceStub()) # Use a fresh mail stub. # apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) # Every test needs a client. self.client = Client()
def InitAppHostingApi(): """Initialize stubs for various app hosting APIs.""" # clear ndb's context cache # see https://developers.google.com/appengine/docs/python/ndb/cache ndb.get_context().clear_cache() # Pretend we're running in the dev_appserver os.environ['SERVER_SOFTWARE'] = 'Development/unittests' # used by app_identity.get_default_version_hostname() os.environ['DEFAULT_VERSION_HOSTNAME'] = 'localhost:8080' appid = os.environ['APPLICATION_ID'] = 'app' apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Need an HRD stub to support XG transactions hrd_policy = datastore_stub_util.TimeBasedHRConsistencyPolicy() apiproxy_stub_map.apiproxy.RegisterStub( 'datastore_v3', datastore_file_stub.DatastoreFileStub(appid, '/dev/null', '/dev/null', trusted=True, require_indexes=True, consistency_policy=hrd_policy)) # memcache stub apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) # urlfetch stub apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) # blobstore stub temp_dir = tempfile.gettempdir() storage_directory = os.path.join(temp_dir, 'blob_storage') if os.access(storage_directory, os.F_OK): shutil.rmtree(storage_directory) blob_storage = file_blob_storage.FileBlobStorage(storage_directory, appid) apiproxy_stub_map.apiproxy.RegisterStub( 'blobstore', blobstore_stub.BlobstoreServiceStub(blob_storage)) # file stub, required by blobstore stub apiproxy_stub_map.apiproxy.RegisterStub( 'file', file_service_stub.FileServiceStub(blob_storage))
def setup_stubs(app_src): from google.appengine.api import apiproxy_stub_map apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() from google.appengine.api import urlfetch_stub apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) from google.appengine.api.memcache import memcache_stub apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub(), ) from google.appengine.api import datastore_file_stub apiproxy_stub_map.apiproxy.RegisterStub( 'datastore', datastore_file_stub.DatastoreFileStub( app_id=read_yaml(app_src)['application'], datastore_file=join(dirname(app_src), '.tmp', 'test1.db'))) import app
def set_up_basic_stubs(app_id): """Set up a basic set of stubs. Configures datastore and memcache stubs for testing. Args: app_id: Application ID to configure stubs with. Returns: Dictionary mapping stub name to stub. """ apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() ds_stub = datastore_file_stub.DatastoreFileStub(app_id, None) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub) mc_stub = memcache_stub.MemcacheServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('memcache', mc_stub) return { 'datastore': ds_stub, 'memcache': mc_stub, }
def setUp(self): super(AppEngineTestCase, self).setUp() # save the apiproxy self.__origApiproxy = apiproxy_stub_map.apiproxy # make a new one apiproxy_stub_map.apiproxy = \ apiproxy_stub_map.APIProxyStubMap() self.__taskqueue = taskqueue_stub.TaskQueueServiceStub( root_path='./test/') apiproxy_stub_map.apiproxy.RegisterStub('taskqueue', self.__taskqueue) # optimization for slow sdk update tq = apiproxy_stub_map.apiproxy.GetStub('taskqueue') tq.GetTasks('default') # pylint: disable=W0212 # - workaround to prevent GetTasks from re-parsing queue.yaml on every call for value in (tq._queues or {}).values(): value._queue_yaml_parser = None self.__urlfetch = urlfetch_stub.URLFetchServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', self.__urlfetch) self.__memcache = memcache_stub.MemcacheServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('memcache', self.__memcache) self.__datastore = datastore_file_stub.DatastoreFileStub( 'fantasm', '/dev/null', '/dev/null', require_indexes=True) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.__datastore) self.__capabilities = capability_stub.CapabilityServiceStub() apiproxy_stub_map.apiproxy.RegisterStub('capability_service', self.__capabilities) constants.DATASTORE_ASYNCRONOUS_INDEX_WRITE_WAIT_TIME = 0.0 constants.DEFAULT_LOG_QUEUE_NAME = constants.DEFAULT_QUEUE_NAME
def setUp(self, urlfetch_mock=URLFetchServiceMock()): unittest.TestCase.setUp(self) self.mox = mox.Mox() self.appid = "testapp" self.version_id = "1.23456789" os.environ["APPLICATION_ID"] = self.appid os.environ["CURRENT_VERSION_ID"] = self.version_id os.environ["HTTP_HOST"] = "localhost" self.memcache = memcache_stub.MemcacheServiceStub() self.taskqueue = taskqueue_stub.TaskQueueServiceStub() self.taskqueue.queue_yaml_parser = ( 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")) self.datastore = datastore_file_stub.DatastoreFileStub( self.appid, "/dev/null", "/dev/null") self.blob_storage_directory = tempfile.mkdtemp() blob_storage = file_blob_storage.FileBlobStorage( self.blob_storage_directory, self.appid) self.blobstore_stub = blobstore_stub.BlobstoreServiceStub(blob_storage) self.file_service = self.createFileServiceStub(blob_storage) self._urlfetch_mock = urlfetch_mock self.search_service = simple_search_stub.SearchServiceStub() self.images_service = images_stub.ImagesServiceStub() apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub("taskqueue", self.taskqueue) apiproxy_stub_map.apiproxy.RegisterStub("memcache", self.memcache) apiproxy_stub_map.apiproxy.RegisterStub("datastore_v3", self.datastore) apiproxy_stub_map.apiproxy.RegisterStub("blobstore", self.blobstore_stub) apiproxy_stub_map.apiproxy.RegisterStub("file", self.file_service) apiproxy_stub_map.apiproxy.RegisterStub("urlfetch", self._urlfetch_mock) apiproxy_stub_map.apiproxy.RegisterStub("search", self.search_service) apiproxy_stub_map.apiproxy.RegisterStub("images", self.images_service)
def setUp(self): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test', '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) s = LazySettings(settings_module='kay.tests.settings') app = get_application(settings=s) self.client = Client(app, BaseResponse) if apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map.has_key('capability_service'): del(apiproxy_stub_map.apiproxy\ ._APIProxyStubMap__stub_map['capability_service'])
def convert_datastore_file_stub_data_to_sqlite(app_id, datastore_file): """Convert datastore_file_stub data into sqlite data. Args: app_id: String indicating application id. datastore_file: String indicating the file name of datastore_file_stub data. Raises: IOError: if datastore_file is not writeable. """ if not os.access(datastore_file, os.W_OK): raise IOError('Does not have write access to %s' % datastore_file) logging.info('Converting datastore file stub data to sqlite.') previous_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3') sqlite_file_name = datastore_file + '.sqlite' try: apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() datastore_stub = datastore_file_stub.DatastoreFileStub( app_id, datastore_file, 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, sqlite_file_name, 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) back_up_file_name = datastore_file + '.filestub' shutil.copy(datastore_file, back_up_file_name) os.remove(datastore_file) shutil.move(sqlite_file_name, datastore_file) logging.info( 'Datastore conversion complete. File stub data has been backed ' 'up in %s', back_up_file_name)
def convert_python_data_to_emulator(app_id, stub_type, filename, gcd_emulator_host): """Convert datastore_file_stub or datastore_sqlite_stub data to emulator data. Args: app_id: A String representing application ID. stub_type: A String representing the stub type filename belongs to. filename: A String representing the absolute path to local data. gcd_emulator_host: A String in the format of host:port indicate the hostname and port number of gcd emulator. """ previous_stub = apiproxy_stub_map.apiproxy.GetStub('datastore_v3') try: if stub_type == StubTypes.PYTHON_FILE_STUB: logging.info( 'Converting datastore_file_stub data to cloud datastore emulator ' 'data.') python_stub = datastore_file_stub.DatastoreFileStub( app_id, filename, trusted=True, save_changes=False) else: # Sqlite stub logging.info( 'Converting datastore_sqlite_stub data to cloud datastore emulator ' 'data.') python_stub = datastore_sqlite_stub.DatastoreSqliteStub( app_id, filename, trusted=True, use_atexit=False) apiproxy_stub_map.apiproxy.ReplaceStub('datastore_v3', python_stub) entities = _fetch_all_datastore_entities() grpc_stub = datastore_grpc_stub.DatastoreGrpcStub(gcd_emulator_host) grpc_stub.get_or_set_call_handler_stub() apiproxy_stub_map.apiproxy.ReplaceStub('datastore_v3', grpc_stub) datastore.Put(entities) logging.info('Conversion complete.') python_stub.Close() finally: apiproxy_stub_map.apiproxy.ReplaceStub('datastore_v3', previous_stub) logging.info('Datastore conversion complete')
def init_env(): try: if not apiproxy_stub_map.apiproxy.GetStub('user'): apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'datastore_v3', datastore_file_stub.DatastoreFileStub('mobicagecloud', '/dev/null', '/dev/null')) apiproxy_stub_map.apiproxy.RegisterStub( 'mail', mail_stub.MailServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'blobstore', blobstore_stub.BlobstoreServiceStub( file_blob_storage.FileBlobStorage('/dev/null', 'mobicagecloud'))) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'images', images_stub.ImagesServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'taskqueue', taskqueue_stub.TaskQueueServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'app_identity_service', app_identity_stub.AppIdentityServiceStub()) except Exception as e: print e raise from rogerthat.settings import get_server_settings settings = get_server_settings() settings.jabberDomain = "localhost"
def setUp(self): # Ensure we're in UTC. time.tzset() # Start with a fresh api proxy. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Use a fresh stub datastore. stub = datastore_file_stub.DatastoreFileStub(APP_ID, '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) # Use a fresh stub UserService. apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) # Use a fresh urlfetch stub. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) # Use a fresh mail stub. apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub())