Skip to content

Commit

Permalink
#372 - Update EasyClient.import_jobs to properly handle the beer-gard…
Browse files Browse the repository at this point in the history
…en api response (#373)
  • Loading branch information
scott-taubman authored Nov 17, 2021
1 parent 7154e28 commit f2bddad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
4 changes: 1 addition & 3 deletions brewtils/rest/easy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,7 @@ def export_jobs(self, job_id_list=None):

return self.client.post_export_jobs(payload) # noqa # wrapper changes type

@wrap_response(
parse_method="parse_job_ids", parse_many=True, default_exc=FetchError
)
@wrap_response(parse_method="parse_job_ids")
def import_jobs(self, job_list):
# type: (List[Job]) -> List[str]
"""Import job definitions from a list of Jobs.
Expand Down
26 changes: 9 additions & 17 deletions brewtils/schema_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,33 +301,25 @@ def parse_job(cls, job, from_string=False, **kwargs):
return cls.parse(job, brewtils.models.Job, from_string=from_string, **kwargs)

@classmethod
def parse_job_ids(cls, job_id_list, from_string=False, **kwargs):
"""Convert raw JSON string or list of strings to a list of job ids.
def parse_job_ids(cls, job_id_json, from_string=False, **kwargs):
"""Convert raw JSON string containing a list of strings to a list of job ids.
Passes a list of strings through unaltered if from_string is False.
Args:
job_id_list: Raw input
job_id_json: Raw input
from_string: True if input is a JSON string, False otherwise
**kwargs: Additional parameters to be passed to the Schema (e.g. many=True)
Returns:
A list of job ids.
A dictionary containing a list of job ids
"""
# this is needed by easy_client
#
# some functionality duplicated from the parse method because model not used
if job_id_list is None: # pragma: no cover
raise TypeError("job_id_list can not be None")
if not bool(from_string):
if isinstance(job_id_list, list):
if len(job_id_list) > 0 and not all(
map(lambda x: isinstance(x, str), job_id_list)
): # pragma: no cover
raise TypeError("Not a list of strings")
return job_id_list
schema = brewtils.schemas.JobExportInputSchema(**kwargs)

return json.dumps(job_id_list)
if from_string:
return schema.loads(job_id_json).data
else:
return schema.load(job_id_json).data

@classmethod
def parse_garden(cls, garden, from_string=False, **kwargs):
Expand Down

0 comments on commit f2bddad

Please sign in to comment.