def SetUpTestbedTestCase(case): """Set up appengine testbed enviroment.""" case.testbed = testbed.Testbed() case.testbed.activate() # The oauth_aware decorator will 302 to login unless there is either # a current user _or_ a valid oauth header; this is easier to stub. case.testbed.setup_env(user_email='*****@*****.**', user_id='1234', overwrite=True) case.testbed.init_all_stubs() policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1) case.testbed.init_datastore_v3_stub(consistency_policy=policy) case.testbed.init_taskqueue_stub(_all_queues_valid=True) os.environ['AUTH_DOMAIN'] = 'example.com' # Lazily stub out key-fetching RPC dependency. def Stub(data, **_): return data case.patches = [ mock.patch.object(crypto, 'Decrypt', side_effect=Stub), mock.patch.object(crypto, 'Encrypt', side_effect=Stub), ] for m in case.patches: m.start()
def init_datastore(): from google.appengine.ext import testbed from google.appengine.ext import ndb # First, create an instance of the Testbed class. testbed = testbed.Testbed() # Then activate the testbed, which prepares the service stubs for use. testbed.activate() # Next, declare which service stubs you want to use. testbed.init_app_identity_stub() testbed.init_datastore_v3_stub() testbed.init_memcache_stub() testbed.init_blobstore_stub() testbed.init_urlfetch_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()
def main(sdk_path, test_path): # If the sdk path points to a google cloud sdk installation # then we should alter it to point to the GAE platform location. if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')): sys.path.insert(0, os.path.join(sdk_path, 'platform/google_appengine')) else: sys.path.insert(0, sdk_path) # Ensure that the google.appengine.* packages are available # in tests as well as all bundled third-party packages. import dev_appserver dev_appserver.fix_sys_path() # Loading appengine_config from the current project ensures that any # changes to configuration there are available to all tests (e.g. # sys.path modifications, namespaces, etc.) try: import appengine_config (appengine_config) except ImportError: print "Note: unable to import appengine_config." from google.appengine.ext import testbed testbed = testbed.Testbed() testbed.activate() testbed.init_app_identity_stub() testbed.init_datastore_v3_stub() testbed.init_user_stub() testbed.init_memcache_stub() # Discover and run tests. suite = unittest.loader.TestLoader().discover(test_path) for root, dirs, files in os.walk(test_path): for name in dirs: # print(os.path.join(root,name)) suite.addTests(unittest.loader.TestLoader().discover( os.path.join(root, name))) unittest.TextTestRunner(verbosity=2).run(suite)
def SetUpTestbedTestCase(case): """Set up appengine testbed enviroment.""" case.testbed = testbed.Testbed() case.testbed.activate() # The oauth_aware decorator will 302 to login unless there is either # a current user _or_ a valid oauth header; this is easier to stub. case.testbed.setup_env( user_email='*****@*****.**', user_id='1234', overwrite=True) case.testbed.init_all_stubs() policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1) case.testbed.init_datastore_v3_stub(consistency_policy=policy) case.testbed.init_taskqueue_stub(_all_queues_valid=True) os.environ['AUTH_DOMAIN'] = 'example.com' # Lazily stub out key-fetching RPC dependency. crypto.Decrypt = lambda x: x crypto.Encrypt = lambda x: x
def main(sdk_path, test_path): # If the sdk path points to a google cloud sdk installation # then we should alter it to point to the GAE platform location. if os.path.exists(os.path.join(sdk_path, 'platform/google_appengine')): sys.path.insert(0, os.path.join(sdk_path, 'platform/google_appengine')) else: sys.path.insert(0, sdk_path) # Ensure that the google.appengine.* packages are available # in tests as well as all bundled third-party packages. import dev_appserver dev_appserver.fix_sys_path() # Loading appengine_config from the current project ensures that any # changes to configuration there are available to all tests (e.g. # sys.path modifications, namespaces, etc.) try: import appengine_config (appengine_config) except ImportError: print "Note: unable to import appengine_config." from google.appengine.ext import testbed testbed = testbed.Testbed() testbed.activate() testbed.init_app_identity_stub() testbed.init_datastore_v3_stub() testbed.init_user_stub() testbed.init_memcache_stub() # Discover and run tests. suite = unittest.loader.TestLoader().discover(test_path) for root, dirs, files in os.walk(test_path): for name in dirs: # print(os.path.join(root,name)) suite.addTests(unittest.loader.TestLoader().discover(os.path.join(root,name))) unittest.TextTestRunner(verbosity=2).run(suite)
def _initStubs(self, testbed): testbed.init_datastore_v3_stub()
# run with py.test if 1: from google.appengine.ext import testbed from google.appengine.api.app_identity import app_identity_stub from google.appengine.api.app_identity import app_identity_keybased_stub import local_config email_address = local_config.SERVICE_EMAIL private_key_path = local_config.SERVICE_KEY_FILE stub = app_identity_keybased_stub.KeyBasedAppIdentityServiceStub(email_address=email_address, private_key_path=private_key_path) testbed = testbed.Testbed() APP_IDENTITY_SERVICE_NAME = 'app_identity_service' testbed.activate() #testbed._register_stub(testbed.APP_IDENTITY_SERVICE_NAME, stub) testbed._register_stub(APP_IDENTITY_SERVICE_NAME, stub) testbed.init_datastore_v3_stub() testbed.init_memcache_stub() testbed.init_urlfetch_stub() from google.appengine.ext import testbed testbed = testbed.Testbed() testbed.activate() testbed.init_datastore_v3_stub() testbed.init_memcache_stub() from bqutil import *
import dev_appserver # noqa sys.path.extend(dev_appserver.EXTRA_PATHS) from google.appengine.ext import testbed # noqa testbed = testbed.Testbed() testbed.activate() # If you have PIL installed, you can just use: # testbed.init_all_stubs() # If you don't have PIL installed, you have to manually deselect the # images_stub and init the rest. You may be able to speed # things up by only selecting the ones you need and commenting the rest. # testbed.init_images_stub() testbed.init_app_identity_stub() testbed.init_blobstore_stub() testbed.init_capability_stub() testbed.init_channel_stub() testbed.init_datastore_v3_stub() testbed.init_files_stub() testbed.init_logservice_stub() testbed.init_mail_stub() testbed.init_memcache_stub() testbed.init_taskqueue_stub() testbed.init_urlfetch_stub() testbed.init_user_stub() testbed.init_xmpp_stub()