Coverage for yaptide/routes/estimator_routes.py: 93%
27 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:31 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:31 +0000
1from flask import request
2from flask_restful import Resource
3from marshmallow import Schema, fields
5from yaptide.persistence.db_methods import (fetch_estimator_names_by_job_id)
6from yaptide.persistence.models import (UserModel)
7from yaptide.routes.utils.decorators import requires_auth
8from yaptide.routes.utils.response_templates import yaptide_response
9from yaptide.routes.utils.utils import check_if_job_is_owned_and_exist
12class EstimatorResource(Resource):
13 """Class responsible for retreving estimator names"""
15 class APIParametersSchema(Schema):
16 """Class specifies API parameters"""
18 job_id = fields.String()
20 @staticmethod
21 @requires_auth()
22 def get(user: UserModel):
23 """Method returning estimator names for specific simulation"""
24 schema = EstimatorResource.APIParametersSchema()
25 errors: dict[str, list[str]] = schema.validate(request.args)
26 if errors:
27 return yaptide_response(message="Wrong parameters", code=400, content=errors)
28 param_dict: dict = schema.load(request.args)
30 job_id = param_dict['job_id']
32 is_owned, error_message, res_code = check_if_job_is_owned_and_exist(job_id=job_id, user=user)
33 if not is_owned:
34 return yaptide_response(message=error_message, code=res_code)
36 estimator_names = fetch_estimator_names_by_job_id(job_id=job_id)
38 if not estimator_names:
39 return yaptide_response(message="Estimators not found", code=404)
41 return yaptide_response(message="List of estimator names for specific simulation",
42 code=200,
43 content={"estimator_names": estimator_names})