def send_samples(self, samples_list):
"""
post request to send sample(s) to the given project
the project that the sample will be sent to is in its dictionary's
"sampleProject" key
arguments:
samples_list -- list containing Sample object(s) to send
returns a list containing dictionaries of the result of post request.
"""
self.cached_samples = {} # reset the cache, we're updating stuff
self.cached_projects = None
json_res_list = []
for sample in samples_list:
try:
project_id = sample.get_project_id()
proj_URL = self.get_link(self.base_URL, "projects")
url = self.get_link(proj_URL, "project/samples",
targ_dict={
"key": "identifier",
"value": project_id
})
except StopIteration:
raise ProjectError("The given project ID: " +
project_id + " doesn't exist")
headers = {
"headers": {
"Content-Type": "application/json"
}
}
json_obj = json.dumps(sample, cls=Sample.JsonEncoder)
response = self.session.post(url, json_obj, **headers)
if response.status_code == httplib.CREATED: # 201
json_res = json.loads(response.text)
json_res_list.append(json_res)
else:
logging.error("Didn't create sample on server, response code is [{}] and error message is [{}]".format(response.status_code, response.text))
raise SampleError("Error {status_code}: {err_msg}.\nSample data: {sample_data}".format(
status_code=str(response.status_code),
err_msg=response.text,
sample_data=str(sample)), ["IRIDA rejected the sample."])
return json_res_list
评论列表
文章目录