def user_set(app, user): print 'ready handler' def handler(sender, **kwargs): g.user = user print 'run handler' with appcontext_pushed.connected_to(handler, app): yield
def set_wp10_db(): def handler(sender, **kwargs): g.wp10db = self._connect_wp_one_db() with appcontext_pushed.connected_to(handler, app): yield
def content_from_fixtures(self, app, fixture_directory): """ Replace the application content with content from fixtures. """ def handler(sender, **kwargs): app = sender try: app.articles = self.articles except AttributeError: try: app.articles = list(article.loader.find( join(fixture_directory, 'articles'))) except OSError: app.articles = [] try: app.bookmarks = self.bookmarks except AttributeError: try: app.bookmarks = list(bookmark.loader.find( join(fixture_directory, 'bookmarks'))) except OSError: app.bookmarks = [] try: app.search_index = self.search_index except AttributeError: app.search_index = SearchIndex(bookmarks=app.bookmarks) with appcontext_pushed.connected_to(handler, app): yield
def client(): device_wizard_config = { "device_idm": { "server": "http://localhost:8080/auth/", "username": "******", "password": "******", "realm_name": "n5geh_devices" }, "fiware": { "orion": "http://localhost:1026", "iotagent": "http://localhost:4041", "quantumleap": "http://localhost:8668" }, "datamodel": { "ngsi2": "datamodel/NGSI2", "ngsi-ld": "datamodel/NGSI-LD", "classes": "datamodel/classes" }, "idm": { "logout_link": "http://localhost:8080/auth/realms/n5geh/protocol/openid-connect/logout?referrer=flask-app&redirect_uri=http%3A%2F%2Flocalhost%3A8090%2Fdashboard" } } app = main.create_app(device_wizard_config, 'client_secrets.json') app.testing = True app.config['TESTING'] = True app.before_request_funcs[None] = [] def handler(sender, **kwargs): g.oidc_id_token = 'foobar' client = app.test_client() with appcontext_pushed.connected_to(handler, app): yield client
def database_set(app): def handler(sender, **kwargs): from orvsd_central.database import init_db g.db_session = create_db_session() init_db() with appcontext_pushed.connected_to(handler, app): yield
def user_set(APP, user, keep_get_user=False): """ Set the provided user as fas_user in the provided application.""" # Hack used to remove the before_request function set by # flask.ext.fas_openid.FAS which otherwise kills our effort to set a # flask.g.fas_user. from flask import appcontext_pushed, g keep = [] for meth in APP.before_request_funcs[None]: if "flask_fas_openid.FAS" in str(meth): continue keep.append(meth) APP.before_request_funcs[None] = keep def handler(sender, **kwargs): g.fas_user = user g.fas_session_id = b"123" g.authenticated = True old_get_user = pagure.flask_app._get_user if not keep_get_user: pagure.flask_app._get_user = mock.MagicMock( return_value=pagure.lib.model.User() ) with appcontext_pushed.connected_to(handler, APP): yield pagure.flask_app._get_user = old_get_user
def db_ctx(app, status=None, dpid=None): def handler(sender, **kwargs): g.db = mock.MagicMock() if status is None: g.db.re.state.find_one.return_value = None # Completed elif status == 200: g.db.re.state.find_one.return_value = { "created": YESTERDAY, "failed": False, "ended": UTCNOW } # In progress elif status == 202: g.db.re.state.find_one.return_value = { "created": YESTERDAY, "failed": None, "ended": None, "active_step": "noop:UnitTest" } # deploy failed elif status == 400: g.db.re.state.find_one.return_value = { "created": YESTERDAY, "failed": True, "ended": UTCNOW, "failed_step": "noop:Fail" } with appcontext_pushed.connected_to(handler, app): yield
def user_set(app, user): """User set.""" def handler(sender, **kwargs): g.user = user with appcontext_pushed.connected_to(handler, app): yield
def db_ctx(app): def handler(sender, **kwargs): g.db = mock.MagicMock() g.db.re.playbooks.distinct.return_value = ['group'] with appcontext_pushed.connected_to(handler, app): yield
def set_current_user(): test_user = add_to_db(User(), first_name="Test", last_name="User", email="*****@*****.**") def handler(sender, **kwargs): g.user = test_user # User.get(user_id=1) with appcontext_pushed.connected_to(handler, app): with app.app_context(): yield
def set_redis(): def handler(sender, **kwargs): g.redis = self.redis with appcontext_pushed.connected_to(handler, app): yield
def user_set(APP, user, keep_get_user=False): """ Set the provided user as fas_user in the provided application.""" # Hack used to remove the before_request function set by # flask.ext.fas_openid.FAS which otherwise kills our effort to set a # flask.g.fas_user. from flask import appcontext_pushed, g keep = [] for meth in APP.before_request_funcs[None]: if 'flask_fas_openid.FAS' in str(meth): continue keep.append(meth) APP.before_request_funcs[None] = keep def handler(sender, **kwargs): g.fas_user = user g.fas_session_id = b'123' g.authenticated = True old_get_user = pagure.flask_app._get_user if not keep_get_user: pagure.flask_app._get_user = mock.MagicMock( return_value=pagure.lib.model.User()) with appcontext_pushed.connected_to(handler, APP): yield pagure.flask_app._get_user = old_get_user
def set_user(app, user): def handler(sender, **kwargs): g.user = user log.debug('Setting user %s', g.user) with appcontext_pushed.connected_to(handler, app): yield
def uaac_set(app, uaac=Mock()): """Shim in a mock object to flask.g""" def handler(sender, **kwargs): flask.g.uaac = uaac with appcontext_pushed.connected_to(handler, app): yield
def set_user(app: Flask, user: User): def handler(sender: Flask): del sender g.user = user log.debug("Setting user %s", g.user) with appcontext_pushed.connected_to(handler, app): yield
def identity(app): identity = Identity("test") def handler(sender): g.identity = identity with appcontext_pushed.connected_to(handler, app): yield identity
def user_set(app, fake_user_type, user_name): """ set the test user doing the request """ def handler(sender, **kwargs): g.user = fake_user_type.get_from_token(user_name, valid_until=None) with appcontext_pushed.connected_to(handler, app): yield
def user_set(app, user_name): """ add user """ def handler(sender, **kwargs): g.user = FakeUser.get_from_token(user_name) with appcontext_pushed.connected_to(handler, app): yield
def objects_set(app, data_source, db, model): """ This allows to set (simulate) session objects with arbitrary ones """ def handler(sender, **kwargs): g.data_source = data_source g.db = db g.model = model with appcontext_pushed.connected_to(handler, app): yield
def set_token(application: Flask, token: bool) -> Iterator: """Set whether API needs to implement token based authentication.""" if not isinstance(token, bool): raise TypeError("Token flag must be of type <bool>") def handler(sender: Flask, **kwargs: Any) -> None: g.token_ = token with appcontext_pushed.connected_to(handler, application): yield
def wrapper(*args, **kwargs): user = User(email="*****@*****.**", identifier="facebook.com/adele") radlibs.Client().session().add(user) def handler(sender, **kwargs): g.user = user with appcontext_pushed.connected_to(handler, app): args = args + (user,) fn(*args, **kwargs)
def authenticate(self): ''' Inject fake security tokens into the app context for testing. ''' def handler(sender, **kwargs): g.tokens = self.tokens with appcontext_pushed.connected_to(handler, api.app): yield
def set_hydrus_server_url(application, server_url): """Set the server URL for the app. Must be of type <str>.""" if not isinstance(server_url, str): raise TypeError("The server_url is not of type <str>") def handler(sender, **kwargs): g.hydrus_server_url = server_url with appcontext_pushed.connected_to(handler, application): yield
def set_api_name(application, api_name): """Set the server name or EntryPoint for the app. Must be of type <str>.""" if not isinstance(api_name, str): raise TypeError("The api_name is not of type <str>") def handler(sender, **kwargs): g.api_name = api_name with appcontext_pushed.connected_to(handler, application): yield
def set_authentication(application, authentication): """Set the wether API needs to be authenticated or not.""" if not isinstance(authentication, bool): raise TypeError("Authentication flag must be of type <bool>") def handler(sender, **kwargs): g.authentication_ = authentication with appcontext_pushed.connected_to(handler, application): yield
def set_session(application, DB_SESSION): """Set the database session for the app. Must be of type <hydrus.hydraspec.doc_writer.HydraDoc>.""" if not isinstance(DB_SESSION, Session): raise TypeError( "The API Doc is not of type <sqlalchemy.orm.session.Session>") def handler(sender, **kwargs): g.dbsession = DB_SESSION with appcontext_pushed.connected_to(handler, application): yield
def set_doc(application, APIDOC): """Set the API Documentation for the app. Must be of type <hydrus.hydraspec.doc_writer.HydraDoc>.""" if not isinstance(APIDOC, HydraDoc): raise TypeError( "The API Doc is not of type <hydrus.hydraspec.doc_writer.HydraDoc>" ) def handler(sender, **kwargs): g.doc = APIDOC with appcontext_pushed.connected_to(handler, application): yield
def user_set(app, user): """ user_set @param app: @param user: @return: """ def handler(sender, **kwargs): g.user = user with appcontext_pushed.connected_to(handler, app): yield
def db_ctx(app): def handler(sender, **kwargs): g.db = mock.MagicMock() g.db.re.playbooks.insert.return_value = '53614ccf1370129d6f29c7dd' g.db.re.playbooks.save.return_value = '53614ccf1370129d6f29c7dd' g.db.re.playbooks.find_one.return_value = { "_id": ObjectId('53614ccf1370129d6f29c7dd'), "data": "test"} g.db.re.playbooks.remove.return_value = True with appcontext_pushed.connected_to(handler, app): yield
def set_global(app, plugin_id=None, request_id=None): """ Set flask.g values """ # pylint: disable=unused-argument def handler(sender, **kwargs): g.plugin_id = plugin_id g.request_id = request_id with appcontext_pushed.connected_to(handler, app): yield
def content_empty(self, app): """ Replace the application content with all empty values. """ def handler(sender, **kwargs): app = sender app.articles = None app.bookmarks = None app.search_index = None with appcontext_pushed.connected_to(handler, app): yield
def user_set(APP, user): """ Set the provided user as fas_user in the provided application.""" # Hack used to remove the before_request function set by # flask.ext.fas_openid.FAS which otherwise kills our effort to set a # flask.g.fas_user. APP.before_request_funcs[None] = [] def handler(sender, **kwargs): g.fas_user = user with appcontext_pushed.connected_to(handler, APP): yield
def set_hydrus_server_url(application: Flask, server_url: str) -> Iterator: """ Set the server URL for the app (before it is run in main.py). :param application: Flask app object <flask.app.Flask> :param server_url : Server URL <str> """ if not isinstance(server_url, str): raise TypeError("The server_url is not of type <str>") def handler(sender: Flask, **kwargs: Any) -> None: g.hydrus_server_url = server_url with appcontext_pushed.connected_to(handler, application): yield
def set_api_name(application: Flask, api_name: str) -> Iterator: """ Set the server name or EntryPoint for the app (before it is run in main.py). :param application: Flask app object <flask.app.Flask> :param api_name : API/Server name or EntryPoint <str> """ if not isinstance(api_name, str): raise TypeError("The api_name is not of type <str>") def handler(sender: Flask, **kwargs: Any) -> None: g.api_name = api_name with appcontext_pushed.connected_to(handler, application): yield
def set_session(application: Flask, DB_SESSION: scoped_session) -> Iterator: """ Set the Database Session for the app before it is run in main.py. :param application: Flask app object <flask.app.Flask> :param DB_SESSION: SQLalchemy Session object <sqlalchemy.orm.session.Session> """ if not isinstance(DB_SESSION, scoped_session): raise TypeError( "The API Doc is not of type or <sqlalchemy.orm.scoping.scoped_session>") def handler(sender: Flask, **kwargs: Any) -> None: g.dbsession = DB_SESSION with appcontext_pushed.connected_to(handler, application): yield
def set_authentication(application: Flask, authentication: bool) -> Iterator: """ Set the whether API needs to be authenticated or not (before it is run in main.py). :param application: Flask app object <flask.app.Flask> :param authentication : Bool. API Auth needed or not <bool> """ if not isinstance(authentication, bool): raise TypeError("Authentication flag must be of type <bool>") def handler(sender: Flask, **kwargs: Any) -> None: g.authentication_ = authentication with appcontext_pushed.connected_to(handler, application): yield
def set_doc(application: Flask, APIDOC: HydraDoc) -> Iterator: """ Set the API Documentation for the app (before it is run in main.py). :param application: Flask app object <flask.app.Flask> :param APIDOC : Hydra Documentation object <hydrus.hydraspec.doc_writer.HydraDoc> """ if not isinstance(APIDOC, HydraDoc): raise TypeError( "The API Doc is not of type <hydrus.hydraspec.doc_writer.HydraDoc>") def handler(sender: Flask, **kwargs: Any) -> None: g.doc = APIDOC with appcontext_pushed.connected_to(handler, application): yield
def user_set(APP, user): """ Set the provided user as fas_user in the provided application.""" # Hack used to remove the before_request function set by # flask.ext.fas_openid.FAS which otherwise kills our effort to set a # flask.g.fas_user. from flask import appcontext_pushed, g keep = [] for meth in APP.before_request_funcs[None]: if 'flask_fas_openid.FAS' in str(meth): continue keep.append(meth) APP.before_request_funcs[None] = keep def handler(sender, **kwargs): g.fas_user = user g.fas_session_id = b'123' with appcontext_pushed.connected_to(handler, APP): yield
def set_pagination(application: Flask, paginate: bool) -> Iterator: """ Enable or disable pagination. :param application: Flask app object <flask.app.Flask> :param paginate : Pagination enabled or not <bool> Raises: TypeError: If `paginate` is not a bool. """ if not isinstance(paginate, bool): raise TypeError("The CLI argument 'pagination' is not of type <bool>") def handler(sender: Flask, **kwargs: Any) -> None: g.paginate = paginate with appcontext_pushed.connected_to(handler, application): yield
def user_set(app, user): def handler(sender, **kwargs): g.user = user with appcontext_pushed.connected_to(handler, app): yield
def lang_set(app, lang): def handler(sender, **kwargs): g.lang_code = lang with appcontext_pushed.connected_to(handler, app): yield
def centralauth_service_set(app, centralauth_service): def handler(sender, **kwargs): g.centralauth_service = centralauth_service with appcontext_pushed.connected_to(handler, app): yield
def cohort_service_set(app, cohort_service): def handler(sender, **kwargs): g.cohort_service = cohort_service with appcontext_pushed.connected_to(handler, app): yield
def user_set(application, user): def handler(sender, **kwargs): _app_ctx_stack.top.current_user = user with appcontext_pushed.connected_to(handler, application): yield
def current_party_set(app, party): def handler(sender, **kwargs): g.party = party with appcontext_pushed.connected_to(handler, app): yield
def file_manager_set(app, file_manager): def handler(sender, **kwargs): g.file_manager = file_manager with appcontext_pushed.connected_to(handler, app): yield