Skip to content

Commit

Permalink
Add prep test API creation (#1872)
Browse files Browse the repository at this point in the history
* Adding prep template data handler to REST api

* Adding creation endpoint for prep info

* flake8ing

* Addressing @antgonza's comments
  • Loading branch information
josenavas authored and antgonza committed Jun 29, 2016
1 parent 15a03de commit 3932dc6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
16 changes: 16 additions & 0 deletions qiita_db/handlers/prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
# The full license is in the file LICENSE, distributed with this software.
# -----------------------------------------------------------------------------

from json import loads

from tornado.web import HTTPError
import pandas as pd

import qiita_db as qdb
from .oauth2 import OauthBaseHandler, authenticate_oauth
Expand Down Expand Up @@ -63,3 +66,16 @@ def get(self, prep_id):
response = {'data': pt.to_dataframe().to_dict(orient='index')}

self.write(response)


class PrepTemplateAPItestHandler(OauthBaseHandler):
@authenticate_oauth
def post(self):
prep_info_dict = loads(self.get_argument('prep_info'))
study = self.get_argument('study')
data_type = self.get_argument('data_type')

metadata = pd.DataFrame.from_dict(prep_info_dict, orient='index')
pt = qdb.metadata_template.prep_template.PrepTemplate.create(
metadata, qdb.study.Study(study), data_type)
self.write({'prep': pt.id})
29 changes: 28 additions & 1 deletion qiita_db/handlers/tests/test_prep_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# -----------------------------------------------------------------------------

from unittest import main, TestCase
from json import loads
from json import loads, dumps

from tornado.web import HTTPError

Expand Down Expand Up @@ -96,5 +96,32 @@ def test_get(self):
'target_subfragment': 'V4'}
self.assertEqual(obs, exp)


class PrepTemplateAPItestHandlerTests(OauthTestingBase):
database = True

def test_post(self):
metadata_dict = {
'SKB8.640193': {'primer': 'GTGCCAGCMGCCGCGGTAA',
'barcode': 'GTCCGCAAGTTA',
'platform': 'ILLUMINA',
'instrument_model': 'Illumina MiSeq'},
'SKD8.640184': {'primer': 'GTGCCAGCMGCCGCGGTAA',
'barcode': 'GTCCGCAAGTTA',
'platform': 'ILLUMINA',
'instrument_model': 'Illumina MiSeq'}}
data = {'prep_info': dumps(metadata_dict),
'study': 1,
'data_type': '16S'}
obs = self.post('/apitest/prep_template/', headers=self.header,
data=data)
self.assertEqual(obs.code, 200)
obs = loads(obs.body)
self.assertEqual(obs.keys(), ['prep'])

pt = qdb.metadata_template.prep_template.PrepTemplate(obs['prep'])
self.assertItemsEqual(pt.keys(), ['1.SKB8.640193', '1.SKD8.640184'])


if __name__ == '__main__':
main()
6 changes: 4 additions & 2 deletions qiita_pet/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
JobHandler, HeartbeatHandler, ActiveStepHandler, CompleteHandler,
ProcessingJobAPItestHandler)
from qiita_db.handlers.artifact import ArtifactHandler
from qiita_db.handlers.prep_template import PrepTemplateDataHandler
from qiita_db.handlers.prep_template import (
PrepTemplateDataHandler, PrepTemplateAPItestHandler)
from qiita_db.handlers.oauth2 import TokenAuthHandler
from qiita_db.handlers.reference import ReferenceFilepathsHandler
from qiita_db.handlers.core import ResetAPItestHandler
Expand Down Expand Up @@ -165,7 +166,8 @@ def __init__(self):
# We add the endpoints for testing plugins
test_handlers = [
(r"/apitest/processing_job/", ProcessingJobAPItestHandler),
(r"/apitest/reset/", ResetAPItestHandler)
(r"/apitest/reset/", ResetAPItestHandler),
(r"/apitest/prep_template/", PrepTemplateAPItestHandler)
]
handlers.extend(test_handlers)

Expand Down

0 comments on commit 3932dc6

Please sign in to comment.