Skip to content

Commit e460390

Browse files
committed
Merge branch 'death-march' of github.com:eldeveloper/qiita into death-march
2 parents 23c9993 + 53b3803 commit e460390

File tree

8 files changed

+35
-66
lines changed

8 files changed

+35
-66
lines changed

qiita_db/study.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,6 @@ def from_name_and_affiliation(cls, name, affiliation):
12401240
qdb.sql_connection.TRN.add(sql, [name, affiliation])
12411241
return cls(int(qdb.sql_connection.TRN.execute_fetchlast()))
12421242

1243-
12441243
@classmethod
12451244
def create(cls, name, email, affiliation, address=None, phone=None):
12461245
"""Create a StudyPerson object, checking if person already exists.

qiita_db/test/test_study.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,11 @@ def test_delete(self):
4646
self.assertFalse(
4747
qdb.study.StudyPerson.exists('SomeDude', 'affil'))
4848

49-
def test_retrieve_non_existant_person(self):
50-
with self.assertRaises(qdb.esceptions.QiitaDBLookupError):
49+
def test_retrieve_non_existant_people(self):
50+
with self.assertRaises(qdb.exceptions.QiitaDBLookupError):
5151
qdb.study.StudyPerson.from_name_and_affiliation('Boaty McBoatFace',
5252
'UCSD')
5353

54-
def test_retrieve_non_existant_person(self):
5554
p = qdb.study.StudyPerson.from_name_and_affiliation('LabDude',
5655
'knight lab')
5756
self.assertEqual(p.name, 'LabDude')

qiita_pet/handlers/rest/rest_handler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212

1313

1414
class RESTHandler(BaseHandler):
15+
def fail(self, msg, status):
16+
self.write({'message': msg})
17+
self.set_status(status)
18+
self.finish()
19+
1520
def study_boilerplate(self, study_id):
1621
study_id = to_int(study_id)
1722
s = None
1823
try:
1924
s = Study(study_id)
2025
except QiitaDBUnknownIDError:
21-
self.set_status(404)
22-
self.write({'message': 'Study not found'})
23-
self.finish()
26+
self.fail('Study not found', 404)
2427
finally:
2528
return s

qiita_pet/handlers/rest/study.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818

1919
class StudyHandler(RESTHandler):
20-
# /api/v1/study/<int>
2120

2221
@authenticate_oauth
2322
def get(self, study_id):
@@ -45,23 +44,20 @@ def get(self, study_id):
4544

4645

4746
class StudyCreatorHandler(RESTHandler):
47+
4848
@authenticate_oauth
4949
def post(self, *args, **kwargs):
5050
try:
5151
payload = json_decode(self.request.body)
5252
except ValueError:
53-
self.set_status(400)
54-
self.write({'message': 'Could not parse body'})
55-
self.finish()
53+
self.fail('Could not parse body', 400)
5654
return
5755

5856
required = {'title', 'study_abstract', 'study_description',
5957
'study_alias', 'owner', 'efo', 'contacts'}
6058

6159
if not required.issubset(payload):
62-
self.set_status(400)
63-
self.write({'message': 'Not all required arguments provided'})
64-
self.finish()
60+
self.fail('Not all required arguments provided', 400)
6561
return
6662

6763
title = payload['title']
@@ -71,9 +67,7 @@ def post(self, *args, **kwargs):
7167

7268
owner = payload['owner']
7369
if not User.exists(owner):
74-
self.set_status(403)
75-
self.write({'message': 'Unknown user'})
76-
self.finish()
70+
self.fail('Unknown user', 403)
7771
return
7872
else:
7973
owner = User(owner)
@@ -82,27 +76,21 @@ def post(self, *args, **kwargs):
8276
contacts = payload['contacts']
8377

8478
if Study.exists(title):
85-
self.set_status(409)
86-
self.write({'message': 'Study title already exists'})
87-
self.finish()
79+
self.fail('Study title already exists', 409)
8880
return
8981

9082
pi_name = contacts['principal_investigator'][0]
9183
pi_aff = contacts['principal_investigator'][1]
9284
if not StudyPerson.exists(pi_name, pi_aff):
93-
self.set_status(403)
94-
self.write({'message': 'Unknown principal investigator'})
95-
self.finish()
85+
self.fail('Unknown principal investigator', 403)
9686
return
9787
else:
9888
pi = StudyPerson.from_name_and_affiliation(pi_name, pi_aff)
9989

10090
lp_name = contacts['lab_person'][0]
10191
lp_aff = contacts['lab_person'][1]
10292
if not StudyPerson.exists(lp_name, lp_aff):
103-
self.set_status(403)
104-
self.write({'message': 'Unknown lab person'})
105-
self.finish()
93+
self.fail('Unknown lab person', 403)
10694
return
10795
else:
10896
lp = StudyPerson.from_name_and_affiliation(lp_name, lp_aff)

qiita_pet/handlers/rest/study_person.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ def get(self, *args, **kwargs):
2121
try:
2222
p = StudyPerson.from_name_and_affiliation(name, affiliation)
2323
except QiitaDBLookupError:
24-
self.set_status(404)
25-
self.write({'message': 'Person not found'})
26-
self.finish()
24+
self.fail('Person not found', 404)
2725
return
2826

2927
self.write({'address': p.address, 'phone': p.phone, 'email': p.email,
@@ -40,9 +38,7 @@ def post(self, *args, **kwargs):
4038
address = self.get_argument('address', None)
4139

4240
if StudyPerson.exists(name, affiliation):
43-
self.set_status(409)
44-
self.write({'message': 'Person already exists'})
45-
self.finish()
41+
self.fail('Person already exists', 409)
4642
return
4743

4844
p = StudyPerson.create(name=name, affiliation=affiliation, email=email,

qiita_pet/handlers/rest/study_preparation.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010

1111
import pandas as pd
12-
from tornado.escape import json_encode, json_decode
12+
from tornado.escape import json_decode
1313

1414
from qiita_db.util import get_mountpoint
1515
from qiita_db.artifact import Artifact
@@ -21,7 +21,6 @@
2121

2222

2323
class StudyPrepCreatorHandler(RESTHandler):
24-
# /api/v1/study/<int>/preparation/
2524
# TODO: do something smart about warnings, perhaps this should go in its
2625
# own endpoint i.e. /api/v1/study/<int>/preparation/validate
2726

@@ -41,9 +40,7 @@ def post(self, study_id, *args, **kwargs):
4140
p = PrepTemplate.create(data, study_id, data_type,
4241
investigation_type)
4342
except QiitaError as e:
44-
self.write(json_encode({'message': e.message}))
45-
self.set_status(406)
46-
self.finish()
43+
self.fail(e.message, 406)
4744
return
4845

4946
self.write({'id': p.id})
@@ -52,7 +49,7 @@ def post(self, study_id, *args, **kwargs):
5249

5350

5451
class StudyPrepArtifactCreatorHandler(RESTHandler):
55-
# /api/v1/study/<int>/preparation/<int>/artifact
52+
5653
@authenticate_oauth
5754
def post(self, study_id, prep_id):
5855
study = self.study_boilerplate(study_id)
@@ -63,16 +60,11 @@ def post(self, study_id, prep_id):
6360
try:
6461
p = PrepTemplate(prep_id)
6562
except QiitaDBUnknownIDError:
66-
self.set_status(404)
67-
self.write({'message': 'Preparation not found'})
68-
self.finish()
63+
self.fail('Preparation not found', 404)
6964
return
7065

7166
if p.study_id != study.id:
72-
self.set_status(409)
73-
self.write({'message': 'Preparation ID not associated with the '
74-
'study'})
75-
self.finish()
67+
self.fail('Preparation ID not associated with the study', 409)
7668
return
7769

7870
artifact_deets = json_decode(self.request.body)
@@ -87,9 +79,7 @@ def post(self, study_id, prep_id):
8779
artifact_deets['artifact_name'],
8880
p)
8981
except QiitaError as e:
90-
self.write(json_encode({'message': e.message}))
91-
self.set_status(406)
92-
self.finish()
82+
self.fail(e.message, 406)
9383
return
9484

9585
self.write({'id': art.id})

qiita_pet/handlers/rest/study_samples.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
class StudySamplesHandler(RESTHandler):
15-
# /api/v1/study/<int>/samples
1615

1716
@authenticate_oauth
1817
def get(self, study_id):
@@ -30,17 +29,12 @@ def get(self, study_id):
3029

3130

3231
class StudySamplesCategoriesHandler(RESTHandler):
33-
# /api/v1/study/<int>/samples?foo
34-
35-
def _err(self, msg, status):
36-
self.write({'message': msg})
37-
self.set_status(status)
38-
self.finish()
3932

4033
@authenticate_oauth
4134
def get(self, study_id, categories):
4235
if not categories:
43-
return self._err('No categories specified', 405)
36+
self.fail('No categories specified', 405)
37+
return
4438

4539
study = self.study_boilerplate(study_id)
4640
if study is None:
@@ -49,11 +43,13 @@ def get(self, study_id, categories):
4943
categories = categories.split(',')
5044

5145
if study.sample_template is None:
52-
return self._err('Category not found', 404)
46+
self.fail('Category not found', 404)
47+
return
5348

5449
available_categories = set(study.sample_template.categories())
5550
if not set(categories).issubset(available_categories):
56-
return self._err('Category not found', 404)
51+
self.fail('Category not found', 404)
52+
return
5753

5854
blob = {'header': categories,
5955
'samples': {}}
@@ -66,7 +62,6 @@ def get(self, study_id, categories):
6662

6763

6864
class StudySamplesInfoHandler(RESTHandler):
69-
# /api/v1/study/<int>/samples/info
7065

7166
@authenticate_oauth
7267
def get(self, study_id):

qiita_pet/webserver.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@
5757
ReloadPluginAPItestHandler)
5858
from qiita_pet import uimodules
5959
from qiita_db.util import get_mountpoint
60-
if qiita_config.portal == "QIITA":
61-
from qiita_pet.handlers.portal import (
62-
StudyPortalHandler, StudyPortalAJAXHandler)
63-
64-
from qiita_pet.handlers.rest import (
65-
StudyHandler as WeDontKnowWhatToCallThis)
6660
from qiita_pet.handlers.rest import (
61+
StudyHandler as WeDontKnowWhatToCallThis,
6762
StudySamplesHandler as WeDontKnowWhatToCallThisJr,
6863
StudySamplesInfoHandler as WeDontKnowWhatToCallThisJrJr,
6964
StudySamplesCategoriesHandler as WeDontKnowWhatToCallThisTheFourth,
@@ -72,6 +67,9 @@
7267
StudyPrepCreatorHandler as MonsiourWeDontKnowWhatToCallThis,
7368
StudyPrepArtifactCreatorHandler as FranklyMadamWeDontKnowWhatToCallThis,
7469
StudyStatusHandler as BondJamesBond)
70+
if qiita_config.portal == "QIITA":
71+
from qiita_pet.handlers.portal import (
72+
StudyPortalHandler, StudyPortalAJAXHandler)
7573

7674

7775
DIRNAME = dirname(__file__)
@@ -181,7 +179,8 @@ def __init__(self):
181179
# start of REST API URIs
182180
(r"/api/v1/study$", WeDontKnowWhatToCallThisSr),
183181
(r"/api/v1/study/([0-9]+)", WeDontKnowWhatToCallThis),
184-
(r"/api/v1/study/([0-9]+)/samples/categories=([a-zA-Z\-0-9\.:,_]*)",
182+
(r"/api/v1/study/([0-9]+)/samples/"
183+
r"categories=([a-zA-Z\-0-9\.:,_]*)",
185184
WeDontKnowWhatToCallThisTheFourth),
186185
(r"/api/v1/study/([0-9]+)/samples", WeDontKnowWhatToCallThisJr),
187186
(r"/api/v1/study/([0-9]+)/samples/info",

0 commit comments

Comments
 (0)