def test_loads_config_from_test_config_instead_of_file_if_test_config_specified( self, TEST_CONFIG_DICT, TEST_CONFIG_FILE): """If a `test_config` dict is passed, we load it, instead of loading from a file.""" app = construct_flask_app(test_config=TEST_CONFIG_DICT, config_file=TEST_CONFIG_FILE) for key, value in TEST_CONFIG_DICT.items(): assert app.config.get(key) == value
def transaction_service_app(rpc_client_id): app = construct_flask_app() app.config["TESTING"] = True app.config["rpc-client"] = RPCRegistry() app.config["rpc-client"].dict = { rpc_client_id: mock.Mock(**{"send_transaction.return_value": b"my_tx_hash"}) } return app
def run(ctx, mailgun_api_key, auth, password, keystore_file, scenario_file, notify_tasks, enable_ui): scenario_file = Path(scenario_file.name).absolute() data_path = ctx.obj["data_path"] chain_rpc_urls = ctx.obj["chain_rpc_urls"] log_file_name = construct_log_file_name("run", data_path, scenario_file) configure_logging_for_subcommand(log_file_name) account = load_account_obj(keystore_file, password) notify_tasks_callable = None if notify_tasks is TaskNotifyType.ROCKETCHAT: if "RC_WEBHOOK_URL" not in os.environ: click.secho( "'--notify-tasks rocket-chat' requires env variable 'RC_WEBHOOK_URL' to be set.", fg="red", ) notify_tasks_callable = post_task_state_to_rc log_buffer = None # If the output is a terminal, beautify our output. if enable_ui: enable_gui_formatting() # Dynamically import valid Task classes from sceanrio_player.tasks package. collect_tasks(tasks) # Start our Services service = construct_flask_app() service_process = ServiceProcess(service) service_process.start() # Run the scenario using the configurations passed. runner = ScenarioRunner(account, chain_rpc_urls, auth, data_path, scenario_file, notify_tasks_callable) ui = None ui_greenlet = None if enable_ui: ui = ScenarioUI(runner, log_buffer, log_file_name) ui_greenlet = ui.run() success = False try: try: runner.run_scenario() except ScenarioAssertionError as ex: log.error("Run finished", result="assertion errors") send_notification_mail( runner.notification_email, f"Assertion mismatch in {scenario_file.name}", str(ex), mailgun_api_key, ) except ScenarioError: log.exception("Run finished", result="scenario error") send_notification_mail( runner.notification_email, f"Invalid scenario {scenario_file.name}", traceback.format_exc(), mailgun_api_key, ) else: success = True log.info("Run finished", result="success") send_notification_mail( runner.notification_email, f"Scenario successful {scenario_file.name}", "Success", mailgun_api_key, ) except Exception: log.exception("Exception while running scenario") send_notification_mail( runner.notification_email, f"Error running scenario {scenario_file.name}", traceback.format_exc(), mailgun_api_key, ) finally: try: if enable_ui and ui: ui.set_success(success) log.warning("Press q to exit") while not ui_greenlet.dead: gevent.sleep(1) service_process.start() except ServiceProcessException: service_process.kill() finally: if runner.is_managed: runner.node_controller.stop() if ui_greenlet is not None and not ui_greenlet.dead: ui_greenlet.kill(ExitMainLoop) ui_greenlet.join()
def app(): app = construct_flask_app(test_config={"TESTING": True}) with app.app_context(): yield
def run(self): """Run the Service.""" app = construct_flask_app() waitress.serve(app, host=self.host, port=self.port)
def client(): app = construct_flask_app(metrics_blueprint) app.config['TESTING'] = True client = app.test_client() return client
def test_loads_config_from_file_if_no_test_config_specified( self, TEST_CONFIG_FILE): """The configuration is loaded from a default file if no `test_config` is passed.""" app = construct_flask_app(config_file=TEST_CONFIG_FILE) assert app.config.get('TESTING') is False assert app.config.get('ICE_CREAM_FLAVOR') == 'CHOCOLATE'
def test_constructor_makes_call_to_blueprint_registration_hook( self, mock_register_blueprints, plugins_enabled): """There is exactly one call for each available Blueprint.""" construct_flask_app(enable_plugins=plugins_enabled) assert mock_register_blueprints.called is plugins_enabled
def test_test_config_overwrites_app_configs(self): config = {"DATABASE": 'custom_db', 'SECRET_KEY': 'banana pie'} app = construct_flask_app(test_config=config) for key, value in config.items(): assert app.config.get(key) == value
def test_constructor_always_creates_expected_config_settings_regardless_of_test_config( self, values, test_config): constructed_app = construct_flask_app(test_config=test_config) for key, value in values.items(): assert constructed_app.config.get(key) == value
def client(): app = construct_flask_app(admin_blueprint) app.config["TESTING"] = True client = app.test_client() return client