def test_init(): """Test extension initialization.""" app = Flask('testapp') ext = InvenioFormatter(app) assert 'invenio-formatter' in app.extensions app = Flask('testapp') ext = InvenioFormatter() assert 'invenio-formatter' not in app.extensions ext.init_app(app) assert 'invenio-formatter' in app.extensions
def test_badge_enable_disable(): """Test if badge is disabled if CairoSVG is not installed.""" app = Flask('testapp') InvenioFormatter(app) assert app.config['FORMATTER_BADGES_ENABLE'] is True assert 'invenio_formatter_badges' in app.blueprints with patch('invenio_formatter.ext.get_distribution') as f: f.side_effect = DistributionNotFound app = Flask('testapp') InvenioFormatter(app) assert app.config['FORMATTER_BADGES_ENABLE'] is False assert 'invenio_formatter_badges' not in app.blueprints
def app(): """Flask application fixture.""" app = Flask('testapp') app.config.update( TESTING=True ) InvenioFormatter(app) return app
def app(request): """Flask application fixture.""" app_ = Flask('testapp') app_.config.update( TESTING=True, CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND="memory", CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND="cache", SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI', 'sqlite://'), SQLALCHEMY_TRACK_MODIFICATIONS=False, SECRET_KEY='mysecret', SUPPORT_EMAIL='*****@*****.**', WTF_CSRF_ENABLED=False, SERVER_NAME='test.it', RECORDS_UI_ENDPOINTS=dict( recid=dict( pid_type='recid', route='/records/<pid_value>', template='invenio_records_ui/detail.html', ), recid_access_request=dict( pid_type='recid', route='/records/<pid_value>/accessrequest', template='zenodo_accessrequests/access_request.html', view_imp='zenodo_accessrequests.views.requests.access_request', methods=['GET', 'POST'], ), recid_access_request_email_confirm=dict( pid_type='recid', route='/records/<pid_value>/accessrequest/<token>/confirm', # template='invenio_records_ui/detail.html', view_imp='zenodo_accessrequests.views.requests.confirm', ), ), ) InvenioFormatter(app_) Babel(app_) InvenioDB(app_) InvenioAccounts(app_) InvenioRecords(app_) FlaskMenu(app_) Mail(app_) InvenioRecordsUI(app_) InvenioAccess(app_) ZenodoAccessRequests(app_) InvenioPIDStore(app_) app_.register_blueprint(request_blueprint) app_.register_blueprint(settings_blueprint) app_.register_blueprint(blueprint_user) app_.register_blueprint(create_blueprint_from_app(app_)) with app_.app_context(): yield app_
def app(): """Flask application fixture.""" app = Flask('testapp') app.config.update( TESTING=True, ALLOWED_HTML_TAGS=[ 'a', ], ALLOWED_HTML_ATTRS={ 'a': ['href'], }, ) InvenioFormatter(app) return app
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)
def test_views_badge_svg_mapping(): """Test context processor badge generating a SVG.""" """Flask application fixture.""" app = Flask('testapp') app.config.update( TESTING=True, FORMATTER_BADGES_ALLOWED_TITLES=['test', 'TEST'], FORMATTER_BADGES_TITLE_MAPPING={'test': 'TEST'}, ) InvenioFormatter(app) with app.app_context(): with app.test_client() as client: response = client.get('/badge/test/value.svg') response_data = response.get_data(as_text=True).replace( '\n', '').replace(' ', '') assert 'fill-opacity=".3">TEST</text>' in response_data response = client.get('/badge/TEST/value.svg') response_data = response.get_data(as_text=True).replace( '\n', '').replace(' ', '') assert 'fill-opacity=".3">TEST</text>' in response_data
""" from __future__ import absolute_import, print_function import datetime from os.path import dirname, join import jinja2 from flask import Flask, render_template from invenio_formatter import InvenioFormatter # Create Flask application app = Flask(__name__) InvenioFormatter(app) # Set jinja loader to first grab templates from the app's folder. app.jinja_loader = jinja2.ChoiceLoader([ jinja2.FileSystemLoader(join(dirname(__file__), "templates")), app.jinja_loader ]) @app.route('/', methods=['GET']) def index(): """Example format date.""" mydate = datetime.date.today() return render_template('index.html', mydate=mydate)
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)