Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions qiita_db/handlers/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,21 @@ def post(self):
"""
filepaths = loads(self.get_argument('filepaths'))
artifact_type = self.get_argument('type')
prep_template = self.get_argument('prep')
prep_template = self.get_argument('prep', None)
analysis = self.get_argument('analysis', None)
name = self.get_argument('name', None)
dtype = self.get_argument('data_type', None)

if prep_template:
if prep_template is not None:
prep_template = qdb.metadata_template.prep_template.PrepTemplate(
prep_template)
dtype = None
if analysis is not None:
analysis = qdb.analysis.Analysis(analysis)

a = qdb.artifact.Artifact.create(
filepaths, artifact_type, name=name, prep_template=prep_template)
filepaths, artifact_type, name=name, prep_template=prep_template,
analysis=analysis, data_type=dtype)

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

Expand Down
23 changes: 23 additions & 0 deletions qiita_db/handlers/tests/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from tornado.web import HTTPError
import pandas as pd
from biom import example_table as et
from biom.util import biom_open

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

def test_post_analysis(self):
fd, fp = mkstemp(suffix='_table.biom')
close(fd)
with biom_open(fp, 'w') as f:
et.to_hdf5(f, "test")
self._clean_up_files.append(fp)

data = {'filepaths': dumps([(fp, 'biom')]),
'type': "BIOM",
'name': "New biom artifact",
'analysis': 1,
'data_type': '16S'}
obs = self.post('/apitest/artifact/', headers=self.header, data=data)
self.assertEqual(obs.code, 200)
obs = loads(obs.body)
self.assertEqual(obs.keys(), ['artifact'])

a = qdb.artifact.Artifact(obs['artifact'])
self._clean_up_files.extend([afp for _, afp, _ in a.filepaths])
self.assertEqual(a.name, "New biom artifact")

def test_post_error(self):
data = {'filepaths': dumps([('Do not exist', 'raw_forward_seqs')]),
'type': "FASTQ",
Expand Down