Skip to content

mv some methods #2268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixing errors and gui
  • Loading branch information
antgonza committed Sep 1, 2017
commit 2d8dffa33d095db647a04830c00f0b0bee9a1272
6 changes: 6 additions & 0 deletions qiita_pet/handlers/study_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ class StudyIndexHandler(BaseHandler):
@authenticated
def get(self, study_id):
study = to_int(study_id)
level = self.get_argument('level', '')
message = self.get_argument('message', '')

study_info = study_get_req(study, self.current_user.id)
if study_info['status'] != 'success':
raise HTTPError(404, study_info['message'])

if message != '':
study_info['level'] = level
study_info['message'] = message

self.render("study_base.html", **study_info)


Expand Down
18 changes: 11 additions & 7 deletions qiita_pet/handlers/study_handlers/ebi_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
from __future__ import division

from tornado.web import authenticated, HTTPError
from tornado.escape import url_escape
from json import dumps

from qiita_files.demux import stats as demux_stats

from qiita_core.qiita_settings import r_client
from qiita_core.qiita_settings import r_client, qiita_config
from qiita_core.util import execute_as_transaction
from qiita_db.metadata_template.constants import (SAMPLE_TEMPLATE_COLUMNS,
PREP_TEMPLATE_COLUMNS)
Expand Down Expand Up @@ -109,9 +110,6 @@ def get(self, preprocessed_data_id):
@authenticated
@execute_as_transaction
def post(self, preprocessed_data_id):
status = 'success'
message = ''

user = self.current_user
# make sure user is admin and can therefore actually submit to EBI
if user.level != 'admin':
Expand All @@ -123,10 +121,11 @@ def post(self, preprocessed_data_id):
raise HTTPError(403, "User: %s, %s is not a recognized submission "
"type" % (user.id, submission_type))

state = Artifact(preprocessed_data_id).study.ebi_submission_status
study = Artifact(preprocessed_data_id).study
state = study.ebi_submission_status
if state == 'submitting':
level = 'danger'
message = "Cannot resubmit! Current state is: %s" % state
status = 'danger'
else:
qiita_plugin = Software.from_name_and_version('Qiita', 'alpha')
cmd = qiita_plugin.get_command('submit_to_EBI')
Expand All @@ -137,5 +136,10 @@ def post(self, preprocessed_data_id):

r_client.set('ebi_submission_%s' % preprocessed_data_id,
dumps({'job_id': job.id, 'is_qiita_job': True}))
job.submit()

level = 'success'
message = 'EBI submission started. Job id: %s' % job.id

return {'status': status, 'message': message}
self.redirect("%s/study/description/%d?level=%s&message=%s" % (
qiita_config.portal_dir, study.id, level, url_escape(message)))
20 changes: 15 additions & 5 deletions qiita_ware/private_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,20 @@ def copy_artifact(job):
job._set_status('success')


def submit_to_ebi(preprocessed_data_id, submission_type):
"""Submit a study to EBI"""
submit_EBI(preprocessed_data_id, submission_type, True)
def submit_to_EBI(job):
"""Submit a study to EBI

Parameters
----------
job : qiita_db.processing_job.ProcessingJob
The processing job performing the task
"""
with qdb.sql_connection.TRN:
param_vals = job.parameters.values
artifact_id = int(param_vals['artifact'])
submission_type = param_vals['submission_type']
submit_EBI(artifact_id, submission_type, False)
job._set_status('success')


def delete_artifact(job):
Expand All @@ -126,7 +137,6 @@ def create_sample_template(job):
----------
job : qiita_db.processing_job.ProcessingJob
The processing job performing the task

"""
with qdb.sql_connection.TRN:
params = job.parameters.values
Expand All @@ -151,7 +161,7 @@ def create_sample_template(job):
'release_validators': release_validators,
'submit_to_VAMPS': submit_to_VAMPS,
'copy_artifact': copy_artifact,
'submit_to_ebi': submit_to_ebi,
'submit_to_EBI': submit_to_EBI,
'delete_artifact': delete_artifact,
'create_sample_template': create_sample_template,
}
Expand Down
53 changes: 28 additions & 25 deletions qiita_ware/test/test_private_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from qiita_db.artifact import Artifact
from qiita_db.metadata_template.prep_template import PrepTemplate
from qiita_db.exceptions import QiitaDBUnknownIDError
from qiita_ware.private_plugin import (
private_task, create_sample_template, delete_artifact)
from qiita_ware.private_plugin import private_task


@qiita_test_checker()
Expand All @@ -44,7 +43,7 @@ def tearDown(self):
def _create_job(self, cmd, values_dict):
user = User('test@foo.bar')
qiita_plugin = Software.from_name_and_version('Qiita', 'alpha')
cmd = qiita_plugin.get_command('copy_artifact')
cmd = qiita_plugin.get_command(cmd)
params = Parameters.load(cmd, values_dict=values_dict)
job = ProcessingJob.create(user, params)
job._set_status('queued')
Expand Down Expand Up @@ -79,37 +78,41 @@ def test_copy_artifact(self):
self.assertEqual(job.status, 'success')

def test_delete_artifact(self):
obs = delete_artifact(1)
exp = {'status': 'danger',
'message': 'Cannot delete artifact 1: it has children: 2, 3'}
self.assertEqual(obs, exp)

obs = delete_artifact(3)
exp = {'status': 'success',
'message': ''}
self.assertEqual(obs, exp)
job = self._create_job('delete_artifact', {'artifact': 1})
private_task(job.id)
self.assertEqual(job.status, 'error')
self.assertIn(
'Cannot delete artifact 1: it has children: 2, 3', job.log.msg)

job = self._create_job('delete_artifact', {'artifact': 3})
private_task(job.id)
self.assertEqual(job.status, 'success')
with self.assertRaises(QiitaDBUnknownIDError):
Artifact(3)

def test_create_sample_template(self):
obs = create_sample_template(self.fp, Study(1), False)
exp = {'status': 'danger',
'message': "The 'SampleTemplate' object with attributes "
"(id: 1) already exists."}
self.assertEqual(obs, exp)
job = self._create_job('create_sample_template', {
'fp': self.fp, 'study_id': 1, 'is_mapping_file': False,
'data_type': None})
private_task(job.id)
self.assertEqual(job.status, 'error')
self.assertIn("The 'SampleTemplate' object with attributes (id: 1) "
"already exists.", job.log.msg)

def test_create_sample_template_nonutf8(self):
fp = join(dirname(abspath(__file__)), 'test_data',
'sample_info_utf8_error.txt')
obs = create_sample_template(fp, Study(1), False)
exp = {'status': 'danger',
'message': 'There are invalid (non UTF-8) characters in your '
'information file. The offending fields and their '
'location (row, column) are listed below, invalid '
'characters are represented using 🐾: '
'"🐾collection_timestamp" = (0, 13)'}
self.assertEqual(obs, exp)
job = self._create_job('create_sample_template', {
'fp': fp, 'study_id': 1, 'is_mapping_file': False,
'data_type': None})
private_task(job.id)
self.assertEqual(job.status, 'error')
self.assertIn(
'There are invalid (non UTF-8) characters in your information '
'file. The offending fields and their location (row, column) are '
'listed below, invalid characters are represented using '
'🐾: "🐾collection_timestamp" = (0, 13)',
job.log.msg)


if __name__ == '__main__':
Expand Down