def setup_stub(high_replication=False): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test','/dev/null', '/dev/null', trusted=True) if high_replication: stub.SetConsistencyPolicy( datastore_stub_util.TimeBasedHRConsistencyPolicy()) 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()) try: apiproxy_stub_map.apiproxy.RegisterStub( 'images', images_stub.ImagesServiceStub()) except NameError: pass
def setUp(self): unittest.TestCase.setUp(self) # Regist API Proxy apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Regist urlfetch stub stub = urlfetch_stub.URLFetchServiceStub() apiproxy_stub_map.apiproxy.RegisterStub("urlfetch", stub)
def setUp(self): # Ensure we're in UTC. os.environ['TZ'] = 'UTC' time.tzset() # Start with a fresh api proxy. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Use a fresh stub datastore. self.__datastore_stub = datastore_file_stub.DatastoreFileStub( APP_ID, '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.__datastore_stub) os.environ['APPLICATION_ID'] = APP_ID # 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 # 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())
def setUp(self): super(UrlFetchTestCase, self).setUp() from google.appengine.api import apiproxy_stub_map, urlfetch_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub()) postmaster.http.HTTP_LIB = 'urlfetch'
def setupURLFetchService(): """Sets up urlfetch.""" from google.appengine.api import urlfetch_stub apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub())
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 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 # 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()) # Use a fresh memcache stub apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) # Create a fake remplate renderer self.render_calls = [] def template_render(filename, params, debug, template_dirs): self.render_calls.append(params) template.render = template_render
def init_urlfetch_stub(self, enable=True, urlmatchers=None): """Enables the urlfetch stub. The urlfetch service stub uses the urllib module to make requests. On appserver, urllib also relies the urlfetch infrastructure, so using this stub will have no effect. Args: enable: `True` if the fake service should be enabled, or `False` if the real service should be disabled. urlmatchers: optional initial sequence of (matcher, fetcher) pairs to populate urlmatchers_to_fetch_functions; matchers passed here, if any, take precedence over default matchers dispatching GCS access. """ if not enable: self._disable_stub(URLFETCH_SERVICE_NAME) return urlmatchers_to_fetch_functions = [] if urlmatchers: urlmatchers_to_fetch_functions.extend(urlmatchers) urlmatchers_to_fetch_functions.extend( GCS_URLMATCHERS_TO_FETCH_FUNCTIONS) stub = urlfetch_stub.URLFetchServiceStub( urlmatchers_to_fetch_functions=urlmatchers_to_fetch_functions) self._register_stub(URLFETCH_SERVICE_NAME, stub)
def setup_gae_services(): """Setups all google app engine services required for testing.""" from google.appengine.api import apiproxy_stub_map from google.appengine.api import mail_stub from google.appengine.api import user_service_stub from google.appengine.api import urlfetch_stub from google.appengine.api.capabilities import capability_stub from google.appengine.api.memcache import memcache_stub from google.appengine.api.taskqueue import taskqueue_stub from google.appengine.api import datastore_file_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'datastore', datastore_file_stub.DatastoreFileStub('test-app-run', None, None)) apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) yaml_location = os.path.join(HERE, 'app') apiproxy_stub_map.apiproxy.RegisterStub( 'taskqueue', taskqueue_stub.TaskQueueServiceStub(root_path=yaml_location)) apiproxy_stub_map.apiproxy.RegisterStub( 'capability_service', capability_stub.CapabilityServiceStub())
def setup_stub(): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() stub = datastore_file_stub.DatastoreFileStub('test', '/dev/null', '/dev/null', trusted=True) 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()) try: apiproxy_stub_map.apiproxy.RegisterStub( 'images', images_stub.ImagesServiceStub()) except NameError: pass
def init_env(): os.environ['AUTH_DOMAIN'] = 'gmail.com' os.environ['APPLICATION_ID'] = 'mobicagecloud' os.environ['SERVER_NAME'] = 'localhost' os.environ['SERVER_PORT'] = '8080' os.environ['SERVER_SOFTWARE'] = 'Development Server' os.environ["DEFAULT_VERSION_HOSTNAME"] = 'mobicagecloudhr.appspot.com' os.environ[ 'APPENGINE_RUNTIME'] = 'python27' # Needed to make webapp.template load ._internal.django 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())
def get_api_client(): if 'APPENGINE_RUNTIME' in os.environ: from google.appengine.api import apiproxy_stub_map from google.appengine.api import urlfetch_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub()) return Client(os.environ['ALGOLIA_APPLICATION_ID'], os.environ['ALGOLIA_API_KEY'])
def setUp(self): super(TrelloUtilTest, self).setUp() # Create a stub map so we can build App Engine mock stubs. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Register App Engine mock stubs. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub())
def setUp(self): unittest.TestCase.setUp(self) self.tempdir = tempfile.mkdtemp() # Regist API Proxy apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Regist urlfetch stub self._urlfetch_mock = URLFetchServiceMock() urlfetch_stub.URLFetchServiceStub() apiproxy_stub_map.apiproxy.RegisterStub("urlfetch", self._urlfetch_mock)
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()) return _apiproxy
def setUp(self): import eventflit.gae from google.appengine.api import apiproxy_stub_map, urlfetch_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) self.p = eventflit.Eventflit.from_url( u'http://*****:*****@service.eventflit.com/apps/4', backend=eventflit.gae.GAEBackend)
def setUp(self): import pusher.gae from google.appengine.api import apiproxy_stub_map, urlfetch_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) self.p = pusher.Pusher.from_url( u'http://*****:*****@api.pusherapp.com/apps/4', backend=pusher.gae.GAEBackend)
def test_OFLParser_GetMatchesFromHTML_matchCount(self): # Create a stub map so we can build App Engine mock stubs. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Register App Engine mock stubs. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) parser = OFLScheduleParser() data = [] data = parser.parse(10, 1) #Get matches from old season/week. self.assertEqual(20 * 11, len(data)) #Return 20 * 11 pieces of data
def main(): sys.path = extra_paths + sys.path os.environ['SERVER_SOFTWARE'] = 'Development via nose' os.environ['SERVER_NAME'] = 'Foo' os.environ['SERVER_PORT'] = '8080' os.environ['APPLICATION_ID'] = 'test-app-run' os.environ['USER_EMAIL'] = '*****@*****.**' os.environ['CURRENT_VERSION_ID'] = 'testing-version' os.environ['HTTP_HOST'] = 'some.testing.host.tld' import main as app_main from google.appengine.api import apiproxy_stub_map from google.appengine.api import datastore_file_stub from google.appengine.api import mail_stub from google.appengine.api import user_service_stub from google.appengine.api import urlfetch_stub from google.appengine.api.memcache import memcache_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'datastore', datastore_file_stub.DatastoreFileStub('test-app-run', None, None)) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) import django.test.utils django.test.utils.setup_test_environment() # register a core for the test modules to use from soc.modules import callback from soc.modules import core callback.registerCore(core.Core()) callback.getCore().registerModuleCallbacks() plugins = [AppEngineDatastoreClearPlugin()] if '--coverage' in sys.argv: from nose.plugins import cover plugin = cover.Coverage() plugins.append(plugin) args = [ '--with-coverage', '--cover-package=soc', '--cover-erase', '--cover-html', '--cover-html-dir=coverageResults' ] sys.argv.remove('--coverage') sys.argv += args nose.main(plugins=plugins)
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 __init__(self, addr, app, apps_root, var, verbose=False, secure=False): """Initialize the WSGI server. Args: app: A webapp.WSGIApplication. addr: Use this address to initialize the HTTP server. apps_root: Applications root directory. var: Directory for platform independent data. verbose: Boolean, default False. If True, enable verbose mode. secure: Boolean, default False. If True, enable secure connection. """ assert isinstance(app, webapp.WSGIApplication) self.app = app host, port = addr.split(':') self.host = host self.port = int(port) self.apps_root = apps_root self.secure = secure # Setup signals signal.signal(signal.SIGHUP, self._handleSignal) signal.signal(signal.SIGQUIT, self._handleSignal) signal.signal(signal.SIGABRT, self._handleSignal) signal.signal(signal.SIGTERM, self._handleSignal) # Setup environment os.environ['APPLICATION_ID'] = APPLICATION_ID # Setup Datastore # We use the SQLite Datastore stub for development. Later, we take # the production Datastore. from google.appengine.datastore import datastore_sqlite_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() datastore_path = os.path.join(var, APPLICATION_ID + '.sqlite') datastore = datastore_sqlite_stub.DatastoreSqliteStub( APPLICATION_ID, datastore_path) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore) logging.debug('Using datastore: %s', datastore_path) # Setup Urlfetch from google.appengine.api import urlfetch_stub urlfetch_stub.MAX_REQUEST_SIZE = 5012 << 30 apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub())
def init_urlfetch_stub(self, enable=True): """Enable the urlfetch stub. The urlfetch service stub uses the urllib module to make requests. Because on appserver urllib also relies the urlfetch infrastructure, using this stub will have no effect. Args: enable: True, if the fake service should be enabled, False if real service should be disabled. """ if not enable: self._disable_stub(URLFETCH_SERVICE_NAME) return stub = urlfetch_stub.URLFetchServiceStub() self._register_stub(URLFETCH_SERVICE_NAME, stub)
def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_urlfetch_stub() self.testbed.init_memcache_stub() self.testbed.init_taskqueue_stub(root_path='.') self.testbed.init_search_stub() self._expected_fetches = [] apiproxy_stub_map.apiproxy.ReplaceStub( testbed.URLFETCH_SERVICE_NAME, urlfetch_stub.URLFetchServiceStub( urlmatchers_to_fetch_functions=[(lambda a: True, self._fetch)])) self.tasks = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
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 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 create_client(app_id_env='ALGOLIA_APPLICATION_ID', api_key_env='ALGOLIA_API_KEY'): if 'APPENGINE_RUNTIME' in os.environ: from google.appengine.api import apiproxy_stub_map from google.appengine.api import urlfetch_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) check_credentials() try: return algoliasearch.Client(os.environ[app_id_env], os.environ[api_key_env]) except: raise RuntimeError( "{} and {} environement variables must be set".format( app_id_env, api_key_env))
def setup_stubs(storage_path, options, configuration): datastore_path = options.datastore_path or os.path.join(storage_path, 'datastore.db') search_index_path = options.search_indexes_path or os.path.join(storage_path, 'search_indexes') blobstore_path = options.blobstore_path or os.path.join(storage_path, 'blobs') # Init the proxy map and stubs from google.appengine.api import apiproxy_stub_map apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # DB from google.appengine.datastore import datastore_sqlite_stub apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore_sqlite_stub.DatastoreSqliteStub(configuration.app_id, datastore_path)) # Search service from google.appengine.api.search import simple_search_stub apiproxy_stub_map.apiproxy.RegisterStub('search', simple_search_stub.SearchServiceStub(index_file=search_index_path)) from google.appengine.api.blobstore import file_blob_storage blob_storage = file_blob_storage.FileBlobStorage(blobstore_path, configuration.app_id) from google.appengine.api.blobstore import blobstore_stub apiproxy_stub_map.apiproxy.RegisterStub('blobstore', blobstore_stub.BlobstoreServiceStub(blob_storage)) from google.appengine.api.app_identity import app_identity_stub apiproxy_stub_map.apiproxy.RegisterStub('app_identity_service', app_identity_stub.AppIdentityServiceStub()) # Capability from google.appengine.api.capabilities import capability_stub apiproxy_stub_map.apiproxy.RegisterStub('capability_service', capability_stub.CapabilityServiceStub()) # Memcache from google.appengine.api.memcache import memcache_stub apiproxy_stub_map.apiproxy.RegisterStub('memcache', memcache_stub.MemcacheServiceStub()) # Task queues from google.appengine.api.taskqueue import taskqueue_stub apiproxy_stub_map.apiproxy.RegisterStub('taskqueue', taskqueue_stub.TaskQueueServiceStub()) # URLfetch service from google.appengine.api import urlfetch_stub apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub())
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(root_path=kay.PROJECT_DIR)) try: _apiproxy.RegisterStub('images', images_stub.ImagesServiceStub()) except NameError: pass return _apiproxy
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 setUp(self): # Patch random.random to a stable value so we don't randomize email # addresses chosen out of our lists of possible candidates. We # randomize in production b/c it's a hacky fair way to choose who takes # responsibility for organizing the retrospective if no PMs are found. self.mock_patch = mock.patch('random.random', return_value=0) self.mock_patch.start() # Create a stub map so we can build App Engine mock stubs. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Register App Engine mock stubs. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) # Patch mail so we can test sending reminders self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_mail_stub() self.mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
def init_urlfetch_stub(self, enable=True): """Enable the urlfetch stub. The urlfetch service stub uses the urllib module to make requests. Because on appserver urllib also relies the urlfetch infrastructure, using this stub will have no effect. Args: enable: True, if the fake service should be enabled, False if real service should be disabled. """ if not enable: self._disable_stub(URLFETCH_SERVICE_NAME) return urlmatchers_to_fetch_functions = [] urlmatchers_to_fetch_functions.extend( gcs_dispatcher.URLMATCHERS_TO_FETCH_FUNCTIONS) stub = urlfetch_stub.URLFetchServiceStub( urlmatchers_to_fetch_functions=urlmatchers_to_fetch_functions) self._register_stub(URLFETCH_SERVICE_NAME, stub)