def test_run_report(bson_library, environ): flask_app = create_app() with flask_app.app_context() as c: serialiser = get_serializer() overrides = {"n_points": 5} report_name = "fake/report" report_title = "my report title" mailto = "*****@*****.**" job_id = run_report(report_name, report_title, mailto, overrides, generate_pdf_output=False, prepare_only=True) _check_report_output( job_id, serialiser, overrides=overrides, report_name=report_name, report_title=report_title, mailto=mailto, ) assert job_id == serialiser.get_latest_job_id_for_name_and_params( report_name, overrides) assert job_id == serialiser.get_latest_job_id_for_name_and_params( report_name, None) assert job_id == serialiser.get_latest_successful_job_id_for_name_and_params( report_name, overrides) assert job_id == serialiser.get_latest_successful_job_id_for_name_and_params( report_name, None)
def _all_templates(): web_config = WebappConfig(PY_TEMPLATE_BASE_DIR="") flask_app = create_app() flask_app = setup_app(flask_app, web_config) with flask_app.app_context(): templates = list( _gen_all_templates( get_all_possible_templates(warn_on_local=False))) return templates
def test_run_report_and_rerun(bson_library, mongo_host, workspace, test_db_name, test_lib_name): _setup_workspace(workspace) for k, v in _environ(mongo_host, workspace, test_db_name, test_lib_name).items(): os.environ[k] = v try: flask_app = create_app() with flask_app.app_context() as c: serialiser = get_serializer() overrides = {"n_points": 5} report_name = "fake/report" report_title = "my report title" mailto = "*****@*****.**" job_id = run_report(report_name, report_title, mailto, overrides, generate_pdf_output=False, prepare_only=True) _check_report_output( job_id, serialiser, overrides=overrides, report_name=report_name, report_title=report_title, mailto=mailto, generate_pdf_output=False, ) new_job_id = _rerun_report(job_id, prepare_only=True) _check_report_output( new_job_id, serialiser, overrides=overrides, report_name=report_name, report_title="Rerun of " + report_title, mailto=mailto, generate_pdf_output=False, ) assert new_job_id == serialiser.get_latest_job_id_for_name_and_params( report_name, overrides) assert not {job_id, new_job_id} - set( serialiser.get_all_job_ids_for_name_and_params( report_name, overrides)) assert new_job_id == serialiser.get_latest_successful_job_id_for_name_and_params( report_name, overrides) assert job_id != serialiser.get_latest_successful_job_id_for_name_and_params( report_name, overrides) finally: for k, __ in _environ(mongo_host, workspace, test_db_name, test_lib_name).items(): del os.environ[k]
def setup_test(template_dir): try: with TemporaryDirectory() as tmpdir: app = create_app() web_config = WebappConfig() web_config.PY_TEMPLATE_BASE_DIR = template_dir web_config.CACHE_DIR = tmpdir app = setup_app(app, web_config) with app.app_context(): yield finally: filesystem._cleanup_dirs(web_config)
def flask_app(webapp_config): flask_app = create_app() flask_app = setup_app(flask_app, webapp_config) return flask_app