def test_fetch_application_data__success__using_id( respx_mock, dummy_context, dummy_application_data, dummy_domain, ): app_data = dummy_application_data[0] app_id = app_data["id"] fetch_route = respx_mock.get(f"{dummy_domain}/applications/{app_id}") fetch_route.mock(return_value=httpx.Response( httpx.codes.OK, json=app_data, ), ) result = fetch_application_data(dummy_context, id=app_id) assert fetch_route.called assert result == ApplicationResponse(**app_data)
def get_one( ctx: typer.Context, id: Optional[int] = typer.Option( None, help=f"The specific id of the application. {ID_NOTE}", ), identifier: Optional[str] = typer.Option( None, help=f"The human-friendly identifier of the application. {IDENTIFIER_NOTE}", ), ): """ Get a single application by id or identifier """ jg_ctx: JobbergateContext = ctx.obj result = fetch_application_data(jg_ctx, id=id, identifier=identifier) render_single_result( jg_ctx, result, hidden_fields=HIDDEN_FIELDS, title="Application", )
def test_fetch_application_data__fails_with_neither_id_or_identifier( dummy_context): with pytest.raises(Abort, match="You must supply either"): fetch_application_data(dummy_context)
def test_fetch_application_data__fails_with_both_id_or_identifier( dummy_context): with pytest.raises(Abort, match="You may not supply both"): fetch_application_data(dummy_context, id=1, identifier="one")
def create( ctx: typer.Context, name: str = typer.Option( ..., help="The name of the job script to create.", ), application_id: Optional[int] = typer.Option( None, help="The id of the application from which to create the job script.", ), application_identifier: Optional[str] = typer.Option( None, help= "The identifier of the application from which to create the job script.", ), sbatch_params: Optional[List[str]] = typer.Option( None, help="Optional parameter to submit raw sbatch parameters.", ), param_file: Optional[pathlib.Path] = typer.Option( None, help=dedent(""" Supply a yaml file that contains the parameters for populating templates. If this is not supplied, the question asking in the application is triggered. """), ), fast: bool = typer.Option( False, help="Use default answers (when available) instead of asking the user.", ), submit: Optional[bool] = typer.Option( None, help="Do not ask the user if they want to submit a job.", ), ): """ Create a new job script. """ jg_ctx: JobbergateContext = ctx.obj # Make static type checkers happy assert jg_ctx.client is not None app_data = fetch_application_data(jg_ctx, id=application_id, identifier=application_identifier) (app_config, app_module) = load_application_data(app_data) request_data = JobScriptCreateRequestData( application_id=app_data.id, job_script_name=name, sbatch_params=sbatch_params, param_dict=app_config, ) supplied_params = validate_parameter_file( param_file) if param_file else dict() execute_application(app_module, app_config, supplied_params, fast_mode=fast) if app_config.jobbergate_config.job_script_name is not None: request_data.job_script_name = app_config.jobbergate_config.job_script_name job_script_result = cast( JobScriptResponse, make_request( jg_ctx.client, "/job-scripts", "POST", expected_status=201, abort_message="Couldn't create job script", support=True, request_model=request_data, response_model_cls=JobScriptResponse, ), ) render_single_result( jg_ctx, job_script_result, hidden_fields=HIDDEN_FIELDS, title="Created Job Script", ) # `submit` will be `None` --submit/--no-submit flag was not set if submit is None: # If not running in "fast" mode, ask the user what to do. if not fast: submit = typer.confirm( "Would you like to submit this job immediately?") # Otherwise, assume that the job script should be submitted immediately else: submit = True if not submit: return try: job_submission_result = create_job_submission( jg_ctx, job_script_result.id, job_script_result.job_script_name) except Exception as err: raise Abort( "Failed to immediately submit the job after job script creation.", subject="Automatic job submission failed", support=True, log_message= f"There was an issue submitting the job immediately job_script_id={job_script_result.id}.", original_error=err, ) render_single_result( jg_ctx, job_submission_result, hidden_fields=JOB_SUBMISSION_HIDDEN_FIELDS, title="Created Job Submission (Fast Mode)", )