def app(): """Flask application fixture with database initialization.""" instance_path = tempfile.mkdtemp() app_ = Flask( 'testapp', static_folder=instance_path, instance_path=instance_path) app_.config.update( TESTING=True, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', 'sqlite:///:memory:'), SQLALCHEMY_TRACK_MODIFICATIONS=True, RECORDS_UI_DEFAULT_PERMISSION_FACTORY=None, RECORDS_UI_ENDPOINTS=dict( recid=dict( pid_type='recid', route='/records/<pid_value>', template='invenio_records_ui/detail.html', ), recid_previewer=dict( pid_type='recid', route='/records/<pid_value>/preview/<filename>', view_imp='invenio_previewer.views:preview', record_class='invenio_records_files.api:Record', ), recid_files=dict( pid_type='recid', route='/record/<pid_value>/files/<filename>', view_imp='invenio_records_files.utils.file_download_ui', record_class='invenio_records_files.api:Record', ), ), SERVER_NAME='localhost' ) Babel(app_) assets_ext = InvenioAssets(app_) InvenioDB(app_) InvenioRecords(app_) previewer = InvenioPreviewer(app_)._state InvenioRecordsUI(app_) InvenioFilesREST(app_) # Add base assets bundles for jQuery and Bootstrap # Note: These bundles aren't included by default since package consumers # should handle assets and their dependencies manually. assets_ext.env.register(previewer.js_bundles[0], previewer_base_js) assets_ext.env.register(previewer.css_bundles[0], previewer_base_css) with app_.app_context(): yield app_ shutil.rmtree(instance_path)
def app(): """Flask application fixture with database initialization.""" instance_path = tempfile.mkdtemp() app_ = Flask('testapp', static_folder=instance_path, instance_path=instance_path) app_.config.update( TESTING=True, SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite:///:memory:'), SQLALCHEMY_TRACK_MODIFICATIONS=True, RECORDS_UI_DEFAULT_PERMISSION_FACTORY=None, RECORDS_UI_ENDPOINTS=dict( recid=dict( pid_type='recid', route='/records/<pid_value>', template='invenio_records_ui/detail.html', ), recid_previewer=dict( pid_type='recid', route='/records/<pid_value>/preview', view_imp='invenio_previewer.views:preview', record_class='invenio_records_files.api:Record', ), recid_files=dict( pid_type='recid', route='/record/<pid_value>/files/<filename>', view_imp='invenio_records_files.utils.file_download_ui', record_class='invenio_records_files.api:Record', ), ), SERVER_NAME='localhost', APP_THEME=['semantic-ui']) Babel(app_) InvenioAssets(app_) InvenioDB(app_) InvenioRecords(app_) InvenioConfigDefault(app_) InvenioFormatter(app_) InvenioPreviewer(app_)._state InvenioRecordsUI(app_) app_.register_blueprint(create_blueprint_from_app(app_)) InvenioFilesREST(app_) with app_.app_context(): yield app_ shutil.rmtree(instance_path)
view_imp='invenio_records_files.utils:file_download_ui', record_class='invenio_records_files.api:Record', ), recid_previewer=dict( pid_type='recid', route='/records/<pid_value>/preview', view_imp='invenio_previewer.views:preview', record_class='invenio_records_files.api:Record', ))) Babel(app) InvenioI18N(app) InvenioDB(app) InvenioAssets(app) InvenioRecords(app) InvenioFilesREST(app) InvenioPreviewer(app) InvenioRecordsUI(app) app.register_blueprint(create_blueprint_from_app(app)) @app.cli.command() def fixtures(): """Command for working with test data.""" temp_path = os.path.join(os.path.dirname(__file__), 'temp') demo_files_path = os.path.join(os.path.dirname(__file__), 'demo_files') # Create location loc = Location(name='local', uri=temp_path, default=True) db.session.add(loc) db.session.commit()
def app_assets(request): """Flask application fixture with assets.""" initial_dir = os.getcwd() instance_path = tempfile.mkdtemp() os.chdir(instance_path) app = Flask("testapp", static_folder=instance_path, instance_path=instance_path) Babel(app) FlaskCLI(app) InvenioAssets(app) previewer = InvenioPreviewer(app) previewer.register_previewer(zip) previewer.register_previewer(mistune) previewer.register_previewer(pdfjs) previewer.register_previewer(csv_dthreejs) previewer.register_previewer(default) script_info = ScriptInfo(create_app=lambda info: app) script_info._loaded_app = app runner = CliRunner() runner.invoke(npm, obj=script_info) subprocess.call(["npm", "install", instance_path]) runner.invoke(collect, ["-v"], obj=script_info) runner.invoke(assets, ["build"], obj=script_info) def teardown(): shutil.rmtree(instance_path) os.chdir(initial_dir) request.addfinalizer(teardown) return app
def test_entrypoint_previewer(): """Test the entry points.""" app = Flask('testapp') ext = InvenioPreviewer(app) ext.load_entry_point_group('invenio_previewer.previewers') assert len(ext.previewers) == 2
def test_init(): """Test extension initialization.""" app = Flask('testapp') InvenioPreviewer(app) assert 'invenio-previewer' in app.extensions
def previewer_app(app, previewer_deposit): """Init deposit REST API.""" if 'invenio-previewer' not in app.extensions: InvenioPreviewer(app) return app