From 768eefa32275bd2829ad3fadeabadeb871de1a3c Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Mon, 26 Sep 2016 22:09:07 -0700 Subject: [PATCH 1/7] Adding activate handler --- qiita_db/handlers/plugin.py | 21 ++++++++++++++++++++ qiita_db/handlers/tests/test_plugin.py | 21 ++++++++++++++++++++ qiita_db/software.py | 27 ++++++++++++++++++++++++++ qiita_db/test/test_software.py | 7 +++++++ qiita_pet/webserver.py | 6 ++++-- 5 files changed, 80 insertions(+), 2 deletions(-) diff --git a/qiita_db/handlers/plugin.py b/qiita_db/handlers/plugin.py index 3f810a5cc..dd5b48401 100644 --- a/qiita_db/handlers/plugin.py +++ b/qiita_db/handlers/plugin.py @@ -184,3 +184,24 @@ def get(self, plugin_name, plugin_version, cmd_name): 'default_parameter_sets': { p.name: p.values for p in cmd.default_parameter_sets}} self.write(response) + + +class CommandActivateHandler(OauthBaseHandler): + @authenticate_oauth + def post(self, plugin_name, plugin_version, cmd_name): + """Activates the command + + Parameters + ---------- + plugin_name : str + The plugin name + plugin_version : str + The plugin version + cmd_name : str + The command name + """ + with qdb.sql_connection.TRN: + cmd = _get_command(plugin_name, plugin_version, cmd_name) + cmd.activate() + + self.finish() diff --git a/qiita_db/handlers/tests/test_plugin.py b/qiita_db/handlers/tests/test_plugin.py index 9063fa5b1..de61df0e1 100644 --- a/qiita_db/handlers/tests/test_plugin.py +++ b/qiita_db/handlers/tests/test_plugin.py @@ -164,5 +164,26 @@ def test_get(self): self.assertEqual(loads(obs.body), exp) +class CommandActivateHandlerTests(OauthTestingBase): + def test_post_command_does_not_exist(self): + obs = self.post('/qiita_db/plugins/QIIME/1.9.1/commands/' + 'UNKNOWN/activate/', + headers=self.header, data={}) + self.assertEqual(obs.code, 404) + + def test_post_no_header(self): + obs = self.post('/qiita_db/plugins/QIIME/1.9.1/commands/' + 'Split%20libraries/activate/', data={}) + self.assertEqual(obs.code, 400) + + def test_post(self): + qdb.software.Software.deactivate_all() + self.assertFalse(qdb.software.Command(2).active) + obs = self.post('/qiita_db/plugins/QIIME/1.9.1/commands/' + 'Split%20libraries/activate/', headers=self.header, + data={}) + self.assertEqual(obs.code, 200) + self.assertTrue(qdb.software.Command(2).active) + if __name__ == '__main__': main() diff --git a/qiita_db/software.py b/qiita_db/software.py index 3841642f0..fb972452f 100644 --- a/qiita_db/software.py +++ b/qiita_db/software.py @@ -425,6 +425,31 @@ def outputs(self): qdb.sql_connection.TRN.add(sql, [self.id]) return qdb.sql_connection.TRN.execute_fetchindex() + @property + def active(self): + """Returns if the command is active or not + + Returns + ------- + bool + Whether the command is active or not + """ + with qdb.sql_connection.TRN: + sql = """SELECT active + FROM qiita.software_command + WHERE command_id = %s""" + qdb.sql_connection.TRN.add(sql, [self.id]) + return qdb.sql_connection.TRN.execute_fetchlast() + + def activate(self): + """Activates the command""" + with qdb.sql_connection.TRN: + sql = """UPDATE qiita.software_command + SET active = %s + WHERE command_id = %s""" + qdb.sql_connection.TRN.add(sql, [True, self.id]) + return qdb.sql_connection.TRN.execute() + class Software(qdb.base.QiitaObject): r"""A software package available in the system @@ -456,6 +481,8 @@ def deactivate_all(cls): with qdb.sql_connection.TRN: sql = "UPDATE qiita.software SET active = False" qdb.sql_connection.TRN.add(sql) + sql = "UPDATE qiita.software_command SET active = False" + qdb.sql_connection.TRN.add(sql) qdb.sql_connection.TRN.execute() @classmethod diff --git a/qiita_db/test/test_software.py b/qiita_db/test/test_software.py index 7cec98bc3..0fb796a49 100644 --- a/qiita_db/test/test_software.py +++ b/qiita_db/test/test_software.py @@ -253,6 +253,13 @@ def test_create(self): 'opt_bool': ['boolean', 'False']} self.assertEqual(obs.optional_parameters, exp_optional) + def test_activate(self): + qdb.software.Software.deactivate_all() + tester = qdb.software.Command(1) + self.assertFalse(tester.active) + tester.activate() + self.assertTrue(tester.active) + @qiita_test_checker() class SoftwareTests(TestCase): diff --git a/qiita_pet/webserver.py b/qiita_pet/webserver.py index d3d433eff..4b2b7d070 100644 --- a/qiita_pet/webserver.py +++ b/qiita_pet/webserver.py @@ -51,8 +51,8 @@ from qiita_db.handlers.oauth2 import TokenAuthHandler from qiita_db.handlers.reference import ReferenceHandler from qiita_db.handlers.core import ResetAPItestHandler -from qiita_db.handlers.plugin import (PluginHandler, CommandHandler, - CommandListHandler) +from qiita_db.handlers.plugin import ( + PluginHandler, CommandHandler, CommandListHandler, CommandActivateHandler) from qiita_pet import uimodules from qiita_db.util import get_mountpoint if qiita_config.portal == "QIITA": @@ -156,6 +156,8 @@ def __init__(self): (r"/qiita_db/prep_template/(.*)/data/", PrepTemplateDataHandler), (r"/qiita_db/prep_template/(.*)/", PrepTemplateDBHandler), (r"/qiita_db/references/(.*)/", ReferenceHandler), + (r"/qiita_db/plugins/(.*)/(.*)/commands/(.*)/activate/", + CommandActivateHandler), (r"/qiita_db/plugins/(.*)/(.*)/commands/(.*)/", CommandHandler), (r"/qiita_db/plugins/(.*)/(.*)/commands/", CommandListHandler), (r"/qiita_db/plugins/(.*)/(.*)/", PluginHandler) From 15ac925098bd5c0a7e58081b682e241be24be17c Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 27 Sep 2016 08:08:15 -0700 Subject: [PATCH 2/7] Adding artifact type creation --- qiita_db/artifact.py | 51 ++++++++++++++++++++++++++++++++++ qiita_db/test/test_artifact.py | 19 ++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/qiita_db/artifact.py b/qiita_db/artifact.py index b7adb4d4f..f45021e1a 100644 --- a/qiita_db/artifact.py +++ b/qiita_db/artifact.py @@ -100,6 +100,57 @@ def types(): qdb.sql_connection.TRN.add(sql) return qdb.sql_connection.TRN.execute_fetchindex() + @staticmethod + def create_type(name, description, can_be_submitted_to_ebi, + can_be_submitted_to_vamps, filepath_types): + """Creates a new artifact type in the system + + Parameters + ---------- + name : str + The artifact type name + description : str + The artifact type description + can_be_submitted_to_ebi : bool + Whether the artifact type can be submitted to EBI or not + can_be_submitted_to_vamps : bool + Whether the artifact type can be submitted to VAMPS or not + filepath_types : list of (str, bool) + The list filepath types that the new artifact type supports, and + if they're required or not in an artifact instance of this type + + Raises + ------ + qiita_db.exceptions.QiitaDBDuplicateError + If an artifact type with the same name already exists + """ + with qdb.sql_connection.TRN: + sql = """SELECT EXISTS( + SELECT * + FROM qiita.artifact_type + WHERE artifact_type=%s)""" + qdb.sql_connection.TRN.add(sql, [name]) + if qdb.sql_connection.TRN.execute_fetchlast(): + raise qdb.exceptions.QiitaDBDuplicateError( + 'artifact type', 'name: %s' % name) + sql = """INSERT INTO qiita.artifact_type + (artifact_type, description, can_be_submitted_to_ebi, + can_be_submitted_to_vamps) + VALUES (%s, %s, %s, %s) + RETURNING artifact_type_id""" + qdb.sql_connection.TRN.add( + sql, [name, description, can_be_submitted_to_ebi, + can_be_submitted_to_vamps]) + at_id = qdb.sql_connection.TRN.execute_fetchlast() + sql = """INSERT INTO qiita.artifact_type_filepath_type + (artifact_type_id, filepath_type_id, required) + VALUES (%s, %s, %s)""" + sql_args = [ + [at_id, qdb.util.convert_to_id(fpt, 'filepath_type'), req] + for fpt, req in filepath_types] + qdb.sql_connection.TRN.add(sql, sql_args, many=True) + qdb.sql_connection.TRN.execute() + @classmethod def copy(cls, artifact, prep_template): """Creates a copy of `artifact` and attaches it to `prep_template` diff --git a/qiita_db/test/test_artifact.py b/qiita_db/test/test_artifact.py index 1df481706..a93404d40 100644 --- a/qiita_db/test/test_artifact.py +++ b/qiita_db/test/test_artifact.py @@ -42,7 +42,7 @@ def test_iter_public(self): exp = [] self.assertEqual(obs, exp) - def test_types(self): + def test_create_type(self): obs = qdb.artifact.Artifact.types() exp = [['BIOM', 'BIOM table'], ['Demultiplexed', 'Demultiplexed and QC sequeneces'], @@ -50,6 +50,23 @@ def test_types(self): ['SFF', None], ['per_sample_FASTQ', None]] self.assertItemsEqual(obs, exp) + qdb.artifact.Artifact.create_type( + "NewType", "NewTypeDesc", False, False, + [("log", False), ("raw_forward_seqs", True)]) + + obs = qdb.artifact.Artifact.types() + exp = [['BIOM', 'BIOM table'], + ['Demultiplexed', 'Demultiplexed and QC sequeneces'], + ['FASTA', None], ['FASTA_Sanger', None], ['FASTQ', None], + ['SFF', None], ['per_sample_FASTQ', None], + ['NewType', 'NewTypeDesc']] + self.assertItemsEqual(obs, exp) + + with self.assertRaises(qdb.exceptions.QiitaDBDuplicateError): + qdb.artifact.Artifact.create_type( + "NewType", "NewTypeDesc", False, False, + [("log", False), ("raw_forward_seqs", True)]) + def test_name(self): self.assertEqual(qdb.artifact.Artifact(1).name, "Raw data 1") self.assertEqual(qdb.artifact.Artifact(2).name, "Demultiplexed 1") From 49b7e6fdf075a0b6d8865e6e8cb267b4e6400a88 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 27 Sep 2016 08:20:26 -0700 Subject: [PATCH 3/7] Adding artifact type creator handler --- qiita_db/handlers/artifact.py | 21 +++++++++++++++++++++ qiita_db/handlers/tests/test_artifact.py | 23 +++++++++++++++++++++++ qiita_pet/webserver.py | 4 +++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/qiita_db/handlers/artifact.py b/qiita_db/handlers/artifact.py index b782a5f01..34f73ef02 100644 --- a/qiita_db/handlers/artifact.py +++ b/qiita_db/handlers/artifact.py @@ -177,3 +177,24 @@ def post(self): filepaths, artifact_type, name=name, prep_template=prep_template) self.write({'artifact': a.id}) + + +class ArtifactTypeHandler(OauthBaseHandler): + @authenticate_oauth + def post(self): + """Creates a new artifact type + + Parameters + ---------- + """ + a_type = self.get_argument('type_name') + a_desc = self.get_argument('description') + ebi = self.get_argument('can_be_submitted_to_ebi') + vamps = self.get_argument('can_be_submitted_to_vamps') + fp_types = loads(self.get_argument('filepath_types')) + + try: + qdb.artifact.Artifact.create_type(a_type, a_desc, ebi, vamps, + fp_types) + except qdb.exceptions.QiitaDBDuplicateError as e: + raise HTTPError(400, str(e)) diff --git a/qiita_db/handlers/tests/test_artifact.py b/qiita_db/handlers/tests/test_artifact.py index 8762c6289..9ec9d15b7 100644 --- a/qiita_db/handlers/tests/test_artifact.py +++ b/qiita_db/handlers/tests/test_artifact.py @@ -191,5 +191,28 @@ def test_post_error(self): obs.body) +class ArtifactTypeHandlerTests(OauthTestingBase): + def test_post_no_header(self): + obs = self.post('/qiita_db/artifacts/types/', data={}) + self.assertEqual(obs.code, 400) + + def test_post(self): + data = {'type_name': 'new_type', + 'description': 'some_description', + 'can_be_submitted_to_ebi': False, + 'can_be_submitted_to_vamps': False, + 'filepath_types': dumps([("log", False), + ("raw_forward_seqs", True)])} + obs = self.post('/qiita_db/artifacts/types/', headers=self.header, + data=data) + self.assertEqual(obs.code, 200) + self.assertIn(['new_type', 'some_description'], + qdb.artifact.Artifact.types()) + + obs = self.post('/qiita_db/artifacts/types/', headers=self.header, + data=data) + self.assertEqual(obs.code, 400) + self.assertIn('already exists', obs.body) + if __name__ == '__main__': main() diff --git a/qiita_pet/webserver.py b/qiita_pet/webserver.py index 4b2b7d070..500921b63 100644 --- a/qiita_pet/webserver.py +++ b/qiita_pet/webserver.py @@ -44,7 +44,8 @@ from qiita_db.handlers.processing_job import ( JobHandler, HeartbeatHandler, ActiveStepHandler, CompleteHandler, ProcessingJobAPItestHandler) -from qiita_db.handlers.artifact import ArtifactHandler, ArtifactAPItestHandler +from qiita_db.handlers.artifact import ( + ArtifactHandler, ArtifactAPItestHandler, ArtifactTypeHandler) from qiita_db.handlers.prep_template import ( PrepTemplateDataHandler, PrepTemplateAPItestHandler, PrepTemplateDBHandler) @@ -152,6 +153,7 @@ def __init__(self): (r"/qiita_db/jobs/(.*)/step/", ActiveStepHandler), (r"/qiita_db/jobs/(.*)/complete/", CompleteHandler), (r"/qiita_db/jobs/(.*)", JobHandler), + (r"/qiita_db/artifacts/types/", ArtifactTypeHandler), (r"/qiita_db/artifacts/(.*)/", ArtifactHandler), (r"/qiita_db/prep_template/(.*)/data/", PrepTemplateDataHandler), (r"/qiita_db/prep_template/(.*)/", PrepTemplateDBHandler), From 11b4f34a5471d5ae0e9e212a2e0e9ae2e7aae977 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 27 Sep 2016 08:22:52 -0700 Subject: [PATCH 4/7] Adding docs --- qiita_db/handlers/artifact.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qiita_db/handlers/artifact.py b/qiita_db/handlers/artifact.py index 34f73ef02..a50319c4f 100644 --- a/qiita_db/handlers/artifact.py +++ b/qiita_db/handlers/artifact.py @@ -186,6 +186,22 @@ def post(self): Parameters ---------- + name : str + The artifact type name + description : str + The artifact type description + can_be_submitted_to_ebi : bool + Whether the artifact type can be submitted to EBI or not + can_be_submitted_to_vamps : bool + Whether the artifact type can be submitted to VAMPS or not + filepath_types : list of (str, bool) + The list filepath types that the new artifact type supports, and + if they're required or not in an artifact instance of this type + + Raises + ------ + HTTPError + If the artifact type already exists, with error code 400 """ a_type = self.get_argument('type_name') a_desc = self.get_argument('description') From a1df2040f2cc145896887a55d702666a50933f02 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 27 Sep 2016 12:08:46 -0700 Subject: [PATCH 5/7] Missing bits --- qiita_db/handlers/artifact.py | 2 ++ qiita_db/handlers/plugin.py | 19 +++++++++++++++++-- qiita_db/handlers/processing_job.py | 9 +++++---- .../handlers/tests/test_processing_job.py | 4 ++-- qiita_db/software.py | 17 +++++++++++++++-- qiita_db/test/test_software.py | 18 +++++++++++------- qiita_pet/webserver.py | 6 ++++-- 7 files changed, 56 insertions(+), 19 deletions(-) diff --git a/qiita_db/handlers/artifact.py b/qiita_db/handlers/artifact.py index a50319c4f..f5f21521a 100644 --- a/qiita_db/handlers/artifact.py +++ b/qiita_db/handlers/artifact.py @@ -214,3 +214,5 @@ def post(self): fp_types) except qdb.exceptions.QiitaDBDuplicateError as e: raise HTTPError(400, str(e)) + + self.finish() diff --git a/qiita_db/handlers/plugin.py b/qiita_db/handlers/plugin.py index dd5b48401..3e01553f9 100644 --- a/qiita_db/handlers/plugin.py +++ b/qiita_db/handlers/plugin.py @@ -7,10 +7,13 @@ # ----------------------------------------------------------------------------- from json import loads +from glob import glob +from os.path import join from tornado.web import HTTPError from .oauth2 import OauthBaseHandler, authenticate_oauth +from qiita_core.qiita_settings import qiita_config import qiita_db as qdb @@ -106,8 +109,9 @@ def post(self, name, version): plugin, cmd_name, cmd_desc, parameters) # params = opt_params - for name, vals in dflt_param_set.items(): - qdb.software.DefaultParameters.create(name, cmd, **vals) + if dflt_param_set is not None: + for name, vals in dflt_param_set.items(): + qdb.software.DefaultParameters.create(name, cmd, **vals) self.finish() @@ -205,3 +209,14 @@ def post(self, plugin_name, plugin_version, cmd_name): cmd.activate() self.finish() + + +class ReloadPluginAPItestHandler(OauthBaseHandler): + @authenticate_oauth + def post(self): + """Reloads the plugins""" + conf_files = glob(join(qiita_config.plugin_dir, "*.conf")) + for fp in conf_files: + s = qdb.software.Software.from_file(fp, update=True) + s.activate() + self.finish() diff --git a/qiita_db/handlers/processing_job.py b/qiita_db/handlers/processing_job.py index 5eb7e0ef1..86e1fdb68 100644 --- a/qiita_db/handlers/processing_job.py +++ b/qiita_db/handlers/processing_job.py @@ -153,13 +153,14 @@ class ProcessingJobAPItestHandler(OauthBaseHandler): @authenticate_oauth def post(self): user = self.get_argument('user', 'test@foo.bar') - cmd = self.get_argument('command') + s_name, s_version, cmd_name = loads(self.get_argument('command')) params_dict = self.get_argument('parameters') status = self.get_argument('status', None) - params = qdb.software.Parameters.load( - qdb.software.Command(cmd), - json_str=params_dict) + cmd = qdb.software.Software.from_name_and_version( + s_name, s_version).get_command(cmd_name) + + params = qdb.software.Parameters.load(cmd, json_str=params_dict) job = qdb.processing_job.ProcessingJob.create( qdb.user.User(user), params) diff --git a/qiita_db/handlers/tests/test_processing_job.py b/qiita_db/handlers/tests/test_processing_job.py index 6cd862d91..b4494f347 100644 --- a/qiita_db/handlers/tests/test_processing_job.py +++ b/qiita_db/handlers/tests/test_processing_job.py @@ -204,7 +204,7 @@ class ProcessingJobAPItestHandlerTests(OauthTestingBase): def test_post_processing_job(self): data = { 'user': 'demo@microbio.me', - 'command': 3, + 'command': dumps(['QIIME', '1.9.1', 'Pick closed-reference OTUs']), 'parameters': dumps({"reference": 1, "sortmerna_e_value": 1, "sortmerna_max_pos": 10000, @@ -225,7 +225,7 @@ def test_post_processing_job(self): def test_post_processing_job_status(self): data = { 'user': 'demo@microbio.me', - 'command': 3, + 'command': dumps(['QIIME', '1.9.1', 'Pick closed-reference OTUs']), 'status': 'running', 'parameters': dumps({"reference": 1, "sortmerna_e_value": 1, diff --git a/qiita_db/software.py b/qiita_db/software.py index fb972452f..67e37ab52 100644 --- a/qiita_db/software.py +++ b/qiita_db/software.py @@ -147,7 +147,7 @@ def exists(cls, software, name): return qdb.sql_connection.TRN.execute_fetchlast() @classmethod - def create(cls, software, name, description, parameters): + def create(cls, software, name, description, parameters, outputs): r"""Creates a new command in the system The supported types for the parameters are: @@ -175,6 +175,9 @@ def create(cls, software, name, description, parameters): format is: {parameter_name: (parameter_type, default)}, where parameter_name, parameter_type and default are strings. If default is None. + outputs : dict + The description of the outputs that this command generated. The + format is: {output_name: artifact_type} Returns ------- @@ -216,7 +219,7 @@ def create(cls, software, name, description, parameters): ptype, dflt = vals # Check that the type is one of the supported types supported_types = ['string', 'integer', 'float', 'reference', - 'boolean'] + 'boolean', 'prep_template'] if ptype not in supported_types and not ptype.startswith( ('choice', 'artifact')): supported_types.extend(['choice', 'artifact']) @@ -281,6 +284,16 @@ def create(cls, software, name, description, parameters): for at in atypes] qdb.sql_connection.TRN.add(sql_type, sql_params, many=True) + # Add the outputs to the command + sql = """INSERT INTO qiita.command_output + (name, command_id, artifact_type_id) + VALUES (%s, %s, %s)""" + sql_args = [ + [pname, c_id, qdb.util.convert_to_id(at, 'artifact_type')] + for pname, at in outputs.items()] + qdb.sql_connection.TRN.add(sql, sql_args, many=True) + qdb.sql_connection.TRN.execute() + return cls(c_id) @property diff --git a/qiita_db/test/test_software.py b/qiita_db/test/test_software.py index 0fb796a49..2e12c7665 100644 --- a/qiita_db/test/test_software.py +++ b/qiita_db/test/test_software.py @@ -29,6 +29,7 @@ def setUp(self): 'opt_int_param': ['integer', '4'], 'opt_choice_param': ['choice:["opt1", "opt2"]', 'opt1'], 'opt_bool': ['boolean', 'False']} + self.outputs = {'out1': 'BIOM'} def test_get_commands_by_input_type(self): obs = list(qdb.software.Command.get_commands_by_input_type(['FASTQ'])) @@ -202,11 +203,13 @@ def test_create_error(self): # no parameters with self.assertRaises(qdb.exceptions.QiitaDBError): qdb.software.Command.create( - self.software, "Test command", "Testing command", {}) + self.software, "Test command", "Testing command", {}, + self.outputs) with self.assertRaises(qdb.exceptions.QiitaDBError): qdb.software.Command.create( - self.software, "Test command", "Testing command", None) + self.software, "Test command", "Testing command", None, + self.outputs) # malformed params parameters = deepcopy(self.parameters) @@ -214,7 +217,7 @@ def test_create_error(self): with self.assertRaises(qdb.exceptions.QiitaDBError): qdb.software.Command.create( self.software, "Test command", "Testing command", - parameters) + parameters, self.outputs) # unsupported parameter type parameters = deepcopy(self.parameters) @@ -222,7 +225,7 @@ def test_create_error(self): with self.assertRaises(qdb.exceptions.QiitaDBError): qdb.software.Command.create( self.software, "Test command", "Testing command", - parameters) + parameters, self.outputs) # bad default choice parameters = deepcopy(self.parameters) @@ -230,18 +233,19 @@ def test_create_error(self): with self.assertRaises(qdb.exceptions.QiitaDBError): qdb.software.Command.create( self.software, "Test command", "Testing command", - parameters) + parameters, self.outputs) # duplicate with self.assertRaises(qdb.exceptions.QiitaDBDuplicateError): qdb.software.Command.create( self.software, "Split libraries", - "This is a command for testing", self.parameters) + "This is a command for testing", self.parameters, + self.outputs) def test_create(self): obs = qdb.software.Command.create( self.software, "Test Command", "This is a command for testing", - self.parameters) + self.parameters, self.outputs) self.assertEqual(obs.name, "Test Command") self.assertEqual(obs.description, "This is a command for testing") exp_required = {'req_param': ('string', [None]), diff --git a/qiita_pet/webserver.py b/qiita_pet/webserver.py index 500921b63..48ff597cf 100644 --- a/qiita_pet/webserver.py +++ b/qiita_pet/webserver.py @@ -53,7 +53,8 @@ from qiita_db.handlers.reference import ReferenceHandler from qiita_db.handlers.core import ResetAPItestHandler from qiita_db.handlers.plugin import ( - PluginHandler, CommandHandler, CommandListHandler, CommandActivateHandler) + PluginHandler, CommandHandler, CommandListHandler, CommandActivateHandler, + ReloadPluginAPItestHandler) from qiita_pet import uimodules from qiita_db.util import get_mountpoint if qiita_config.portal == "QIITA": @@ -178,7 +179,8 @@ def __init__(self): (r"/apitest/processing_job/", ProcessingJobAPItestHandler), (r"/apitest/reset/", ResetAPItestHandler), (r"/apitest/prep_template/", PrepTemplateAPItestHandler), - (r"/apitest/artifact/", ArtifactAPItestHandler) + (r"/apitest/artifact/", ArtifactAPItestHandler), + (r"/apitest/reload_plugins/", ReloadPluginAPItestHandler) ] handlers.extend(test_handlers) From c86d37d75dac6825a277c5e3e2e90c5185f512f7 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 27 Sep 2016 12:18:46 -0700 Subject: [PATCH 6/7] Last bits --- qiita_db/handlers/plugin.py | 6 ++++-- qiita_db/handlers/tests/test_plugin.py | 1 + qiita_db/software.py | 21 +++++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/qiita_db/handlers/plugin.py b/qiita_db/handlers/plugin.py index 3e01553f9..5850df51c 100644 --- a/qiita_db/handlers/plugin.py +++ b/qiita_db/handlers/plugin.py @@ -100,15 +100,17 @@ def post(self, name, version): cmd_desc = self.get_argument('description') req_params = loads(self.get_argument('required_parameters')) opt_params = loads(self.get_argument('optional_parameters')) + outputs = self.get_argument('outputs', None) + if outputs: + outputs = loads(outputs) dflt_param_set = loads(self.get_argument('default_parameter_sets')) parameters = req_params parameters.update(opt_params) cmd = qdb.software.Command.create( - plugin, cmd_name, cmd_desc, parameters) + plugin, cmd_name, cmd_desc, parameters, outputs) - # params = opt_params if dflt_param_set is not None: for name, vals in dflt_param_set.items(): qdb.software.DefaultParameters.create(name, cmd, **vals) diff --git a/qiita_db/handlers/tests/test_plugin.py b/qiita_db/handlers/tests/test_plugin.py index de61df0e1..ef2f52b16 100644 --- a/qiita_db/handlers/tests/test_plugin.py +++ b/qiita_db/handlers/tests/test_plugin.py @@ -77,6 +77,7 @@ def test_post(self): 'optional_parameters': dumps({'param1': ['string', ''], 'param2': ['float', '1.5'], 'param3': ['boolean', 'True']}), + 'outputs': dumps({'out1': 'BIOM'}), 'default_parameter_sets': dumps( {'dflt1': {'param1': 'test', 'param2': '2.4', diff --git a/qiita_db/software.py b/qiita_db/software.py index 67e37ab52..510c7be95 100644 --- a/qiita_db/software.py +++ b/qiita_db/software.py @@ -147,7 +147,7 @@ def exists(cls, software, name): return qdb.sql_connection.TRN.execute_fetchlast() @classmethod - def create(cls, software, name, description, parameters, outputs): + def create(cls, software, name, description, parameters, outputs=None): r"""Creates a new command in the system The supported types for the parameters are: @@ -175,7 +175,7 @@ def create(cls, software, name, description, parameters, outputs): format is: {parameter_name: (parameter_type, default)}, where parameter_name, parameter_type and default are strings. If default is None. - outputs : dict + outputs : dict, optional The description of the outputs that this command generated. The format is: {output_name: artifact_type} @@ -285,14 +285,15 @@ def create(cls, software, name, description, parameters, outputs): qdb.sql_connection.TRN.add(sql_type, sql_params, many=True) # Add the outputs to the command - sql = """INSERT INTO qiita.command_output - (name, command_id, artifact_type_id) - VALUES (%s, %s, %s)""" - sql_args = [ - [pname, c_id, qdb.util.convert_to_id(at, 'artifact_type')] - for pname, at in outputs.items()] - qdb.sql_connection.TRN.add(sql, sql_args, many=True) - qdb.sql_connection.TRN.execute() + if outputs: + sql = """INSERT INTO qiita.command_output + (name, command_id, artifact_type_id) + VALUES (%s, %s, %s)""" + sql_args = [ + [pname, c_id, qdb.util.convert_to_id(at, 'artifact_type')] + for pname, at in outputs.items()] + qdb.sql_connection.TRN.add(sql, sql_args, many=True) + qdb.sql_connection.TRN.execute() return cls(c_id) From afc8707208eb7f43eece51a9d152184b51e249c6 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 27 Sep 2016 12:49:36 -0700 Subject: [PATCH 7/7] Addressing @antgonza comments --- qiita_db/handlers/tests/test_plugin.py | 11 +++++++++++ qiita_db/test/test_software.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/qiita_db/handlers/tests/test_plugin.py b/qiita_db/handlers/tests/test_plugin.py index ef2f52b16..457104739 100644 --- a/qiita_db/handlers/tests/test_plugin.py +++ b/qiita_db/handlers/tests/test_plugin.py @@ -186,5 +186,16 @@ def test_post(self): self.assertEqual(obs.code, 200) self.assertTrue(qdb.software.Command(2).active) + +class ReloadPluginAPItestHandlerTests(OauthTestingBase): + def test_post_no_header(self): + obs = self.post('/apitest/reload_plugins/', data={}) + self.assertEqual(obs.code, 400) + + def test_post(self): + obs = self.post('/apitest/reload_plugins/', headers=self.header, + data={}) + self.assertEqual(obs.code, 200) + if __name__ == '__main__': main() diff --git a/qiita_db/test/test_software.py b/qiita_db/test/test_software.py index 2e12c7665..675bf1c92 100644 --- a/qiita_db/test/test_software.py +++ b/qiita_db/test/test_software.py @@ -257,6 +257,20 @@ def test_create(self): 'opt_bool': ['boolean', 'False']} self.assertEqual(obs.optional_parameters, exp_optional) + obs = qdb.software.Command.create( + self.software, "Test Command 2", "This is a command for testing", + self.parameters) + self.assertEqual(obs.name, "Test Command 2") + self.assertEqual(obs.description, "This is a command for testing") + exp_required = {'req_param': ('string', [None]), + 'req_art': ('artifact', ['BIOM'])} + self.assertEqual(obs.required_parameters, exp_required) + exp_optional = { + 'opt_int_param': ['integer', '4'], + 'opt_choice_param': ['choice:["opt1", "opt2"]', 'opt1'], + 'opt_bool': ['boolean', 'False']} + self.assertEqual(obs.optional_parameters, exp_optional) + def test_activate(self): qdb.software.Software.deactivate_all() tester = qdb.software.Command(1)