def base_app(): """Flask application fixture.""" app_ = Flask('testapp') 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', SECURITY_PASSWORD_SALT='TEST_SECURITY_PASSWORD_SALT', SECRET_KEY='TEST_SECRET_KEY', FILES_REST_MULTIPART_CHUNKSIZE_MIN=2, FILES_REST_MULTIPART_CHUNKSIZE_MAX=20, FILES_REST_MULTIPART_MAX_PARTS=100, FILES_REST_TASK_WAIT_INTERVAL=0.1, FILES_REST_TASK_WAIT_MAX_SECONDS=1, TAXONOMY_SERVER_NAME='taxonomy-server.com', TAXONOMY_REDIS_URL='redis://localhost:6379/15', ) app.test_client_class = JsonClient InvenioDB(app_) InvenioAccounts(app_) InvenioAccess(app_) InvenioJSONSchemas(app_) OARepoReferences(app_) app_.extensions['oarepo-references'] = RecordReferencesStateMock(app_) return app_
def app(request): """Test mdcobject.""" instance_path = tempfile.mkdtemp() app = Flask('testapp', instance_path=instance_path) app.config.update(ACCOUNTS_JWT_ENABLE=False, INDEXER_DEFAULT_DOC_TYPE='record-v1.0.0', RECORDS_REST_ENDPOINTS={}, RECORDS_REST_DEFAULT_CREATE_PERMISSION_FACTORY=None, RECORDS_REST_DEFAULT_DELETE_PERMISSION_FACTORY=None, RECORDS_REST_DEFAULT_READ_PERMISSION_FACTORY=None, RECORDS_REST_DEFAULT_UPDATE_PERMISSION_FACTORY=None, SERVER_NAME='localhost:5000', JSONSCHEMAS_HOST='localhost:5000', CELERY_ALWAYS_EAGER=True, CELERY_RESULT_BACKEND='cache', CELERY_CACHE_BACKEND='memory', FLASK_TAXONOMIES_URL_PREFIX='/2.0/taxonomies/', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), SQLALCHEMY_TRACK_MODIFICATIONS=True, SUPPORTED_LANGUAGES=["cs", "en"], TESTING=True, ELASTICSEARCH_DEFAULT_LANGUAGE_TEMPLATE={ "type": "text", "fields": { "keywords": { "type": "keyword" } } }) app.secret_key = 'changeme' InvenioDB(app) OarepoTaxonomies(app) OARepoReferences(app) InvenioRecords(app) InvenioJSONSchemas(app) InvenioPIDStore(app) InvenioSearch(app) InvenioIndexer(app) OARepoMappingIncludesExt(app) # app_loaded.send(app, app=app) with app.app_context(): yield app # Teardown instance path. shutil.rmtree(instance_path)
def test_init(): """Test extension initialization.""" app = Flask('testapp') ext = OARepoReferences(app) assert 'oarepo-references' in app.extensions app = Flask('testapp') ext = OARepoReferences() assert 'oarepo-references' not in app.extensions ext.init_app(app) assert 'oarepo-references' in app.extensions
def factory(**config): app = Flask('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', SECURITY_PASSWORD_SALT='TEST_SECURITY_PASSWORD_SALT', SECRET_KEY='TEST_SECRET_KEY', ) Babel(app) InvenioDB(app) InvenioJSONSchemas(app) InvenioRecords(app) InvenioSearch(app) OARepoReferences(app) return app
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', SECURITY_PASSWORD_SALT='TEST_SECURITY_PASSWORD_SALT', SECRET_KEY='TEST_SECRET_KEY', INVENIO_INSTANCE_PATH=instance_path, SEARCH_INDEX_PREFIX='test-', JSONSCHEMAS_HOST='localhost' ) app.test_client_class = JsonClient InvenioDB(app_) InvenioIndexer(app_) InvenioSearch(app_) print('records draft registered to app') InvenioRecordsDraft(app_) OARepoReferences(app_) OARepoReferencesDraft(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 ref_url(self, data): return data.get('links', {}).get('self', None) def ref_uuid(self, data): return data.get('id', None) class ExampleRecord(MarshmallowValidatedRecordMixin, ReferenceEnabledRecordMixin, Record): """References enabled example record class.""" MARSHMALLOW_SCHEMA = ExampleInlineReferenceSchema VALIDATE_MARSHMALLOW = True VALIDATE_PATCH = True @property def canonical_url(self): return url_for('invenio_records_rest.recid_item', pid_value=self['pid'], _external=True) # Create Flask application app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get( 'SQLALCHEMY_DATABASE_URI', "sqlite:///:memory:") app.config['SERVER_NAME'] = os.environ.get('SERVER_NAME', '127.0.0.1:5000') app.config['PREFERRED_URL_SCHEME'] = 'http' app.config["SQLALCHEMY_ECHO"] = True Babel(app) OARepoReferences(app)
def app(mapping, schema): instance_path = tempfile.mkdtemp() app = Flask('testapp', instance_path=instance_path) app.config.update( JSONSCHEMAS_HOST="example.com", 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) 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) OARepoMappingIncludesExt(app) InvenioRecords(app) InvenioRecordsREST(app) InvenioCelery(app) OARepoValidate(app) # 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) yield app shutil.rmtree(instance_path)