Skip to content

Commit 73767ed

Browse files
authored
add parents ArtifactHandler (#3494)
* add parents ArtifactHandler * fixing test * add job_id to ArtifactAPItestHandler * flake8
1 parent bc2244b commit 73767ed

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

qiita_db/handlers/artifact.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def get(self, artifact_id):
7777
'processing_parameters': dict with the processing parameters used
7878
to generate the artifact or None
7979
'files': dict with the artifact files, keyed by filepath type
80+
'parents': list of the parents artifact ids
8081
"""
8182
with qdb.sql_connection.TRN:
8283
artifact = _get_artifact(artifact_id)
@@ -93,7 +94,8 @@ def get(self, artifact_id):
9394
artifact.can_be_submitted_to_vamps,
9495
'prep_information': [p.id for p in artifact.prep_templates],
9596
'study': study.id if study else None,
96-
'analysis': analysis.id if analysis else None}
97+
'analysis': analysis.id if analysis else None,
98+
'parents': [p.id for p in artifact.parents]}
9799
params = artifact.processing_parameters
98100
response['processing_parameters'] = (
99101
params.values if params is not None else None)
@@ -184,16 +186,28 @@ def post(self):
184186
analysis = self.get_argument('analysis', None)
185187
name = self.get_argument('name', None)
186188
dtype = self.get_argument('data_type', None)
189+
parents = self.get_argument('parents', None)
190+
job_id = self.get_argument('job_id', None)
187191

188192
if prep_template is not None:
189193
prep_template = qdb.metadata_template.prep_template.PrepTemplate(
190194
prep_template)
191195
dtype = None
192196
if analysis is not None:
193197
analysis = qdb.analysis.Analysis(analysis)
198+
if parents is not None:
199+
# remember that this method is only accessed via the tests so
200+
# to load an artifact with parents, the easiest it to use
201+
# the job_id that is being used for testing and passed as a
202+
# parameter
203+
parents = [qdb.artifact.Artifact(p) for p in loads(parents)]
204+
pp = qdb.processing_job.ProcessingJob(job_id).parameters
205+
else:
206+
pp = None
194207

195208
a = qdb.artifact.Artifact.create(
196209
filepaths, artifact_type, name=name, prep_template=prep_template,
210+
parents=parents, processing_parameters=pp,
197211
analysis=analysis, data_type=dtype)
198212

199213
self.write({'artifact': a.id})

qiita_db/handlers/tests/test_artifact.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def test_get_artifact(self):
8686
'prep_information': [1],
8787
'study': 1,
8888
'analysis': None,
89+
'parents': [],
8990
'processing_parameters': None,
9091
'files': exp_fps}
9192
self.assertEqual(loads(obs.body), exp)
@@ -109,6 +110,7 @@ def test_get_artifact(self):
109110
'prep_information': [],
110111
'study': None,
111112
'analysis': 1,
113+
'parents': [8],
112114
'processing_parameters': {'biom_table': '8', 'depth': '9000',
113115
'subsample_multinomial': 'False'},
114116
'files': exp_fps}

0 commit comments

Comments
 (0)