def test_load_or_import_from_config(): """Test load or import from config utility function.""" app = Flask('testapp') app.config['OBJ_KEY'] = wsgi_proxyfix app.config['PATH_KEY'] = 'invenio_base.wsgi.wsgi_proxyfix' with app.app_context(): assert load_or_import_from_config('OBJ_KEY') == wsgi_proxyfix assert load_or_import_from_config('PATH_KEY') == wsgi_proxyfix assert load_or_import_from_config( 'MISSING_KEY', default=wsgi_proxyfix) == wsgi_proxyfix
def test_load_or_import_from_config(): """Test load or import from config utility function.""" app = Flask("testapp") app.config["OBJ_KEY"] = wsgi_proxyfix app.config["PATH_KEY"] = "invenio_base.wsgi.wsgi_proxyfix" with app.app_context(): assert load_or_import_from_config("OBJ_KEY") == wsgi_proxyfix assert load_or_import_from_config("PATH_KEY") == wsgi_proxyfix assert (load_or_import_from_config( "MISSING_KEY", default=wsgi_proxyfix) == wsgi_proxyfix)
def __get__(self, obj, objtype=None): """Return value that was grafted on obj (descriptor protocol).""" if self.import_string: return load_or_import_from_config(app=obj._app, key=self.config_key, default=self.default) else: return obj._app.config.get(self.config_key, self.default)
def enabled_endpoints(self): """List of community-enabled REST endpoints.""" enabled_endpoints = load_or_import_from_config( 'OAREPO_COMMUNITIES_ENDPOINTS', app=self.app) return [ e for e in current_oarepo_ui.endpoints if e['name'] in enabled_endpoints ]
def load_config(self, config): """Load a configuration. Uses ``config`` if not None. Otherwise the method will try to load the config from a Flask configuration variable (named using the ``config_name`` attribute). Last it will use the config provided in ``default_config``. :param config: A service configuration or None. """ return config or load_or_import_from_config( self.config_name, default=self.default_config)
def permission_factory(self): """Load default permission factory for Community record collections.""" return load_or_import_from_config( 'OAREPO_COMMUNITIES_PERMISSION_FACTORY', app=self.app)
def role_parser(self): """Load default factory that parses community id and role from community role names.""" return load_or_import_from_config('OAREPO_COMMUNITIES_ROLE_PARSER', app=self.app)
def role_name_factory(self): """Load default factory that returns role name for community-based roles.""" return load_or_import_from_config('OAREPO_COMMUNITIES_ROLE_NAME', app=self.app)
def allowed_actions(self): """Community actions available to community roles.""" return load_or_import_from_config('OAREPO_COMMUNITIES_ALLOWED_ACTIONS', app=self.app)
def roles(self): """Roles created in each community.""" return load_or_import_from_config('OAREPO_COMMUNITIES_ROLES', app=self.app)
def default_action_matrix(self): """Default action2role permission matrix for newly created communities.""" return load_or_import_from_config('OAREPO_COMMUNITIES_DEFAULT_ACTIONS', app=self.app)
def __init__(self, **kwargs): """Constructor.""" schema = load_or_import_from_config("ACCOUNTS_USER_PREFERENCES_SCHEMA") super().__init__(schema, **kwargs)