def app(request): """Flask application fixture.""" instance_path = tempfile.mkdtemp() app = Flask('testapp', instance_path=instance_path) app.config.update( # HTTPretty doesn't play well with Redis. # See gabrielfalcao/HTTPretty#110 CACHE_TYPE='simple', CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND='cache', GITHUB_SHIELDSIO_BASE_URL='http://example.org/badge/', GITHUB_APP_CREDENTIALS=dict( consumer_key='changeme', consumer_secret='changeme', ), LOGIN_DISABLED=False, OAUTHLIB_INSECURE_TRANSPORT=True, OAUTH2_CACHE_TYPE='simple', OAUTHCLIENT_REMOTE_APPS=dict( github=REMOTE_APP, ), SECRET_KEY='test_key', SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], TESTING=True, WTF_CSRF_ENABLED=False, ) app.url_map.converters['pid'] = PIDConverter FlaskCLI(app) celeryext = FlaskCeleryExt(app) celeryext.celery.flask_app = app # Make sure both apps are the same! Babel(app) Mail(app) Menu(app) Breadcrumbs(app) InvenioDB(app) InvenioAccounts(app) app.register_blueprint(accounts_blueprint) InvenioOAuthClient(app) app.register_blueprint(oauthclient_blueprint) InvenioOAuth2Server(app) app.register_blueprint(server_blueprint) app.register_blueprint(settings_blueprint) InvenioPIDStore(app) InvenioRecordsREST(app) InvenioDepositREST(app) InvenioWebhooks(app) app.register_blueprint(webhooks_blueprint) InvenioGitHub(app) with app.app_context(): yield app shutil.rmtree(instance_path)
def test_conflict_in_endpoint_prefixes(): """Test conflict in endpoint prefixes.""" app = Flask('testapp') app.url_map.converters['pid'] = PIDConverter InvenioRecordsREST(app) ext = InvenioDepositREST() ext.init_config(app) endpoints = app.config['RECORDS_REST_ENDPOINTS'] deposit_endpoints = deepcopy(app.config['DEPOSIT_REST_ENDPOINTS']) deposit_endpoints['recid'] = endpoints['recid'] app.config['DEPOSIT_REST_ENDPOINTS'] = deposit_endpoints # check endpoint profixes with pytest.raises(RuntimeError) as err: ext.init_app(app) assert 'recid' in str(err)
def app(): """Flask application fixture.""" instance_path = tempfile.mkdtemp() app_ = Flask(__name__, instance_path=instance_path) app_.config.update( CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND='cache', JSONSCHEMAS_URL_SCHEME='http', SECRET_KEY='CHANGE_ME', SECURITY_PASSWORD_SALT='CHANGE_ME_ALSO', SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_ECHO=False, TESTING=True, WTF_CSRF_ENABLED=False, DEPOSIT_SEARCH_API='/api/search', SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], SECURITY_DEPRECATED_PASSWORD_SCHEMES=[], OAUTHLIB_INSECURE_TRANSPORT=True, OAUTH2_CACHE_TYPE='simple', ) app_.url_map.converters['pid'] = PIDConverter FlaskCLI(app_) Babel(app_) FlaskCeleryExt(app_) InvenioDB(app_) Breadcrumbs(app_) InvenioAccounts(app_) InvenioAccess(app_) app_.register_blueprint(accounts_blueprint) InvenioAssets(app_) InvenioJSONSchemas(app_) InvenioSearch(app_) InvenioRecords(app_) app_.url_map.converters['pid'] = PIDConverter InvenioRecordsREST(app_) InvenioPIDStore(app_) InvenioIndexer(app_) InvenioDeposit(app_) InvenioSearchUI(app_) InvenioRecordsUI(app_) InvenioFilesREST(app_) OAuth2Provider(app_) InvenioOAuth2Server(app_) InvenioOAuth2ServerREST(app_) app_.register_blueprint(oauth2server_settings_blueprint) InvenioDepositREST(app_) with app_.app_context(): yield app_ shutil.rmtree(instance_path)
def previewer_deposit(app): """.""" # FIXME workaround for previewer tests because they require app and api_app from invenio_records_rest import InvenioRecordsREST from invenio_deposit import InvenioDepositREST from invenio_records_rest.utils import PIDConverter backup = app.debug app.debug = False if 'invenio-records-rest' not in app.extensions: InvenioRecordsREST(app) if 'invenio-deposit-rest' not in app.extensions: InvenioDepositREST(app) app.url_map.converters['pid'] = PIDConverter app.debug = backup return app
def test_conflict_in_endpoint_prefixes(): """Test conflict in endpoint prefixes.""" app = Flask('testapp') app.url_map.converters['pid'] = PIDConverter InvenioRecordsREST(app) ext = InvenioDepositREST() ext.init_config(app) endpoints = app.config['RECORDS_REST_ENDPOINTS'] deposit_endpoints = deepcopy(app.config['DEPOSIT_REST_ENDPOINTS']) deposit_endpoints['recid'] = endpoints['recid'] app.config['DEPOSIT_REST_ENDPOINTS'] = deposit_endpoints ext.init_app(app) with app.test_client() as c: assert 500 == c.get('/').status_code
def test_conflict_in_endpoint_prefixes(): """Test conflict in endpoint prefixes.""" app = Flask('testapp') app.url_map.converters['pid'] = PIDConverter InvenioRecordsREST(app) ext = InvenioDepositREST() ext.init_config(app) endpoints = app.config['RECORDS_REST_ENDPOINTS'] # Due to incompatibilty with how we are registering endpoints between # invenio packages we need to now sanitize the endpoints registered in this # test. for endpoint in endpoints: endpoints[endpoint].pop('error_handlers', None) deposit_endpoints = deepcopy(app.config['DEPOSIT_REST_ENDPOINTS']) deposit_endpoints['recid'] = endpoints['recid'] app.config['DEPOSIT_REST_ENDPOINTS'] = deposit_endpoints ext.init_app(app) with app.test_client() as c: assert 500 == c.get('/').status_code
def base_app(request, test_metadata_format): """Flask application fixture.""" instance_path = tempfile.mkdtemp() def init_app(app_): app_.config.update( CELERY_ALWAYS_EAGER=False, CELERY_CACHE_BACKEND="memory", CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND="cache", JSONSCHEMAS_URL_SCHEME="http", SECRET_KEY="CHANGE_ME", SECURITY_PASSWORD_SALT="CHANGE_ME_ALSO", SQLALCHEMY_DATABASE_URI=os.environ.get("SQLALCHEMY_DATABASE_URI", "sqlite:///test.db"), SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_ECHO=False, TESTING=True, WTF_CSRF_ENABLED=False, DEPOSIT_SEARCH_API="/api/search", SECURITY_PASSWORD_HASH="plaintext", SECURITY_PASSWORD_SCHEMES=["plaintext"], SECURITY_DEPRECATED_PASSWORD_SCHEMES=[], THEME_SITENAME="Test Site", OAUTHLIB_INSECURE_TRANSPORT=True, OAUTH2_CACHE_TYPE="simple", ACCOUNTS_JWT_ENABLE=False, # This allows access to files across all of invenio-files-rest FILES_REST_PERMISSION_FACTORY=lambda *a, **kw: type( "Allow", (object, ), {"can": lambda self: True})(), FILES_REST_MULTIPART_CHUNKSIZE_MIN=10, ) Babel(app_) FlaskCeleryExt(app_) Breadcrumbs(app_) OAuth2Provider(app_) InvenioDB(app_) InvenioAccounts(app_) InvenioAccess(app_) InvenioIndexer(app_) InvenioJSONSchemas(app_) InvenioOAuth2Server(app_) InvenioPIDStore(app_) InvenioRecords(app_) search = InvenioSearch(app_) search.register_mappings("deposits", "invenio_deposit.mappings") api_app = Flask("testapiapp", instance_path=instance_path) api_app.url_map.converters["pid"] = PIDConverter # initialize InvenioDeposit first in order to detect any invalid dependency InvenioDepositREST(api_app) init_app(api_app) InvenioREST(api_app) InvenioOAuth2ServerREST(api_app) InvenioRecordsREST(api_app) InvenioFilesREST(api_app) InvenioSword(api_app) api_app.register_blueprint(files_rest_blueprint) # api_app.register_blueprint(records_files_bp(api_app)) api_app.register_blueprint(records_rest_bp(api_app)) api_app.register_blueprint(invenio_files_rest_blueprint) # Register a test (alternate) metadata format api_app.config["SWORD_ENDPOINTS"]["depid"]["metadata_formats"][ test_metadata_format] = TestMetadata app = Flask("testapp", instance_path=instance_path) app.url_map.converters["pid"] = PIDConverter # initialize InvenioDeposit first in order to detect any invalid dependency InvenioDeposit(app) init_app(app) app.register_blueprint(accounts_blueprint) app.register_blueprint(oauth2server_settings_blueprint) InvenioAssets(app) InvenioSearchUI(app) InvenioRecordsUI(app) app.register_blueprint(records_ui_bp(app)) app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {"/api": api_app.wsgi_app}) with app.app_context(): if str(db.engine.url) != "sqlite://" and not database_exists( str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() yield app with app.app_context(): if str(db.engine.url) != "sqlite://": drop_database(str(db.engine.url)) shutil.rmtree(instance_path)
def base_app(request): """Flask application fixture.""" instance_path = tempfile.mkdtemp() def init_app(app_): app_.config.update( CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND='cache', JSONSCHEMAS_URL_SCHEME='http', SECRET_KEY='CHANGE_ME', SECURITY_PASSWORD_SALT='CHANGE_ME_ALSO', SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_ECHO=False, TESTING=True, WTF_CSRF_ENABLED=False, DEPOSIT_SEARCH_API='/api/search', SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], SECURITY_DEPRECATED_PASSWORD_SCHEMES=[], OAUTHLIB_INSECURE_TRANSPORT=True, OAUTH2_CACHE_TYPE='simple', ACCOUNTS_JWT_ENABLE=False, ) Babel(app_) FlaskCeleryExt(app_) Breadcrumbs(app_) OAuth2Provider(app_) InvenioDB(app_) InvenioAccounts(app_) InvenioAccess(app_) InvenioIndexer(app_) InvenioJSONSchemas(app_) InvenioOAuth2Server(app_) InvenioFilesREST(app_) InvenioPIDStore(app_) InvenioRecords(app_) search = InvenioSearch(app_) search.register_mappings('deposits', 'invenio_deposit.mappings') api_app = Flask('testapiapp', instance_path=instance_path) api_app.url_map.converters['pid'] = PIDConverter # initialize InvenioDeposit first in order to detect any invalid dependency InvenioDepositREST(api_app) init_app(api_app) InvenioREST(api_app) InvenioOAuth2ServerREST(api_app) InvenioRecordsREST(api_app) app = Flask('testapp', instance_path=instance_path) app.url_map.converters['pid'] = PIDConverter # initialize InvenioDeposit first in order to detect any invalid dependency InvenioDeposit(app) init_app(app) app.register_blueprint(accounts_blueprint) app.register_blueprint(oauth2server_settings_blueprint) InvenioAssets(app) InvenioSearchUI(app) InvenioRecordsUI(app) app.register_blueprint(records_ui_bp(app)) app.register_blueprint(records_rest_bp(app)) app.wsgi_app = DispatcherMiddleware(app.wsgi_app, { '/api': api_app.wsgi_app }) with app.app_context(): if str(db.engine.url) != 'sqlite://' and \ not database_exists(str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() yield app with app.app_context(): if str(db.engine.url) != 'sqlite://': drop_database(str(db.engine.url)) shutil.rmtree(instance_path)
# search.register_mappings('testrecords', 'data') InvenioSearchUI(app) InvenioREST(app) InvenioIndexer(app) InvenioPIDStore(app) InvenioAdmin(app) InvenioOAuth2Server(app) InvenioRecordsREST(app) InvenioFilesREST(app) assets = InvenioAssets(app) assets.env.register('invenio_search_ui_search_js', js) InvenioDeposit(app) InvenioDepositREST(app) app.register_blueprint(accounts_blueprint) app.register_blueprint(settings_blueprint) app.register_blueprint(server_blueprint) @app.cli.group() def fixtures(): """Command for working with test data.""" @fixtures.command() @with_appcontext def records():
def deposit_rest(app, records_rest_app): """Init deposit REST API.""" if 'invenio-deposit-rest' not in app.extensions: InvenioDepositREST(app) app.url_map.converters['pid'] = PIDConverter return app
def app(request): """Flask application fixture.""" instance_path = tempfile.mkdtemp() app_ = Flask('testapp', instance_path=instance_path) app_.config.update( # HTTPretty doesn't play well with Redis. # See gabrielfalcao/HTTPretty#110 CACHE_TYPE='simple', CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND='cache', GITHUB_APP_CREDENTIALS=dict( consumer_key='changeme', consumer_secret='changeme', ), GITHUB_PID_FETCHER='doi_fetcher', LOGIN_DISABLED=False, OAUTHLIB_INSECURE_TRANSPORT=True, OAUTH2_CACHE_TYPE='simple', OAUTHCLIENT_REMOTE_APPS=dict(github=REMOTE_APP, ), SECRET_KEY='test_key', SERVER_NAME='testserver', SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], SECURITY_DEPRECATED_PASSWORD_SCHEMES=[], TESTING=True, WTF_CSRF_ENABLED=False, ) app_.config['OAUTHCLIENT_REMOTE_APPS']['github']['params'][ 'request_token_params'][ 'scope'] = 'user:email,admin:repo_hook,read:org' app_.url_map.converters['pid'] = PIDConverter celeryext = FlaskCeleryExt(app_) Babel(app_) Mail(app_) Menu(app_) Breadcrumbs(app_) InvenioAssets(app_) InvenioDB(app_) InvenioAccounts(app_) app_.register_blueprint(accounts_blueprint) InvenioOAuthClient(app_) app_.register_blueprint(oauthclient_blueprint) InvenioOAuth2Server(app_) app_.register_blueprint(server_blueprint) app_.register_blueprint(settings_blueprint) InvenioFormatter(app_) from .helpers import doi_fetcher pidstore = InvenioPIDStore(app_) pidstore.register_fetcher('doi_fetcher', doi_fetcher) InvenioJSONSchemas(app_) InvenioRecords(app_) InvenioSearch(app_) InvenioIndexer(app_) InvenioFilesREST(app_) InvenioRecordsREST(app_) InvenioDepositREST(app_) InvenioWebhooks(app_) celeryext.celery.flask_app = app_ # Make sure both apps are the same! app_.register_blueprint(webhooks_blueprint) InvenioGitHub(app_) app_.register_blueprint(github_blueprint) app_.register_blueprint(github_badge_blueprint) with app_.app_context(): yield app_ shutil.rmtree(instance_path)