Example #1
0
 def __init__(self,
              ini,
              config_file_name,
              extra_environ,
              setup_request=False,
              setup_rdb_context=False,
              remote_user_id=None):
     wsgiapp = loadapp('config:' + ini.ini_file_path, name=ini.app_name)
     if not remote_user_id is None:
         extra_environ['REMOTE_USER'] = remote_user_id
     self.__app = EverestTestApp(wsgiapp,
                                 ini.package_name,
                                 extra_environ=extra_environ)
     self.__config_file_name = config_file_name
     if setup_request:
         kw = dict(application_url=ini.app_url,
                   host_url=ini.app_url,
                   path_url=ini.app_url,
                   url=ini.app_url,
                   registry=self.__app.config.registry)
         if not remote_user_id is None:
             self.__app.config.testing_securitypolicy(remote_user_id)
             kw['environ'] = dict(REMOTE_USER=remote_user_id)
         self.__request = DummyRequest(**kw)
     elif not remote_user_id is None:
         raise ValueError('The remote_user_id argument requires the '
                          'setup_request argument to be True.')
     else:
         self.__request = None
     if setup_rdb_context:
         self.__rdb_context = RdbContextManager()
     else:
         self.__rdb_context = None
Example #2
0
 def _test_load(self, num_entities=2):
     with RdbContextManager() as session:
         query = session.query(self.entity_class)
         entities = query.limit(num_entities).all()
         self.assert_equal(len(entities), num_entities)
         for entity in entities:
             self.assert_equal(entity.__class__, self.entity_class)
Example #3
0
 def __init__(self, ini, config_file_name, extra_environ,
              setup_request=False, setup_rdb_context=False,
              remote_user_id=None):
     wsgiapp = loadapp('config:' + ini.ini_file_path, name=ini.app_name)
     if not remote_user_id is None:
         extra_environ['REMOTE_USER'] = remote_user_id
     self.__app = EverestTestApp(wsgiapp, ini.package_name,
                                 extra_environ=extra_environ)
     self.__config_file_name = config_file_name
     if setup_request:
         kw = dict(application_url=ini.app_url,
                   host_url=ini.app_url,
                   path_url=ini.app_url,
                   url=ini.app_url,
                   registry=self.__app.config.registry)
         if not remote_user_id is None:
             self.__app.config.testing_securitypolicy(remote_user_id)
             kw['environ'] = dict(REMOTE_USER=remote_user_id)
         self.__request = DummyRequest(**kw)
     elif not remote_user_id is None:
         raise ValueError('The remote_user_id argument requires the '
                          'setup_request argument to be True.')
     else:
         self.__request = None
     if setup_rdb_context:
         self.__rdb_context = RdbContextManager()
     else:
         self.__rdb_context = None
Example #4
0
 def _test_persist(self):
     with RdbContextManager() as session:
         attrs = self._get_data()
         persist(session, self.entity_class, attrs, True)
Example #5
0
def nested_session():
    with RdbContextManager() as sess:
        yield sess
Example #6
0
class AppCreatorContextManager(object):
    """
    Context manager for setting up the everest framework for application
    level (functional) operations.
    """
    def __init__(self,
                 ini,
                 config_file_name,
                 extra_environ,
                 setup_request=False,
                 setup_rdb_context=False,
                 remote_user_id=None):
        wsgiapp = loadapp('config:' + ini.ini_file_path, name=ini.app_name)
        if not remote_user_id is None:
            extra_environ['REMOTE_USER'] = remote_user_id
        self.__app = EverestTestApp(wsgiapp,
                                    ini.package_name,
                                    extra_environ=extra_environ)
        self.__config_file_name = config_file_name
        if setup_request:
            kw = dict(application_url=ini.app_url,
                      host_url=ini.app_url,
                      path_url=ini.app_url,
                      url=ini.app_url,
                      registry=self.__app.config.registry)
            if not remote_user_id is None:
                self.__app.config.testing_securitypolicy(remote_user_id)
                kw['environ'] = dict(REMOTE_USER=remote_user_id)
            self.__request = DummyRequest(**kw)
        elif not remote_user_id is None:
            raise ValueError('The remote_user_id argument requires the '
                             'setup_request argument to be True.')
        else:
            self.__request = None
        if setup_rdb_context:
            self.__rdb_context = RdbContextManager()
        else:
            self.__rdb_context = None

    def __enter__(self):
        self.__app.config.begin(request=self.__request)
        if not self.__request is None:
            srvc = self.__app.config.get_registered_utility(IService)
            self.__request.root = srvc
        if not self.__config_file_name is None:
            self.__app.config.load_zcml(self.__config_file_name)
        repo_mgr = \
            self.__app.config.get_registered_utility(IRepositoryManager)
        repo_mgr.initialize_all()
        if not self.__request is None:
            srvc.start()
        if not self.__rdb_context is None:
            self.__rdb_context.__enter__()
        return self.__app

    def __exit__(self, ext_type, value, tb):
        if self.__rdb_context is None:
            transaction.abort()
        else:
            self.__rdb_context.__exit__(ext_type, value, tb)
        if not self.__request is None:
            srvc = self.__app.config.get_registered_utility(IService)
            srvc.stop()
        repo_mgr = \
            self.__app.config.get_registered_utility(IRepositoryManager)
        repo_mgr.reset_all()
        self.__app.config.end()
        tear_down_registry(self.__app.config.registry)
Example #7
0
class AppCreatorContextManager(object):
    """
    Context manager for setting up the everest framework for application
    level (functional) operations.
    """
    def __init__(self, ini, config_file_name, extra_environ,
                 setup_request=False, setup_rdb_context=False,
                 remote_user_id=None):
        wsgiapp = loadapp('config:' + ini.ini_file_path, name=ini.app_name)
        if not remote_user_id is None:
            extra_environ['REMOTE_USER'] = remote_user_id
        self.__app = EverestTestApp(wsgiapp, ini.package_name,
                                    extra_environ=extra_environ)
        self.__config_file_name = config_file_name
        if setup_request:
            kw = dict(application_url=ini.app_url,
                      host_url=ini.app_url,
                      path_url=ini.app_url,
                      url=ini.app_url,
                      registry=self.__app.config.registry)
            if not remote_user_id is None:
                self.__app.config.testing_securitypolicy(remote_user_id)
                kw['environ'] = dict(REMOTE_USER=remote_user_id)
            self.__request = DummyRequest(**kw)
        elif not remote_user_id is None:
            raise ValueError('The remote_user_id argument requires the '
                             'setup_request argument to be True.')
        else:
            self.__request = None
        if setup_rdb_context:
            self.__rdb_context = RdbContextManager()
        else:
            self.__rdb_context = None

    def __enter__(self):
        self.__app.config.begin(request=self.__request)
        if not self.__request is None:
            srvc = self.__app.config.get_registered_utility(IService)
            self.__request.root = srvc
        if not self.__config_file_name is None:
            self.__app.config.load_zcml(self.__config_file_name)
        repo_mgr = \
            self.__app.config.get_registered_utility(IRepositoryManager)
        repo_mgr.initialize_all()
        if not self.__request is None:
            srvc.start()
        if not self.__rdb_context is None:
            self.__rdb_context.__enter__()
        return self.__app

    def __exit__(self, ext_type, value, tb):
        if self.__rdb_context is None:
            transaction.abort()
        else:
            self.__rdb_context.__exit__(ext_type, value, tb)
        if not self.__request is None:
            srvc = self.__app.config.get_registered_utility(IService)
            srvc.stop()
        repo_mgr = \
            self.__app.config.get_registered_utility(IRepositoryManager)
        repo_mgr.reset_all()
        self.__app.config.end()
        tear_down_registry(self.__app.config.registry)