Skip to content

Commit 870a04d

Browse files
committed
Merge branch 'extending-artifact-apitest' of https://github.com/josenavas/qiita into analysis-refactor-tests
2 parents 857efc6 + c3409f2 commit 870a04d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

qiita_db/handlers/artifact.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,21 @@ def post(self):
169169
"""
170170
filepaths = loads(self.get_argument('filepaths'))
171171
artifact_type = self.get_argument('type')
172-
prep_template = self.get_argument('prep')
172+
prep_template = self.get_argument('prep', None)
173+
analysis = self.get_argument('analysis', None)
173174
name = self.get_argument('name', None)
175+
dtype = self.get_argument('data_type', None)
174176

175-
if prep_template:
177+
if prep_template is not None:
176178
prep_template = qdb.metadata_template.prep_template.PrepTemplate(
177179
prep_template)
180+
dtype = None
181+
if analysis is not None:
182+
analysis = qdb.analysis.Analysis(analysis)
178183

179184
a = qdb.artifact.Artifact.create(
180-
filepaths, artifact_type, name=name, prep_template=prep_template)
185+
filepaths, artifact_type, name=name, prep_template=prep_template,
186+
analysis=analysis, data_type=dtype)
181187

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

qiita_db/handlers/tests/test_artifact.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from tornado.web import HTTPError
1818
import pandas as pd
19+
from biom import example_table as et
20+
from biom.util import biom_open
1921

2022
from qiita_db.handlers.tests.oauthbase import OauthTestingBase
2123
import qiita_db as qdb
@@ -206,6 +208,27 @@ def test_post(self):
206208
self._clean_up_files.extend([fp for _, fp, _ in a.filepaths])
207209
self.assertEqual(a.name, "New test artifact")
208210

211+
def test_post_analysis(self):
212+
fd, fp = mkstemp(suffix='_table.biom')
213+
close(fd)
214+
with biom_open(fp, 'w') as f:
215+
et.to_hdf5(f, "test")
216+
self._clean_up_files.append(fp)
217+
218+
data = {'filepaths': dumps([(fp, 'biom')]),
219+
'type': "BIOM",
220+
'name': "New biom artifact",
221+
'analysis': 1,
222+
'data_type': '16S'}
223+
obs = self.post('/apitest/artifact/', headers=self.header, data=data)
224+
self.assertEqual(obs.code, 200)
225+
obs = loads(obs.body)
226+
self.assertEqual(obs.keys(), ['artifact'])
227+
228+
a = qdb.artifact.Artifact(obs['artifact'])
229+
self._clean_up_files.extend([afp for _, afp, _ in a.filepaths])
230+
self.assertEqual(a.name, "New biom artifact")
231+
209232
def test_post_error(self):
210233
data = {'filepaths': dumps([('Do not exist', 'raw_forward_seqs')]),
211234
'type': "FASTQ",

0 commit comments

Comments
 (0)