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 app(request): """Flask application fixture.""" instance_path = tempfile.mkdtemp() app_ = Flask(__name__, instance_path=instance_path) app_.config.update( SQLALCHEMY_DATABASE_URI=os.getenv( 'SQLALCHEMY_DATABASE_URI', 'postgresql+psycopg2://localhost/circulation_test'), OAUTH2SERVER_CLIENT_ID_SALT_LEN=40, OAUTH2SERVER_CLIENT_SECRET_SALT_LEN=60, OAUTH2SERVER_TOKEN_PERSONAL_SALT_LEN=60, SECRET_KEY='changeme', SERVER_NAME='localhost:5000', REPLACE_REFS=False, TESTING=True, CIRCULATION_ACTION_LOAN_URL=( '/hooks/receivers/circulation_loan/events/'), CIRCULATION_ACTION_REQUEST_URL=( '/hooks/receivers/circulation_request/events/'), CIRCULATION_ACTION_RETURN_URL=( '/hooks/receivers/circulation_return/events/'), ) app_.url_map.converters['pid'] = PIDConverter Babel(app_) Menu(app_) Breadcrumbs(app_) InvenioAccounts(app_) InvenioAssets(app_) InvenioDB(app_) InvenioIndexer(app_) InvenioJSONSchemas(app_) InvenioPIDStore(app_) InvenioRecords(app_) InvenioRecordsREST(app_) InvenioWebhooks(app_) InvenioOAuth2Server(app_) InvenioCirculation(app_) InvenioCirculationREST(app_) InvenioSearch(app_) app_.register_blueprint(server_blueprint) app_.register_blueprint(settings_blueprint) app_.register_blueprint(webhooks_blueprint) app_.register_blueprint(circulation_blueprint) with app_.app_context(): yield app_ shutil.rmtree(instance_path)
def app(request): """Flask application fixture.""" app = Flask('testapp') app.config.update( ACCOUNTS_JWT_ENABLE=False, BROKER_TRANSPORT='redis', CELERY_ALWAYS_EAGER=True, CELERY_CACHE_BACKEND='memory', CELERY_EAGER_PROPAGATES_EXCEPTIONS=True, CELERY_RESULT_BACKEND='cache', CELERY_TRACK_STARTED=True, LOGIN_DISABLED=False, OAUTH2_CACHE_TYPE='simple', OAUTHLIB_INSECURE_TRANSPORT=True, SECRET_KEY='test_key', SECURITY_DEPRECATED_PASSWORD_SCHEMES=[], SECURITY_PASSWORD_HASH='plaintext', SECURITY_PASSWORD_SCHEMES=['plaintext'], SQLALCHEMY_TRACK_MODIFICATIONS=True, SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI', 'sqlite:///test.db'), TESTING=True, WTF_CSRF_ENABLED=False, ) 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) InvenioOAuth2Server(app) InvenioOAuth2ServerREST(app) app.register_blueprint(server_blueprint) app.register_blueprint(settings_blueprint) InvenioWebhooks(app) app.register_blueprint(blueprint) with app.app_context(): if not database_exists(str(db.engine.url)): create_database(str(db.engine.url)) db.create_all() def teardown(): with app.app_context(): drop_database(str(db.engine.url)) request.addfinalizer(teardown) return app
def test_init(): """Test extension initialization.""" app = Flask('testapp') ext = InvenioWebhooks(app) assert 'invenio-webhooks' in app.extensions app = Flask('testapp') ext = InvenioWebhooks() assert 'invenio-webhooks' not in app.extensions ext.init_app(app) assert 'invenio-webhooks' in app.extensions
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307, USA. # # In applying this license, CERN does not # waive the privileges and immunities granted to it by virtue of its status # as an Intergovernmental Organization or submit itself to any jurisdiction. """Minimal Flask application example for development. Run example development server: .. code-block:: console $ cd examples $ python app.py """ from __future__ import absolute_import, print_function from flask import Flask from flask_babelex import Babel from invenio_webhooks import InvenioWebhooks # Create Flask application app = Flask(__name__) Babel(app) InvenioWebhooks(app) if __name__ == "__main__": app.run()
def webhooks(app): """Init webhooks API.""" if 'invenio-webhooks' not in app.extensions: InvenioWebhooks(app) 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)