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())
Exemple #2
0
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())
Exemple #3
0
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
Exemple #4
0
    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_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 setUp(self):

        os.environ['USER_EMAIL'] = ''
        os.environ['USER_ID'] = ''
        os.environ['USER_IS_ADMIN'] = '0'

        apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
        self.users_stub = user_service_stub.UserServiceStub()
        self.expected_login_request = user_service_pb2.CreateLoginURLRequest()
        self.expected_logout_request = user_service_pb2.CreateLogoutURLRequest(
        )

        class TestStub(apiproxy_stub.APIProxyStub):
            _ACCEPTS_REQUEST_ID = True

            def _Dynamic_CreateLoginURL(myself, request, response, request_id):
                if request != self.expected_login_request:
                    raise AssertionError(
                        'Expected: %s\nFound: %s' %
                        (str(self.expected_login_request), str(request)))
                self.users_stub._Dynamic_CreateLoginURL(
                    request, response, request_id)

            def _Dynamic_CreateLogoutURL(myself, request, response,
                                         request_id):
                if request != self.expected_logout_request:
                    raise AssertionError(
                        'Expected: %s\nFound: %s' %
                        (str(self.expected_logout_request), str(request)))
                self.users_stub._Dynamic_CreateLogoutURL(
                    request, response, request_id)

        apiproxy_stub_map.apiproxy.RegisterStub('user', TestStub('user'))
Exemple #7
0
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
Exemple #8
0
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)

    tq_stub = taskqueue_stub.TaskQueueServiceStub()
    apiproxy_stub_map.apiproxy.RegisterStub('taskqueue', tq_stub)

    user_stub = user_service_stub.UserServiceStub()
    apiproxy_stub_map.apiproxy.RegisterStub('user', user_stub)

    return {
        'datastore': ds_stub,
        'memcache': mc_stub,
        'taskqueue': tq_stub,
        'user': user_stub,
    }
    def testCustomAuthDomain(self):

        apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
        users_stub = user_service_stub.UserServiceStub(
            auth_domain='google.com')
        apiproxy_stub_map.apiproxy.RegisterStub('user', users_stub)
        gow = users.User(email='*****@*****.**', _user_id='24546')
        self.assertEqual('google.com', gow.auth_domain())
Exemple #10
0
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):
     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)
Exemple #12
0
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)
Exemple #13
0
    def init_user_stub(self, enable=True, **stub_kw_args):
        """Enable the users stub.

    Args:
      enable: True, if the fake service should be enabled, False if real
              service should be disabled.
      stub_kw_args: Keyword arguments passed on to the service stub.
    """
        if not enable:
            self._disable_stub(USER_SERVICE_NAME)
            return
        stub = user_service_stub.UserServiceStub(**stub_kw_args)
        self._register_stub(USER_SERVICE_NAME, stub)
Exemple #14
0
    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'    
Exemple #15
0
def setupUserService(login_url='/_ah/login', logout_url='/_ah/logout'):
    """Sets up user service.

    Args:
        login_url: The login URL.
        logout_url: The logout URL.
    """

    from google.appengine.api import user_service_stub

    apiproxy_stub_map.apiproxy.RegisterStub(
        'user',
        user_service_stub.UserServiceStub(login_url=login_url + '?continue=%s',
                                          logout_url=logout_url +
                                          '?continue=%s'))
Exemple #16
0
    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"
Exemple #17
0
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())
Exemple #18
0
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
Exemple #19
0
    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
Exemple #20
0
    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()
Exemple #21
0
    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'])
Exemple #22
0
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())
Exemple #24
0
    def setUp(self):
        googletest.TestCase.setUp(self)

        self.appid = "testapp"
        os.environ["APPLICATION_ID"] = self.appid

        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.user = user_service_stub.UserServiceStub()

        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("user", self.user)
Exemple #25
0
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 urlfetch_stub
from google.appengine.api import user_service_stub

APP_ID = u'test_app'
AUTH_DOMAIN = 'gmail.com'
LOGGED_IN_USER = ''  # set to '' for no logged in user

# 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())
def setup_stubs(
    request_data,
    app_id,
    application_root,
    trusted,
    blobstore_path,
    datastore_consistency,
    datastore_path,
    datastore_require_indexes,
    datastore_auto_id_policy,
    images_host_prefix,
    logs_path,
    mail_smtp_host,
    mail_smtp_port,
    mail_smtp_user,
    mail_smtp_password,
    mail_enable_sendmail,
    mail_show_mail_body,
    matcher_prospective_search_path,
    search_index_path,
    taskqueue_auto_run_tasks,
    taskqueue_default_http_server,
    user_login_url,
    user_logout_url,
    default_gcs_bucket_name):
  """Configures the APIs hosted by this server.

  Args:
    request_data: An apiproxy_stub.RequestInformation instance used by the
        stubs to lookup information about the request associated with an API
        call.
    app_id: The str application id e.g. "guestbook".
    application_root: The path to the directory containing the user's
        application e.g. "/home/joe/myapp".
    trusted: A bool indicating if privileged APIs should be made available.
    blobstore_path: The path to the file that should be used for blobstore
        storage.
    datastore_consistency: The datastore_stub_util.BaseConsistencyPolicy to
        use as the datastore consistency policy.
    datastore_path: The path to the file that should be used for datastore
        storage.
    datastore_require_indexes: A bool indicating if the same production
        datastore indexes requirements should be enforced i.e. if True then
        a google.appengine.ext.db.NeedIndexError will be be raised if a query
        is executed without the required indexes.
    datastore_auto_id_policy: The type of sequence from which the datastore
        stub assigns auto IDs, either datastore_stub_util.SEQUENTIAL or
        datastore_stub_util.SCATTERED.
    images_host_prefix: The URL prefix (protocol://host:port) to prepend to
        image urls on calls to images.GetUrlBase.
    logs_path: Path to the file to store the logs data in.
    mail_smtp_host: The SMTP hostname that should be used when sending e-mails.
        If None then the mail_enable_sendmail argument is considered.
    mail_smtp_port: The SMTP port number that should be used when sending
        e-mails. If this value is None then mail_smtp_host must also be None.
    mail_smtp_user: The username to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host is also None or if
        the SMTP server does not require authentication.
    mail_smtp_password: The password to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host or mail_smtp_user
        is also None.
    mail_enable_sendmail: A bool indicating if sendmail should be used when
        sending e-mails. This argument is ignored if mail_smtp_host is not None.
    mail_show_mail_body: A bool indicating whether the body of sent e-mails
        should be written to the logs.
    matcher_prospective_search_path: The path to the file that should be used to
        save prospective search subscriptions.
    search_index_path: The path to the file that should be used for search index
        storage.
    taskqueue_auto_run_tasks: A bool indicating whether taskqueue tasks should
        be run automatically or it the must be manually triggered.
    taskqueue_default_http_server: A str containing the address of the http
        server that should be used to execute tasks.
    user_login_url: A str containing the url that should be used for user login.
    user_logout_url: A str containing the url that should be used for user
        logout.
    default_gcs_bucket_name: A str, overriding the default bucket behavior.
  """

  identity_stub = app_identity_stub.AppIdentityServiceStub()
  if default_gcs_bucket_name is not None:
    identity_stub.SetDefaultGcsBucketName(default_gcs_bucket_name)
  apiproxy_stub_map.apiproxy.RegisterStub('app_identity_service', identity_stub)

  blob_storage = file_blob_storage.FileBlobStorage(blobstore_path, app_id)
  apiproxy_stub_map.apiproxy.RegisterStub(
      'blobstore',
      blobstore_stub.BlobstoreServiceStub(blob_storage,
                                          request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'capability_service',
      capability_stub.CapabilityServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'channel',
      channel_service_stub.ChannelServiceStub(request_data=request_data))

  datastore_stub = datastore_sqlite_stub.DatastoreSqliteStub(
      app_id,
      datastore_path,
      datastore_require_indexes,
      trusted,
      root_path=application_root,
      auto_id_policy=datastore_auto_id_policy)

  datastore_stub.SetConsistencyPolicy(datastore_consistency)

  apiproxy_stub_map.apiproxy.ReplaceStub(
      'datastore_v3', datastore_stub)

  apiproxy_stub_map.apiproxy.RegisterStub(
      'datastore_v4',
      datastore_v4_stub.DatastoreV4Stub(app_id))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'file',
      file_service_stub.FileServiceStub(blob_storage))

  try:
    from google.appengine.api.images import images_stub
  except ImportError:

    logging.warning('Could not initialize images API; you are likely missing '
                    'the Python "PIL" module.')
    # We register a stub which throws a NotImplementedError for most RPCs.
    from google.appengine.api.images import images_not_implemented_stub
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_not_implemented_stub.ImagesNotImplementedServiceStub(
            host_prefix=images_host_prefix))
  else:
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_stub.ImagesServiceStub(host_prefix=images_host_prefix))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'logservice',
      logservice_stub.LogServiceStub(logs_path=logs_path))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'mail',
      mail_stub.MailServiceStub(mail_smtp_host,
                                mail_smtp_port,
                                mail_smtp_user,
                                mail_smtp_password,
                                enable_sendmail=mail_enable_sendmail,
                                show_mail_body=mail_show_mail_body))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'memcache',
      memcache_stub.MemcacheServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'search',
      simple_search_stub.SearchServiceStub(index_file=search_index_path))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'modules',
      modules_stub.ModulesServiceStub(request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'system',
      system_stub.SystemServiceStub(request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'taskqueue',
      taskqueue_stub.TaskQueueServiceStub(
          root_path=application_root,
          auto_task_running=taskqueue_auto_run_tasks,
          default_http_server=taskqueue_default_http_server,
          request_data=request_data))
  apiproxy_stub_map.apiproxy.GetStub('taskqueue').StartBackgroundExecution()

  apiproxy_stub_map.apiproxy.RegisterStub(
      'urlfetch',
      urlfetch_stub.URLFetchServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'user',
      user_service_stub.UserServiceStub(login_url=user_login_url,
                                        logout_url=user_logout_url,
                                        request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'xmpp',
      xmpp_service_stub.XmppServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'matcher',
      prospective_search_stub.ProspectiveSearchStub(
          matcher_prospective_search_path,
          apiproxy_stub_map.apiproxy.GetStub('taskqueue')))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'remote_socket',
      _remote_socket_stub.RemoteSocketServiceStub())
Exemple #27
0
def setup_stubs(
    request_data,
    app_id,
    application_root,
    trusted,
    appidentity_email_address,
    appidentity_private_key_path,
    blobstore_path,
    datastore_consistency,
    datastore_path,
    datastore_require_indexes,
    datastore_auto_id_policy,
    images_host_prefix,
    logs_path,
    mail_smtp_host,
    mail_smtp_port,
    mail_smtp_user,
    mail_smtp_password,
    mail_enable_sendmail,
    mail_show_mail_body,
    mail_allow_tls,
    search_index_path,
    taskqueue_auto_run_tasks,
    taskqueue_default_http_server,
    user_login_url,
    user_logout_url,
    default_gcs_bucket_name,
    appidentity_oauth_url=None,
    support_datastore_emulator=False):
  """Configures the APIs hosted by this server.

  Args:
    request_data: An apiproxy_stub.RequestInformation instance used by the
        stubs to lookup information about the request associated with an API
        call.
    app_id: The str application id e.g. "guestbook".
    application_root: The path to the directory containing the user's
        application e.g. "/home/joe/myapp".
    trusted: A bool indicating if privileged APIs should be made available.
    appidentity_email_address: Email address associated with a service account
        that has a downloadable key. May be None for no local application
        identity.
    appidentity_private_key_path: Path to private key file associated with
        service account (.pem format). Must be set if appidentity_email_address
        is set.
    blobstore_path: The path to the file that should be used for blobstore
        storage.
    datastore_consistency: The datastore_stub_util.BaseConsistencyPolicy to
        use as the datastore consistency policy.
    datastore_path: The path to the file that should be used for datastore
        storage.
    datastore_require_indexes: A bool indicating if the same production
        datastore indexes requirements should be enforced i.e. if True then
        a google.appengine.ext.db.NeedIndexError will be be raised if a query
        is executed without the required indexes.
    datastore_auto_id_policy: The type of sequence from which the datastore
        stub assigns auto IDs, either datastore_stub_util.SEQUENTIAL or
        datastore_stub_util.SCATTERED.
    images_host_prefix: The URL prefix (protocol://host:port) to prepend to
        image urls on calls to images.GetUrlBase.
    logs_path: Path to the file to store the logs data in.
    mail_smtp_host: The SMTP hostname that should be used when sending e-mails.
        If None then the mail_enable_sendmail argument is considered.
    mail_smtp_port: The SMTP port number that should be used when sending
        e-mails. If this value is None then mail_smtp_host must also be None.
    mail_smtp_user: The username to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host is also None or if
        the SMTP server does not require authentication.
    mail_smtp_password: The password to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host or mail_smtp_user
        is also None.
    mail_enable_sendmail: A bool indicating if sendmail should be used when
        sending e-mails. This argument is ignored if mail_smtp_host is not None.
    mail_show_mail_body: A bool indicating whether the body of sent e-mails
        should be written to the logs.
    mail_allow_tls: A bool indicating whether TLS should be allowed when
        communicating with an SMTP server. This argument is ignored if
        mail_smtp_host is None.
    search_index_path: The path to the file that should be used for search index
        storage.
    taskqueue_auto_run_tasks: A bool indicating whether taskqueue tasks should
        be run automatically or it the must be manually triggered.
    taskqueue_default_http_server: A str containing the address of the http
        server that should be used to execute tasks.
    user_login_url: A str containing the url that should be used for user login.
    user_logout_url: A str containing the url that should be used for user
        logout.
    default_gcs_bucket_name: A str, overriding the default bucket behavior.
    appidentity_oauth_url: A str containing the url to the oauth2 server to use
        to authenticate the private key. If set to None, then the standard
        google oauth2 server is used.
    support_datastore_emulator: A bool indicating if datastore_emulator is
        supported.
  """
  identity_stub = app_identity_stub.AppIdentityServiceStub.Create(
      email_address=appidentity_email_address,
      private_key_path=appidentity_private_key_path,
      oauth_url=appidentity_oauth_url)
  if default_gcs_bucket_name is not None:
    identity_stub.SetDefaultGcsBucketName(default_gcs_bucket_name)
  apiproxy_stub_map.apiproxy.RegisterStub('app_identity_service', identity_stub)

  blob_storage = file_blob_storage.FileBlobStorage(blobstore_path, app_id)
  apiproxy_stub_map.apiproxy.RegisterStub(
      'blobstore',
      blobstore_stub.BlobstoreServiceStub(blob_storage,
                                          request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'capability_service',
      capability_stub.CapabilityServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'channel',
      channel_service_stub.ChannelServiceStub(request_data=request_data))

  if support_datastore_emulator:
    datastore_emulator_host = os.environ.get('DATASTORE_EMULATOR_HOST', '')
    error_msg = 'DATASTORE_EMULATOR_HOST is not found in environment variables'
    assert datastore_emulator_host, error_msg
    apiproxy_stub_map.apiproxy.ReplaceStub(
        'datastore_v3',
        datastore_grpc_stub.DatastoreGrpcStub(datastore_emulator_host)
    )
  else:
    apiproxy_stub_map.apiproxy.ReplaceStub(
        'datastore_v3',
        datastore_sqlite_stub.DatastoreSqliteStub(
            app_id,
            datastore_path,
            datastore_require_indexes,
            trusted,
            root_path=application_root,
            auto_id_policy=datastore_auto_id_policy,
            consistency_policy=datastore_consistency))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'datastore_v4',
      datastore_v4_stub.DatastoreV4Stub(app_id))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'file',
      file_service_stub.FileServiceStub(blob_storage))

  try:
    from google.appengine.api.images import images_stub
  except ImportError:




    # We register a stub which throws a NotImplementedError for most RPCs.
    from google.appengine.api.images import images_not_implemented_stub
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_not_implemented_stub.ImagesNotImplementedServiceStub(
            host_prefix=images_host_prefix))
  else:
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_stub.ImagesServiceStub(host_prefix=images_host_prefix))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'logservice',
      logservice_stub.LogServiceStub(logs_path=logs_path))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'mail',
      mail_stub.MailServiceStub(mail_smtp_host,
                                mail_smtp_port,
                                mail_smtp_user,
                                mail_smtp_password,
                                enable_sendmail=mail_enable_sendmail,
                                show_mail_body=mail_show_mail_body,
                                allow_tls=mail_allow_tls))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'memcache',
      memcache_stub.MemcacheServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'modules',
      modules_stub.ModulesServiceStub(request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'remote_socket',
      _remote_socket_stub.RemoteSocketServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'search',
      simple_search_stub.SearchServiceStub(index_file=search_index_path))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'system',
      system_stub.SystemServiceStub(request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'taskqueue',
      taskqueue_stub.TaskQueueServiceStub(
          root_path=application_root,
          auto_task_running=taskqueue_auto_run_tasks,
          default_http_server=taskqueue_default_http_server,
          request_data=request_data))
  apiproxy_stub_map.apiproxy.GetStub('taskqueue').StartBackgroundExecution()

  apiproxy_stub_map.apiproxy.RegisterStub(
      'urlfetch',
      urlfetch_stub.URLFetchServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'user',
      user_service_stub.UserServiceStub(login_url=user_login_url,
                                        logout_url=user_logout_url,
                                        request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'xmpp',
      xmpp_service_stub.XmppServiceStub())
Exemple #28
0
def _SetupStubs(
    app_id,
    application_root,
    trusted,
    blobstore_path,
    use_sqlite,
    auto_id_policy,
    high_replication,
    datastore_path,
    datastore_require_indexes,
    images_host_prefix,
    logs_path,
    mail_smtp_host,
    mail_smtp_port,
    mail_smtp_user,
    mail_smtp_password,
    mail_enable_sendmail,
    mail_show_mail_body,
    matcher_prospective_search_path,
    taskqueue_auto_run_tasks,
    taskqueue_task_retry_seconds,
    taskqueue_default_http_server,
    user_login_url,
    user_logout_url):
  """Configures the APIs hosted by this server.

  Args:
    app_id: The str application id e.g. "guestbook".
    application_root: The path to the directory containing the user's
        application e.g. "/home/bquinlan/myapp".
    trusted: A bool indicating if privileged APIs should be made available.
    blobstore_path: The path to the file that should be used for blobstore
        storage.
    use_sqlite: A bool indicating whether DatastoreSqliteStub or
        DatastoreFileStub should be used.
    auto_id_policy: One of datastore_stub_util.SEQUENTIAL or .SCATTERED,
        indicating whether the Datastore stub should assign IDs sequentially
        or scattered.
    high_replication: A bool indicating whether to use the high replication
        consistency model.
    datastore_path: The path to the file that should be used for datastore
        storage.
    datastore_require_indexes: A bool indicating if the same production
        datastore indexes requirements should be enforced i.e. if True then
        a google.appengine.ext.db.NeedIndexError will be be raised if a query
        is executed without the required indexes.
    images_host_prefix: The URL prefix (protocol://host:port) to preprend to
        image urls on calls to images.GetUrlBase.
    logs_path: Path to the file to store the logs data in.
    mail_smtp_host: The SMTP hostname that should be used when sending e-mails.
        If None then the mail_enable_sendmail argument is considered.
    mail_smtp_port: The SMTP port number that should be used when sending
        e-mails. If this value is None then mail_smtp_host must also be None.
    mail_smtp_user: The username to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host is also None or if
        the SMTP server does not require authentication.
    mail_smtp_password: The password to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host or mail_smtp_user
        is also None.
    mail_enable_sendmail: A bool indicating if sendmail should be used when
        sending e-mails. This argument is ignored if mail_smtp_host is not None.
    mail_show_mail_body: A bool indicating whether the body of sent e-mails
        should be written to the logs.
    matcher_prospective_search_path: The path to the file that should be used to
        save prospective search subscriptions.
    taskqueue_auto_run_tasks: A bool indicating whether taskqueue tasks should
        be run automatically or it the must be manually triggered.
    taskqueue_task_retry_seconds: An int representing the number of seconds to
        wait before a retrying a failed taskqueue task.
    taskqueue_default_http_server: A str containing the address of the http
        server that should be used to execute tasks.
    user_login_url: A str containing the url that should be used for user login.
    user_logout_url: A str containing the url that should be used for user
        logout.
  """





  os.environ['APPLICATION_ID'] = app_id



  apiproxy_stub_map.apiproxy.RegisterStub(
      'app_identity_service',
      app_identity_stub.AppIdentityServiceStub())

  blob_storage = file_blob_storage.FileBlobStorage(blobstore_path, app_id)
  apiproxy_stub_map.apiproxy.RegisterStub(
      'blobstore',
      blobstore_stub.BlobstoreServiceStub(blob_storage))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'capability_service',
      capability_stub.CapabilityServiceStub())








  apiproxy_stub_map.apiproxy.RegisterStub(
      'channel',
      channel_service_stub.ChannelServiceStub())

  if use_sqlite:
    datastore = datastore_sqlite_stub.DatastoreSqliteStub(
        app_id,
        datastore_path,
        datastore_require_indexes,
        trusted,
        root_path=application_root,
        auto_id_policy=auto_id_policy)
  else:
    datastore = datastore_file_stub.DatastoreFileStub(
        app_id,
        datastore_path,
        datastore_require_indexes,
        trusted,
        root_path=application_root,
        auto_id_policy=auto_id_policy)

  if high_replication:
    datastore.SetConsistencyPolicy(
        datastore_stub_util.TimeBasedHRConsistencyPolicy())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'datastore_v3', datastore)

  apiproxy_stub_map.apiproxy.RegisterStub(
      'file',
      file_service_stub.FileServiceStub(blob_storage))

  try:
    from google.appengine.api.images import images_stub
  except ImportError:


    logging.warning('Could not initialize images API; you are likely missing '
                    'the Python "PIL" module.')

    from google.appengine.api.images import images_not_implemented_stub
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_not_implemented_stub.ImagesNotImplementedServiceStub())
  else:
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_stub.ImagesServiceStub(host_prefix=images_host_prefix))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'logservice',
      logservice_stub.LogServiceStub(persist=True))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'mail',
      mail_stub.MailServiceStub(mail_smtp_host,
                                mail_smtp_port,
                                mail_smtp_user,
                                mail_smtp_password,
                                enable_sendmail=mail_enable_sendmail,
                                show_mail_body=mail_show_mail_body))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'memcache',
      memcache_stub.MemcacheServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'search',
      simple_search_stub.SearchServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub('system',
                                          system_stub.SystemServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'taskqueue',
      taskqueue_stub.TaskQueueServiceStub(
          root_path=application_root,
          auto_task_running=taskqueue_auto_run_tasks,
          task_retry_seconds=taskqueue_task_retry_seconds,
          default_http_server=taskqueue_default_http_server))
  apiproxy_stub_map.apiproxy.GetStub('taskqueue').StartBackgroundExecution()

  apiproxy_stub_map.apiproxy.RegisterStub(
      'urlfetch',
      urlfetch_stub.URLFetchServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'user',
      user_service_stub.UserServiceStub(login_url=user_login_url,
                                        logout_url=user_logout_url))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'xmpp',
      xmpp_service_stub.XmppServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'matcher',
      prospective_search_stub.ProspectiveSearchStub(
          matcher_prospective_search_path,
          apiproxy_stub_map.apiproxy.GetStub('taskqueue')))
Exemple #29
0
def setup_stubs(
    request_data,
    app_id,
    application_root,
    trusted,
    blobstore_path,
    datastore_consistency,
    datastore_path,
    datastore_require_indexes,
    datastore_auto_id_policy,
    images_host_prefix,
    logs_path,
    mail_smtp_host,
    mail_smtp_port,
    mail_smtp_user,
    mail_smtp_password,
    mail_enable_sendmail,
    mail_show_mail_body,
    matcher_prospective_search_path,
    search_index_path,
    taskqueue_auto_run_tasks,
    taskqueue_default_http_server,
    uaserver_path,
    user_login_url,
    user_logout_url,
    xmpp_path):
  """Configures the APIs hosted by this server.

  Args:
    request_data: An apiproxy_stub.RequestInformation instance used by the
        stubs to lookup information about the request associated with an API
        call.
    app_id: The str application id e.g. "guestbook".
    application_root: The path to the directory containing the user's
        application e.g. "/home/joe/myapp".
    trusted: A bool indicating if privileged APIs should be made available.
    blobstore_path: The path to the file that should be used for blobstore
        storage.
    datastore_consistency: The datastore_stub_util.BaseConsistencyPolicy to
        use as the datastore consistency policy.
    datastore_path: The path to the file that should be used for datastore
        storage.
    datastore_require_indexes: A bool indicating if the same production
        datastore indexes requirements should be enforced i.e. if True then
        a google.appengine.ext.db.NeedIndexError will be be raised if a query
        is executed without the required indexes.
    datastore_auto_id_policy: The type of sequence from which the datastore
        stub assigns auto IDs, either datastore_stub_util.SEQUENTIAL or
        datastore_stub_util.SCATTERED.
    images_host_prefix: The URL prefix (protocol://host:port) to prepend to
        image urls on calls to images.GetUrlBase.
    logs_path: Path to the file to store the logs data in.
    mail_smtp_host: The SMTP hostname that should be used when sending e-mails.
        If None then the mail_enable_sendmail argument is considered.
    mail_smtp_port: The SMTP port number that should be used when sending
        e-mails. If this value is None then mail_smtp_host must also be None.
    mail_smtp_user: The username to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host is also None or if
        the SMTP server does not require authentication.
    mail_smtp_password: The password to use when authenticating with the
        SMTP server. This value may be None if mail_smtp_host or mail_smtp_user
        is also None.
    mail_enable_sendmail: A bool indicating if sendmail should be used when
        sending e-mails. This argument is ignored if mail_smtp_host is not None.
    mail_show_mail_body: A bool indicating whether the body of sent e-mails
        should be written to the logs.
    matcher_prospective_search_path: The path to the file that should be used to
        save prospective search subscriptions.
    search_index_path: The path to the file that should be used for search index
        storage.
    taskqueue_auto_run_tasks: A bool indicating whether taskqueue tasks should
        be run automatically or it the must be manually triggered.
    taskqueue_default_http_server: A str containing the address of the http
        server that should be used to execute tasks.
    uaserver_path: (AppScale-specific) A str containing the FQDN or IP address
        of the machine that runs a UserAppServer.
    user_login_url: A str containing the url that should be used for user login.
    user_logout_url: A str containing the url that should be used for user
        logout.
    xmpp_path: (AppScale-specific) A str containing the FQDN or IP address of
        the machine that runs ejabberd, where XMPP clients should connect to.
  """

  apiproxy_stub_map.apiproxy.RegisterStub(
      'app_identity_service',
      app_identity_stub.AppIdentityServiceStub())

  blob_storage = datastore_blob_storage.DatastoreBlobStorage(app_id)
  apiproxy_stub_map.apiproxy.RegisterStub(
      'blobstore',
      blobstore_stub.BlobstoreServiceStub(blob_storage,
                                          request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'capability_service',
      capability_stub.CapabilityServiceStub())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'channel',
      channel_service_stub.ChannelServiceStub(request_data=request_data))

  datastore = datastore_distributed.DatastoreDistributed(
      app_id, datastore_path, require_indexes=datastore_require_indexes,
      trusted=trusted, root_path=application_root)

  apiproxy_stub_map.apiproxy.ReplaceStub(
      'datastore_v3', datastore)

  apiproxy_stub_map.apiproxy.RegisterStub(
      'datastore_v4',
      datastore_v4_stub.DatastoreV4Stub(app_id))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'file',
      file_service_stub.FileServiceStub(blob_storage))

  serve_address = os.environ['NGINX_HOST']
  try:
    from google.appengine.api.images import images_stub
  except ImportError:

    logging.warning('Could not initialize images API; you are likely missing '
                    'the Python "PIL" module.')
    # We register a stub which throws a NotImplementedError for most RPCs.
    from google.appengine.api.images import images_not_implemented_stub
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_not_implemented_stub.ImagesNotImplementedServiceStub(
            host_prefix=images_host_prefix))
  else:
    host_prefix = 'http://{}'.format(serve_address)
    apiproxy_stub_map.apiproxy.RegisterStub(
        'images',
        images_stub.ImagesServiceStub(host_prefix=host_prefix))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'logservice',
      logservice_stub.LogServiceStub(persist=True))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'mail',
      mail_stub.MailServiceStub(mail_smtp_host,
                                mail_smtp_port,
                                mail_smtp_user,
                                mail_smtp_password,
                                enable_sendmail=mail_enable_sendmail,
                                show_mail_body=mail_show_mail_body))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'memcache',
      memcache_distributed.MemcacheService())

  apiproxy_stub_map.apiproxy.RegisterStub(
      'search',
      appscale_search_stub.SearchServiceStub(app_id=app_id))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'modules',
      modules_stub.ModulesServiceStub(request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'system',
      system_stub.SystemServiceStub(request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'taskqueue',
      taskqueue_distributed.TaskQueueServiceStub(app_id, serve_address))

  urlmatchers_to_fetch_functions = []
  urlmatchers_to_fetch_functions.extend(
      gcs_dispatcher.URLMATCHERS_TO_FETCH_FUNCTIONS)
  apiproxy_stub_map.apiproxy.RegisterStub(
      'urlfetch',
      urlfetch_stub.URLFetchServiceStub(
          urlmatchers_to_fetch_functions=urlmatchers_to_fetch_functions))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'user',
      user_service_stub.UserServiceStub(login_url=user_login_url,
                                        logout_url=user_logout_url,
                                        request_data=request_data))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'xmpp',
      xmpp_service_real.XmppService(domain=xmpp_path, uaserver=uaserver_path))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'matcher',
      prospective_search_stub.ProspectiveSearchStub(
          matcher_prospective_search_path,
          apiproxy_stub_map.apiproxy.GetStub('taskqueue')))

  apiproxy_stub_map.apiproxy.RegisterStub(
      'remote_socket',
      _remote_socket_stub.RemoteSocketServiceStub())
 def setUp(self, user_email=None, user_is_admin=False, **kwargs):
     super(NoUsersTest, self).setUp(**kwargs)
     stub = user_service_stub.UserServiceStub()
     self._RegisterStub('user', stub)