From c3409f2a6ce100af94fb12b929ccae52f041c5cb Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 13 Jun 2017 13:44:44 -0700 Subject: [PATCH] Extending post test call to accept analysis --- qiita_db/handlers/artifact.py | 12 +++++++++--- qiita_db/handlers/tests/test_artifact.py | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/qiita_db/handlers/artifact.py b/qiita_db/handlers/artifact.py index c3583518e..0598a88fe 100644 --- a/qiita_db/handlers/artifact.py +++ b/qiita_db/handlers/artifact.py @@ -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}) diff --git a/qiita_db/handlers/tests/test_artifact.py b/qiita_db/handlers/tests/test_artifact.py index 07c1805d4..7e66fddca 100644 --- a/qiita_db/handlers/tests/test_artifact.py +++ b/qiita_db/handlers/tests/test_artifact.py @@ -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 @@ -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",