def test_connect_autocommit(self, mock_sessionmaker, mock_create_engine): connect() # Autocommit should always be set to True, to avoid problems with auto-creation of transactions that block # other processes. mock_sessionmaker.assert_called_with( autocommit=True, autoflush=False, bind=mock_create_engine.return_value, query_cls=AuthorizedQuery)
def before_each_storage_test(monkeypatch): import sqlalchemy importlib.reload(sqlalchemy) import sqlalchemy.ext.automap importlib.reload(sqlalchemy.ext.automap) import sqlalchemy.orm importlib.reload(sqlalchemy.orm) import gobapi.config importlib.reload(gobapi.config) import gobcore.model importlib.reload(gobapi.config) monkeypatch.setattr(sqlalchemy, 'create_engine', mock_create_engine) monkeypatch.setattr(sqlalchemy, 'Table', MockTable) monkeypatch.setattr(sqlalchemy.ext.automap, 'automap_base', mock_automap_base) monkeypatch.setattr(sqlalchemy.orm, 'scoped_session', mock_scoped_session) monkeypatch.setattr(gobapi.session, 'get_session', mock_scoped_session) monkeypatch.setattr(gobapi.config, 'current_api_base_path', lambda: '/gob') monkeypatch.setattr(gobcore.model, 'GOBModel', mock_get_gobmodel) monkeypatch.setattr(gobcore.model.metadata, 'PUBLIC_META_FIELDS', mock_PUBLIC_META_FIELDS) monkeypatch.setattr(gobcore.model.relations, 'get_relation_name', lambda m, a, o, r: 'relation_name') import gobapi.storage importlib.reload(gobapi.storage) monkeypatch.setattr(gobapi.storage, 'models', mock_models) monkeypatch.setattr(gobapi.storage, '_apply_filters', lambda e, f, t: e) monkeypatch.setattr(gobapi.storage, '_format_reference', lambda ref, cat, col, spec: {'reference': ref}) monkeypatch.setattr(gobapi.storage, '_add_relations', lambda q, cat, col: q) from gobapi.storage import connect connect()
def get_app(): """Returns a Flask application object The rules are maintained in the ROUTES variable (Note: By default a rule just listens for GET) CORS is used to allow CORS for all domains on all routes :return: a Flask application object """ connect() graphql = GraphQLView.as_view( 'graphql', schema=schema, graphiql=True # for having the GraphiQL interface ) graphql_streaming = GraphQLStreamingApi() app = Flask(__name__) CORS(app) # Exclude all non-secure urls fot the audit log and provide the callable to get the user from the request app.config['AUDIT_LOG'] = { 'EXEMPT_URLS': [fr'^(?!{API_SECURE_BASE_PATH}).+'], 'LOG_HANDLER_CALLABLE_PATH': 'gobapi.util.audit_log.get_log_handler', 'USER_FROM_REQUEST_CALLABLE_PATH': 'gobapi.util.audit_log.get_user_from_request', } # Add the AuditLogMiddleware AuditLogMiddleware(app) # Health check route app.route(rule='/status/health/')(_health) # Application routes PUBLIC = [API_BASE_PATH, API_SECURE_BASE_PATH] # SECURE = [API_SECURE_BASE_PATH] ROUTES = [ (PUBLIC, '/', _catalogs, ['GET']), (PUBLIC, '/<catalog_name>/', _catalog, ['GET']), (PUBLIC, '/<catalog_name>/<collection_name>/', _collection, ['GET']), (PUBLIC, '/<catalog_name>/<collection_name>/<entity_id>/', _entity, ['GET']), (PUBLIC, '/<catalog_name>/<collection_name>/<entity_id>/<reference_path>/', _reference_collection, ['GET']), (PUBLIC, '/alltests/', _clear_tests, ['DELETE']), (PUBLIC, '/toestanden/', _states, ['GET']), (PUBLIC, '/graphql/', graphql, ['GET', 'POST']), (PUBLIC, '/graphql/streaming/', graphql_streaming.entrypoint, ['POST' ]), (PUBLIC, '/dump/<catalog_name>/<collection_name>/', _dump, ['GET', 'POST']), (PUBLIC, '/worker/<worker_id>', worker_result, ['GET']), (PUBLIC, '/worker/end/<worker_id>', worker_end, ['DELETE']), (PUBLIC, '/worker/status/<worker_id>', worker_status, ['GET']), (PUBLIC, '/fat_file/<gbs>', fat_file, ['GET']), (PUBLIC, '/info/<info_type>/', get_db_info, ['GET']) ] for paths, rule, view_func, methods in ROUTES: _add_route(app, paths, rule, view_func, methods) app.teardown_appcontext(shutdown_session) return app