def base_app(): """Flask applicat-ion fixture.""" instance_path = os.path.join(sys.prefix, 'var', 'test-instance') # empty the instance path if os.path.exists(instance_path): shutil.rmtree(instance_path) os.makedirs(instance_path) os.environ['INVENIO_INSTANCE_PATH'] = instance_path app_ = Flask('invenio-records-draft-testapp', instance_path=instance_path) app_.config.update( TESTING=True, JSON_AS_ASCII=True, SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///:memory:'), SERVER_NAME='localhost:5000', SECURITY_PASSWORD_SALT='TEST_SECURITY_PASSWORD_SALT', SECRET_KEY='TEST_SECRET_KEY', INVENIO_INSTANCE_PATH=instance_path, SEARCH_INDEX_PREFIX='test-', RECORDS_REST_ENDPOINTS={}, JSONSCHEMAS_HOST='localhost:5000', SEARCH_ELASTIC_HOSTS=os.environ.get('SEARCH_ELASTIC_HOSTS', None)) make_versioned() app.test_client_class = JsonClient from oarepo_records_draft import config # noqa InvenioDB(app_) InvenioIndexer(app_) InvenioSearch(app_) RecordsDraft(app_) return app_
def app(): instance_path = tempfile.mkdtemp() app = Flask('testapp', instance_path=instance_path) app.config.update( JSONSCHEMAS_HOST="nusl.cz", SQLALCHEMY_TRACK_MODIFICATIONS=True, SERVER_NAME='127.0.0.1:5000', INVENIO_INSTANCE_PATH=instance_path, DEBUG=True, # in tests, api is not on /api but directly in the root PIDSTORE_RECID_FIELD='pid', FLASK_TAXONOMIES_URL_PREFIX='/2.0/taxonomies/', # RECORDS_REST_ENDPOINTS=RECORDS_REST_ENDPOINTS, CELERY_BROKER_URL='amqp://*****:*****@localhost:5672//', CELERY_TASK_ALWAYS_EAGER=True, CELERY_RESULT_BACKEND='cache', CELERY_CACHE_BACKEND='memory', CELERY_TASK_EAGER_PROPAGATES=True, SUPPORTED_LANGUAGES=["cs", "en"], OAREPO_COMMUNITIES_ENDPOINTS=[], ELASTICSEARCH_DEFAULT_LANGUAGE_TEMPLATE={ "type": "text", "fields": { "keywords": { "type": "keyword" } } }) app.secret_key = 'changeme' print(os.environ.get("INVENIO_INSTANCE_PATH")) InvenioDB(app) OarepoTaxonomies(app) OARepoReferences(app) InvenioAccounts(app) InvenioAccess(app) Principal(app) InvenioJSONSchemas(app) InvenioSearch(app) InvenioIndexer(app) OARepoMappingIncludesExt(app) InvenioRecords(app) InvenioRecordsREST(app) InvenioCelery(app) NRNresults(app) InvenioPIDStore(app) OARepoValidate(app) OARepoCommunities(app) # Invenio Records Draft initialization RecordsDraft(app) app.url_map.converters['pid'] = PIDConverter app.url_map.converters['commpid'] = CommunityPIDConverter # Celery print(app.config["CELERY_BROKER_URL"]) login_manager = LoginManager() login_manager.init_app(app) login_manager.login_view = 'login' @login_manager.user_loader def basic_user_loader(user_id): user_obj = User.query.get(int(user_id)) return user_obj app.register_blueprint(create_blueprint_from_app(app)) @app.route('/test/login/<int:id>', methods=['GET', 'POST']) def test_login(id): print("test: logging user with id", id) response = make_response() user = User.query.get(id) login_user(user) set_identity(user) return response # app.extensions['invenio-search'].mappings["test"] = mapping # app.extensions["invenio-jsonschemas"].schemas["test"] = schema app_loaded.send(app, app=app) with app.app_context(): # app.register_blueprint(taxonomies_blueprint) print(app.url_map) yield app shutil.rmtree(instance_path)
def base_app(app_config): """Flask application fixture.""" instance_path = os.path.join(sys.prefix, 'var', 'test-instance') # empty the instance path if os.path.exists(instance_path): shutil.rmtree(instance_path) os.makedirs(instance_path) os.environ['INVENIO_INSTANCE_PATH'] = instance_path app_ = Flask('oarepo-s3-testapp', instance_path=instance_path) app_.config.update( TESTING=True, JSON_AS_ASCII=True, FILES_REST_PERMISSION_FACTORY=allow_all, SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'sqlite:///:memory:'), SERVER_NAME='localhost:5000', SECURITY_PASSWORD_SALT='TEST_SECURITY_PASSWORD_SALT', SECRET_KEY='TEST_SECRET_KEY', INVENIO_INSTANCE_PATH=instance_path, # SEARCH_INDEX_PREFIX='records-', RECORDS_REST_ENDPOINTS={}, SEARCH_INDEX_PREFIX='test-', FILES_REST_DEFAULT_STORAGE_CLASS='S', CELERY_ALWAYS_EAGER=True, JSONSCHEMAS_HOST='localhost:5000', SEARCH_ELASTIC_HOSTS=os.environ.get('SEARCH_ELASTIC_HOSTS', None) ) app_.config.update(**app_config) app.test_client_class = JsonClient Principal(app_) login_manager = LoginManager() login_manager.init_app(app_) login_manager.login_view = 'login' @login_manager.user_loader def basic_user_loader(user_id): user_obj = User.query.get(int(user_id)) return user_obj @app_.route('/test/login/<int:id>', methods=['GET', 'POST']) def test_login(id): print("test: logging user with id", id) response = make_response() user = User.query.get(id) print('User is', user) login_user(user) set_identity(user) return response @app_.route('/test/logout', methods=['GET', 'POST']) def test_logout(): print("test: logging out") response = make_response() logout_user() # Remove session keys set by Flask-Principal for key in ('identity.name', 'identity.auth_type'): session.pop(key, None) # Tell Flask-Principal the user is anonymous identity_changed.send(current_app._get_current_object(), identity=AnonymousIdentity()) return response from oarepo_s3 import config # noqa InvenioAccess(app_) InvenioDB(app_) InvenioFilesREST(app_) InvenioS3(app_) InvenioIndexer(app_) InvenioSearch(app_) RecordsDraft(app_) OARepoS3(app_) return app_
def app(): instance_path = tempfile.mkdtemp() app = Flask('testapp', instance_path=instance_path) app.config.update( JSONSCHEMAS_HOST="nusl.cz", SQLALCHEMY_TRACK_MODIFICATIONS=True, SERVER_NAME='127.0.0.1:5000', INVENIO_INSTANCE_PATH=instance_path, DEBUG=True, # SQLALCHEMY_ECHO=True, SUPPORTED_LANGUAGES=["cs", "en"], # SQLALCHEMY_DATABASE_URI='postgresql+psycopg2://oarepo:oarepo@localhost/oarepo', OAREPO_COMMUNITIES_ENDPOINTS=[], OAREPO_OAI_PROVIDERS={ "nusl": { "description": "NUŠL", "synchronizers": [{ "name": "marcxml", "oai_endpoint": "http://invenio.nusl.cz/oai2d/", "set": "global", "metadata_prefix": "marcxml", "unhandled_paths": [ '/leader', '/005', '/008', '020__/q', '/0248_', '/246__', '/340__', '/500__', '/502__/a', '/502__/b', '/502__/d', '/502__/g', '/506__', '/6530_', '/6557_', '/655_7', "/656_7/2", '/8560_', '/85642/z', '/8564_', '/909CO/p', '999c1', '/999C2', 'FFT_0' ], "default_endpoint": "common", }] }, }, # RECORDS_REST_ENDPOINTS=RECORDS_REST_ENDPOINTS, PIDSTORE_RECID_FIELD='pid') app.secret_key = 'changeme' InvenioDB(app) InvenioAccounts(app) InvenioAccess(app) Principal(app) InvenioJSONSchemas(app) InvenioSearch(app) InvenioIndexer(app) InvenioRecords(app) InvenioRecordsREST(app) InvenioPIDStore(app) app.url_map.converters['pid'] = PIDConverter app.url_map.converters['commpid'] = CommunityPIDConverter OarepoTaxonomies(app) OArepoOAIClient(app) OARepoValidate(app) RecordsDraft(app) # NRCommon(app) NRTheses(app) NRNresults(app) NREvents(app) app_loaded.send(app, app=app) with app.app_context(): yield app shutil.rmtree(instance_path)